Skip to content

Commit 382af0d

Browse files
authored
Update quant_primitives.py
1 parent 43492c8 commit 382af0d

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

torchao/quantization/quant_primitives.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,10 @@ def _choose_qparams_affine(
730730
max_val_pos = max_val
731731

732732
if mapping_type == MappingType.SYMMETRIC.name:
733+
# calculate smin and smax individually and choose the larger one. For example, if quant_min = -8 and quant_max = 7.
734+
# If smin is bigger: There would be coverage on negative values down to -8, and less rounding error than the existing SYMMETRIC case.
735+
# If smax is bigger: it covers the positive values up to 7. The round error may be bigger than the existing SYMMETRIC case.
736+
# Either way, there's no out-of-range fp values after quantization.
733737
smin = min_val_neg / float(quant_min)
734738
smax = max_val_pos / float(quant_max)
735739
mask = smin > smax

0 commit comments

Comments
 (0)