-
Notifications
You must be signed in to change notification settings - Fork 376
update keepdim params for 1D scale factor #3374
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
base: main
Are you sure you want to change the base?
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/3374
Note: Links to docs will display an error until the docs builds have been completed. This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@pytorchbot label "topic: not user facing" |
|
Local test code: import torch
from torchao.quantization.quant_primitives import _choose_scale_float8, _choose_scale_float8_old
a = torch.randn(4, 4)
scale = _choose_scale_float8(a, block_size=(4, 1)) # keepdim = False
print(scale)
scale_old = _choose_scale_float8_old(a, block_size=(4, 1)) # keepdim = True
print(scale_old)And the result is (same): |
|
this is not enough I think there are ao/torchao/quantization/quant_primitives.py Lines 2320 to 2323 in 2ff1eb2
I actually tried this locally, and doesn't seem to work very well. I think we can leave this for now, but one thing that is useful is to remove the need to do ao/torchao/quantization/quant_primitives.py Line 2332 in 2ff1eb2
ao/torchao/quantization/quant_primitives.py Lines 2318 to 2323 in 2ff1eb2
maybe try removing calls to also another thing we can do is to simplify the implementation of ao/torchao/float8/inference.py Line 130 in 2ff1eb2
|
Overview:
In
_choose_scale_float8, the per-tensor quantization case (len(block_size) == 0) usestensor.amax(keepdim=True)while_choose_qparams_affineusestorch.amax(..., keepdim=False)for the same purpose.This PR aligns
_choose_scale_float8with_choose_qparams_affineby usingtensor.amax(keepdim=False)for 1D scale factor.Related Issue/PR: #3324
Test Plan: test/quantization/test_quant_primitives.py