Skip to content
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
7 changes: 4 additions & 3 deletions test/quantization/test_qat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1951,19 +1951,20 @@ def test_infer_fp8_int4_config(self):
self.assertEqual(weight_config.group_size, 128)
self.assertEqual(weight_config.activation_dtype, e4m3_dtype)

def test_infer_int4_weight_only_config(self):
@parametrize("group_size", [256, 128, 64, 32])
def test_infer_int4_weight_only_config(self, group_size: int):
"""
Test that fake quantize configs are correctly inferred from `Int4WeightOnlyConfig`.
"""
from torchao.quantization.qat.fake_quantize_config import (
_infer_fake_quantize_configs,
)

base_config = Int4WeightOnlyConfig(version=2)
base_config = Int4WeightOnlyConfig(version=2, group_size=group_size)
(act_config, weight_config) = _infer_fake_quantize_configs(base_config)
self.assertIsNone(act_config)
self.assertIsInstance(weight_config, Int4WeightFakeQuantizeConfig)
self.assertEqual(weight_config.group_size, 128)
self.assertEqual(weight_config.group_size, group_size)
self.assertEqual(weight_config.activation_dtype, torch.bfloat16)

@unittest.skipIf(not is_sm_at_least_89(), "Need sm89+")
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(
f"Packing format must be one of {supported_packing_formats}"
)
weight_config = Int4WeightFakeQuantizeConfig(
group_size=128,
group_size=base_config.group_size,
activation_dtype=torch.bfloat16,
)
else:
Expand Down
Loading