Skip to content

Fix float8 zero scale quantization - #4714

Open
Rajioba1 wants to merge 1 commit into
pytorch:mainfrom
Rajioba1:fix-float8-zero-scale-nan
Open

Fix float8 zero scale quantization#4714
Rajioba1 wants to merge 1 commit into
pytorch:mainfrom
Rajioba1:fix-float8-zero-scale-nan

Conversation

@Rajioba1

@Rajioba1 Rajioba1 commented Aug 6, 2026

Copy link
Copy Markdown

Summary

Fixes #4713.

Float8Tensor.from_hp currently produces NaN qdata and NaN dequantized output for all-zero tensors because _choose_scale_float8 returns a zero scale for zero blocks. The later affine float8 quantization path divides 0 by 0.

This clamps the amax value to a small positive floor before dividing by the float8 max, matching the nearby floatx scale helper pattern.

Test Plan

  • CUDA_VISIBLE_DEVICES="" python -m pytest -q test/quantization/quantize_/workflows/float8/test_float8_tensor.py::TestFloat8TensorCPU -q
  • CUDA_VISIBLE_DEVICES="" python -m pytest -q test/quantization/test_quant_primitives.py -q
  • ruff check torchao/quantization/quant_primitives.py test/quantization/quantize_/workflows/float8/test_float8_tensor.py
  • ruff format --check torchao/quantization/quant_primitives.py test/quantization/quantize_/workflows/float8/test_float8_tensor.py

@pytorch-bot

pytorch-bot Bot commented Aug 6, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

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

@meta-cla

meta-cla Bot commented Aug 6, 2026

Copy link
Copy Markdown

Hi @Rajioba1!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@Rajioba1

Rajioba1 commented Aug 6, 2026

Copy link
Copy Markdown
Author

I do not have permission to apply upstream labels from the fork. Could a maintainer please add the appropriate module label? I believe module: core fits this quant primitive / Float8Tensor change.

@Rajioba1

Rajioba1 commented Aug 6, 2026

Copy link
Copy Markdown
Author

I have signed the CLA

@meta-cla meta-cla 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 Aug 6, 2026
@meta-cla

meta-cla Bot commented Aug 6, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Float8Tensor zero inputs quantize to NaN

1 participant