Skip to content
Snippets Groups Projects
Commit 0ae07549 authored by Guy Jacob's avatar Guy Jacob
Browse files

Post-train quant bugfix: squeeze scale factor shape when quantizing bias

parent 1210f412
No related branches found
No related tags found
No related merge requests found
...@@ -359,7 +359,7 @@ class RangeLinearQuantParamLayerWrapper(RangeLinearQuantWrapper): ...@@ -359,7 +359,7 @@ class RangeLinearQuantParamLayerWrapper(RangeLinearQuantWrapper):
self.has_bias = hasattr(wrapped_module, 'bias') and wrapped_module.bias is not None self.has_bias = hasattr(wrapped_module, 'bias') and wrapped_module.bias is not None
if self.has_bias: if self.has_bias:
if self.preset_act_stats: if self.preset_act_stats:
linear_quantize_clamp(wrapped_module.bias.data, self.accum_scale, 0, linear_quantize_clamp(wrapped_module.bias.data, self.accum_scale.squeeze(), 0,
self.accum_min_q_val, self.accum_max_q_val, inplace=True) self.accum_min_q_val, self.accum_max_q_val, inplace=True)
else: else:
b_scale, b_zero_point = _get_quant_params_from_tensor(wrapped_module.bias, num_bits_params, self.mode) b_scale, b_zero_point = _get_quant_params_from_tensor(wrapped_module.bias, num_bits_params, self.mode)
...@@ -387,7 +387,7 @@ class RangeLinearQuantParamLayerWrapper(RangeLinearQuantWrapper): ...@@ -387,7 +387,7 @@ class RangeLinearQuantParamLayerWrapper(RangeLinearQuantWrapper):
if self.has_bias: if self.has_bias:
# Re-quantize bias to match x * w scale: b_q' = (in_scale * w_scale / b_scale) * (b_q + b_zero_point) # Re-quantize bias to match x * w scale: b_q' = (in_scale * w_scale / b_scale) * (b_q + b_zero_point)
self.wrapped_module.bias.data = linear_quantize_clamp(self.base_b_q + self.b_zero_point, self.wrapped_module.bias.data = linear_quantize_clamp(self.base_b_q + self.b_zero_point,
self.accum_scale / self.b_scale, 0, self.accum_scale.squeeze() / self.b_scale, 0,
self.accum_min_q_val, self.accum_max_q_val) self.accum_min_q_val, self.accum_max_q_val)
# Note the main terms within the summation is: # Note the main terms within the summation is:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment