python - 手动更改的量化权重未反映在 state_dict()
问题描述
PyTorch:1.7.0
我将量化权重修改为净后量化,如下所示:
# 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
但是,model_int8.features[0].weight
显示更新的值,但model_int8.state_dict()['features.0.weight']
显示旧的值。
我也尝试保存修改后的模型并重新加载,但问题仍然存在。
问题是哪些权重值被用于推理?我没有看到分类结果的变化。
解决方案
推荐阅读
- c - segmentation fault(core dumped) error while using inline assembly
- python - Autoencoder for Tabular Data with Discrete Values
- android - 如何从服务类更改片段的文本?
- laravel - Laravel 表单请求未验证请求
- python - conv2d():参数“输入”(位置 1)必须是张量,而不是循环函数中的 str
- java - 在我的 contains 和 equals 方法中使用它之前,我是否必须将 Object 对象转换为特定类型?
- rdf - 如何在编写 rdf 三元组时为对象提供数值
- sql - Postgres - 在单独的表格中优化动态标题
- python - Python:dict 和冒号的意外行为。( my_dict['key']: None ) 冒号 ( : ) 有什么作用?
- python - pyinstaller 和外部软件设置