Skip to content

Add Float8Tensor #2463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Add Float8Tensor #2463

wants to merge 1 commit into from

Conversation

jerryzh168
Copy link
Contributor

@jerryzh168 jerryzh168 commented Jun 30, 2025

Stacked PRs:


Add Float8Tensor

Summary:
Added Float8Tensor that works for:

  • fbgemm: per row activation + per row weight calling torch.ops.fbgemm.f8f8bf16_rowwise kernela
  • aten: per row/tensor activation + per row/tensor weight calling torch._scaled_mm, or weight only quantization (fallback path)

Reusing Float8DynamicActivationFloat8WeightConfig for the above, and use kernel to control which kernel
users will use

Test Plan:
python test/dtypes/test_affine_quantized_float.py
python test/quantization/quantize_/test_float8_rowwise_tensor.py

Reviewers:

Subscribers:

Tasks:

Tags:

Copy link

pytorch-bot bot commented Jun 30, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/2463

Note: Links to docs will display an error until the docs builds have been completed.

❌ 2 New Failures, 1 Unrelated Failure

As of commit 032425d with merge base 378e179 (image):

NEW FAILURES - The following jobs have failed:

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

jerryzh168 added a commit that referenced this pull request Jun 30, 2025
Summary:
Splits out the float8 rowwise quantized path (both act and weight) of AQT to Float8RowwiseTensor

Next: could potentially incorporate the per tensor activation path there as well
Next: we can split the per tensor weight path to another Tensor as well, so we can deprecate AQT path for float8

Test Plan:
python test/dtypes/test_affine_quantized_float.py
python test/quantization/quantize_/test_float8_rowwise_tensor.py

Reviewers:

Subscribers:

Tasks:

Tags:

stack-info: PR: #2463, branch: jerryzh168/stack/9
@jerryzh168 jerryzh168 force-pushed the jerryzh168/stack/9 branch from da79207 to 5cae4d0 Compare June 30, 2025 23:01
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 30, 2025
@jerryzh168 jerryzh168 added the topic: new feature Use this tag if this PR adds a new feature label Jun 30, 2025
@jerryzh168 jerryzh168 changed the base branch from jerryzh168/stack/4 to main July 2, 2025 01:58
@jerryzh168 jerryzh168 force-pushed the jerryzh168/stack/9 branch from 5cae4d0 to 33ca58e Compare July 2, 2025 01:58
@jerryzh168 jerryzh168 changed the title Add Float8RowwiseTensor Add Float8Tensor Jul 2, 2025
@jerryzh168 jerryzh168 changed the base branch from main to jerryzh168/stack/4 July 2, 2025 01:58
@jerryzh168 jerryzh168 changed the base branch from jerryzh168/stack/4 to main July 2, 2025 20:35
@jerryzh168 jerryzh168 force-pushed the jerryzh168/stack/9 branch from 33ca58e to 897ec7e Compare July 2, 2025 20:36
@jerryzh168 jerryzh168 changed the base branch from main to jerryzh168/stack/4 July 2, 2025 20:36
@jerryzh168 jerryzh168 changed the base branch from jerryzh168/stack/4 to main July 2, 2025 21:42
@jerryzh168 jerryzh168 force-pushed the jerryzh168/stack/9 branch 2 times, most recently from 7897dcf to 99a1bb1 Compare July 2, 2025 21:42
@jerryzh168 jerryzh168 changed the base branch from main to jerryzh168/stack/11 July 2, 2025 21:42
@jerryzh168 jerryzh168 changed the base branch from jerryzh168/stack/11 to main July 2, 2025 23:44
@jerryzh168 jerryzh168 force-pushed the jerryzh168/stack/9 branch from 99a1bb1 to 7e9f224 Compare July 2, 2025 23:44
@jerryzh168 jerryzh168 changed the base branch from main to jerryzh168/stack/11 July 2, 2025 23:44
@jerryzh168 jerryzh168 changed the base branch from jerryzh168/stack/11 to main July 3, 2025 00:09
@jerryzh168 jerryzh168 force-pushed the jerryzh168/stack/9 branch from 7e9f224 to 442bd6c Compare July 3, 2025 00:09
@jerryzh168 jerryzh168 changed the base branch from main to jerryzh168/stack/11 July 3, 2025 00:09
)
new_weight = new_layer.weight.tensor_impl.float8_data.to(torch.float32)
else:
if mode == "static":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does that practically mean, is static_quant no broken after this PR

