File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change 31
31
from torchao .quantization .qat .embedding import (
32
32
FakeQuantizedEmbedding ,
33
33
)
34
+ from torchao .quantization .qat .fake_quantizer import (
35
+ FakeQuantizer ,
36
+ )
34
37
from torchao .quantization .qat .linear import (
35
38
FakeQuantizedLinear ,
36
39
Int4WeightOnlyQATLinear ,
@@ -1348,6 +1351,21 @@ def test_fake_quantize_config_torch_intx(self):
1348
1351
out2 = linear2 (* x2 )
1349
1352
torch .testing .assert_close (out1 , out2 , atol = 0 , rtol = 0 )
1350
1353
1354
+ @unittest .skipIf (
1355
+ not TORCH_VERSION_AT_LEAST_2_6 , "skipping when torch version is 2.6 or lower"
1356
+ )
1357
+ def test_fake_quantizer_repr (self ):
1358
+ """
1359
+ Test that `repr(FakeQuantizer(config))` exposes useful config details.
1360
+ """
1361
+ config = FakeQuantizeConfig (torch .int4 , group_size = 128 )
1362
+ fake_quantizer = FakeQuantizer (config )
1363
+ fake_quantizer_repr = repr (fake_quantizer )
1364
+ self .assertTrue ("dtype=torch.int4" in fake_quantizer_repr )
1365
+ self .assertTrue ("group_size=128" in fake_quantizer_repr )
1366
+ self .assertTrue ("PerGroup" in fake_quantizer_repr )
1367
+ self .assertTrue ("MappingType.SYMMETRIC" in fake_quantizer_repr )
1368
+
1351
1369
1352
1370
if __name__ == "__main__" :
1353
1371
unittest .main ()
Original file line number Diff line number Diff line change @@ -134,3 +134,9 @@ def _should_compute_qparams(self) -> bool:
134
134
Return whether we need to compute new scales and zero points.
135
135
"""
136
136
return self .config .is_dynamic or self .scale is None or self .zero_point is None
137
+
138
+ def __repr__ (self ) -> str :
139
+ """
140
+ Return a human readable representation of this `FakeQuantizer` with config details.
141
+ """
142
+ return "FakeQuantizer(%s)" % self .config
You can’t perform that action at this time.
0 commit comments