Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.2k views
in Technique[技术] by (71.8m points)

python - Manually changed quantized weights not reflecting in state_dict()

PyTorch: 1.7.0

I modified the quantized weights a net post-quantization as follows:

# instantiate the quantized net (not shown here).

# get one of the conv layers
tmp = model_int8.state_dict()['features.0.weight']
scales = tmp.q_per_channel_scales()
zero_pts = tmp.q_per_channel_zero_points()
axis = tmp.q_per_channel_axis()

# get int repr
tmp_int8 = tmp.int_repr()

# change value (value change is dependent on the int8 value)
tmp_int8[0][0][0][0] = new_value

# how to convert tmp_int8 to torch.qint8 type?
new_tmp = torch._make_per_channel_quantized_tensor(tmp_int8, scales, zero_pts, axis)

# based on the above step:
model_int8.features[0].weight = new_tmp

However, model_int8.features[0].weight shows updated values, but model_int8.state_dict()['features.0.weight'] shows old vales.

I also tried saving the modified model and reloading, but the problem persists.

Question is which weight values are being used for inference? I do not see change in the classification results.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...