File tree Expand file tree Collapse file tree 1 file changed +6
-0
lines changed Expand file tree Collapse file tree 1 file changed +6
-0
lines changed Original file line number Diff line number Diff line change @@ -944,10 +944,16 @@ def _choose_qparams_affine(
944
944
else :
945
945
zero_point = torch .full_like (scale , int ((quant_max + quant_min + 1 ) / 2 ))
946
946
scale = torch .clamp (scale , min = eps )
947
+ if torch .is_floating_point (scale ):
948
+ # Prevent 1.0 / scale to become Inf.
949
+ scale = torch .clamp (scale , min = 2 * torch .finfo (scale .dtype ).tiny )
947
950
else :
948
951
assert mapping_type == MappingType .ASYMMETRIC .name
949
952
scale = (max_val_pos - min_val_neg ) / float (quant_max - quant_min )
950
953
scale = torch .clamp (scale , min = eps )
954
+ if torch .is_floating_point (scale ):
955
+ # Prevent 1.0 / scale to become Inf.
956
+ scale = torch .clamp (scale , min = 2 * torch .finfo (scale .dtype ).tiny )
951
957
if zero_point_domain == ZeroPointDomain .NONE .name :
952
958
zero_point = None
953
959
else :
You can’t perform that action at this time.
0 commit comments