-
Notifications
You must be signed in to change notification settings - Fork 313
Add NVFP4 QAT #2666
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: gh/andrewor14/16/base
Are you sure you want to change the base?
Add NVFP4 QAT #2666
Conversation
**Summary:** This commit adds a QAT flow for NVFP4, following the numerics in `NVFP4Tensor` closely but without the dtyping casting, swizzling, and the packing/unpacking. Users can call this flow as follows: ``` from torchao.quantization import quantize_ from torchao.quantization.qat import NVFP4FakeQuantizeConfig, QATConfig qat_config = QATConfig( activation_config=NVFP4FakeQuantizeConfig(), weight_config=NVFP4FakeQuantizeConfig(), step="prepare", ) quantize_(model, qat_config) ``` **Test Plan:** ``` python test/quantization/test_qat.py -k test_qat_nvfp4 ``` [ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/2666
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 87175e9 with merge base 97b090d ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
**Summary:** This commit adds a QAT flow for NVFP4, following the numerics in `NVFP4Tensor` closely but without the dtyping casting, swizzling, and the packing/unpacking. Users can call this flow as follows: ``` from torchao.quantization import quantize_ from torchao.quantization.qat import NVFP4FakeQuantizeConfig, QATConfig qat_config = QATConfig( activation_config=NVFP4FakeQuantizeConfig(), weight_config=NVFP4FakeQuantizeConfig(), step="prepare", ) quantize_(model, qat_config) ``` **Test Plan:** ``` python test/quantization/test_qat.py -k test_qat_nvfp4 ``` ghstack-source-id: fe592ca Pull Request resolved: #2666
baseline_out = baseline_model(*x) | ||
sqnr = compute_error(out, baseline_out).item() | ||
# Use same SQNR threshold as `test_nvfp4_reconstruction` | ||
# TODO: why is this 0.0 when `use_per_tensor_scale=True`? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a seems to be a bug it use_per_tensor_scale should be higher, probably supposed to be 10.0
after the initial fp8 (e4m3) block-wise scaling. | ||
""" | ||
|
||
use_per_tensor_scale: bool = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should default to true
Any numeric studies on how / if this improves quant error? Even if its pretty trivial setup |
Stack from ghstack (oldest at bottom):
Summary: This commit adds a QAT flow for NVFP4, following the
numerics in
NVFP4Tensor
closely but without the dtyping casting,swizzling, and the packing/unpacking. Users can call this flow as follows:
Test Plan: