Skip to content

Fix float8 + int4 QAT #2851

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

Merged
merged 1 commit into from
Aug 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions test/quantization/test_qat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1932,6 +1932,26 @@ def test_quantize_api_fp8_int4(self):
target_convert_sqnr=float("inf"),
)

@unittest.skipIf(not _CUDA_IS_AVAILABLE, "skipping when cuda is not available")
def test_infer_fp8_int4_config(self):
"""
Test that fake quantize configs are correctly inferred from
`Float8DynamicActivationInt4WeightConfig`.
"""
from torchao.quantization.qat.fake_quantize_config import (
_infer_fake_quantize_configs,
)

base_config = Float8DynamicActivationInt4WeightConfig()
(act_config, weight_config) = _infer_fake_quantize_configs(base_config)
self.assertIsInstance(act_config, Float8FakeQuantizeConfig)
self.assertEqual(act_config.dtype, torch.float8_e4m3fn)
self.assertIsInstance(act_config.granularity, PerRow)
self.assertIsInstance(weight_config, IntxFakeQuantizeConfig)
self.assertEqual(weight_config.dtype, torch.int4)
self.assertEqual(weight_config.group_size, 128)
self.assertTrue(weight_config.is_symmetric)


instantiate_parametrized_tests(TestQAT)

Expand Down
2 changes: 1 addition & 1 deletion torchao/quantization/qat/fake_quantize_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ def _infer_fake_quantize_configs(
)
weight_config = IntxFakeQuantizeConfig(
dtype=torch.int4,
group_size=base_config.group_size,
group_size=128,
is_symmetric=True,
)
else:
Expand Down
Loading