-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add bias quantization in QAT and refactor the code of weight quantization #2914
Conversation
out[out == 0] = 1 | ||
return out | ||
weight[weight == 0] = 1 | ||
wrapper.module.weight.data = weight |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return
is removed? returned value is never used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returned value is quantized weight. There is no need to return in this version because weight is quantized in place in the function quantize_weight().
assert math.isclose(model.conv2.module.scale, 6 / 255, abs_tol=eps) | ||
assert model.conv2.module.zero_point in (42, 43) | ||
# test value of weight and bias after quantization | ||
weight = torch.tensor([[1.1287, 2.3456], [3.7814, 5.9723]]) | ||
weight_valid = torch.tensor([[1.1242, 2.3421], [3.7707, 5.9723]]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just curious, how are the values of weight_valid
and bias_valid
calculated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weight_valid and bias_valid are calculated by quantization function manually. I will modify the test case and annotation after code freeze.
weight_bits = get_bits_length(config, 'weight') | ||
quant_start_step = config.get('quant_start_step', 0) | ||
assert weight_bits >= 1, "quant bits length should be at least 1" | ||
|
||
if quant_start_step > self.steps: | ||
return weight | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add return here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I have fixed it.
Add bias quantization and refactor the code. If this PR was merged, I would submit a new PR to modify the doc.