Copy link
Contributor Author

@jerryzh168 jerryzh168 Jul 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static quant is not migrated yet, it won't break

@jerryzh168 jerryzh168 changed the base branch from jerryzh168/stack/11 to main July 8, 2025 02:27
@jerryzh168 jerryzh168 force-pushed the jerryzh168/stack/9 branch from 4bb1c40 to 1190e05 Compare July 8, 2025 02:27
@jerryzh168 jerryzh168 changed the base branch from main to jerryzh168/stack/11 July 8, 2025 02:27
from torchao.utils import _is_fbgemm_genai_gpu_available, is_sm_at_least_90

_MODEL_NAMES = [
"torchao-testing/opt-125m-float8dq-row-fbgemm",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think model name here should specify the relevant versions

also, IMO this should be a toy model with a single layer with matching done on the layer output, to make it 100x easier to debug when things do go wrong. It's fine to also have a real model and match tokens, but I think it's more important to have a toy model.

Copy link
Contributor Author

@jerryzh168 jerryzh168 Jul 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

single linear for debugability makes sense, although I'm not sure how we can get a toy model with a single linear in huggingface transformers actually, I can add version but can revisit on getting a single layer

@jerryzh168 jerryzh168 changed the base branch from jerryzh168/stack/11 to main July 8, 2025 22:22
@jerryzh168 jerryzh168 force-pushed the jerryzh168/stack/9 branch from 1190e05 to ca37916 Compare July 8, 2025 22:22
@jerryzh168 jerryzh168 changed the base branch from main to jerryzh168/stack/11 July 8, 2025 22:22
@jerryzh168 jerryzh168 changed the base branch from jerryzh168/stack/11 to main July 11, 2025 21:52
@jerryzh168 jerryzh168 force-pushed the jerryzh168/stack/9 branch from ca37916 to 76ba25d Compare July 11, 2025 21:52
@jerryzh168 jerryzh168 changed the base branch from main to jerryzh168/stack/11 July 11, 2025 21:53
@jerryzh168 jerryzh168 changed the base branch from jerryzh168/stack/11 to main July 11, 2025 23:05
@jerryzh168 jerryzh168 force-pushed the jerryzh168/stack/9 branch from 76ba25d to 183e631 Compare July 11, 2025 23:05
@jerryzh168 jerryzh168 changed the base branch from main to jerryzh168/stack/11 July 11, 2025 23:06
@jerryzh168 jerryzh168 changed the base branch from jerryzh168/stack/11 to main July 11, 2025 23:45
@jerryzh168 jerryzh168 force-pushed the jerryzh168/stack/9 branch from 183e631 to 598d7ba Compare July 11, 2025 23:46
@jerryzh168 jerryzh168 changed the base branch from main to jerryzh168/stack/11 July 11, 2025 23:46
@jerryzh168 jerryzh168 changed the base branch from jerryzh168/stack/11 to main July 12, 2025 03:37
@jerryzh168 jerryzh168 force-pushed the jerryzh168/stack/9 branch 2 times, most recently from 66f4137 to 3f8c237 Compare July 12, 2025 04:55
Summary:
Added Float8Tensor that works for:
* fbgemm: per row activation + per row weight calling torch.ops.fbgemm.f8f8bf16_rowwise kernela
* aten: per row/tensor activation + per row/tensor weight calling torch._scaled_mm, or weight only quantization (fallback path)

Reusing Float8DynamicActivationFloat8WeightConfig for the above, and use kernel to control which kernel
users will use

Test Plan:
python test/dtypes/test_affine_quantized_float.py
python test/quantization/quantize_/test_float8_rowwise_tensor.py

Reviewers:

Subscribers:

Tasks:

Tags:

stack-info: PR: #2463, branch: jerryzh168/stack/9
@jerryzh168 jerryzh168 force-pushed the jerryzh168/stack/9 branch from 3f8c237 to 032425d Compare July 12, 2025 05:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. topic: new feature Use this tag if this PR adds a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants