-
Notifications
You must be signed in to change notification settings - Fork 181
Open
Description
Checklist
- Checked the issue tracker for similar issues to ensure this is not a duplicate
- Read the documentation to confirm the issue is not addressed there and your configuration is set correctly
- Tested with the latest version to ensure the issue hasn't been fixed
How often does this bug occurs?
always
Expected behavior
希望可以正确通过量化过程,导出对应的espdl文件等
Actual behavior (suspected bug)
从最开始的两个inputs(input和cache)就无法绑定量化参数。
Error logs or terminal output
(idf5.3_py3.8_env) xcl@xcl:~/esp32/esp-dl/examples/tutorial/how_to_quantize_model$ python /home/xcl/esp32/esp-dl/examples/tutorial/how_to_quantize_model/quantize_streaming_model/quantize_kws_streaming_model.py --config /home/xcl/esp32/esp-dl/examples/tutorial/how_to_quantize_model/quantize_streaming_model/kws_model_cfg.toml -o /home/xcl/esp32/esp-dl/examples/tutorial/how_to_quantize_model/quantize_streaming_model --target esp32s3
___________ ____ ____ ____ ____
/ ____/ ___// __ \ / __ \/ __ \/ __ \
/ __/ \__ \/ /_/ /_____/ /_/ / /_/ / / / /
/ /___ ___/ / ____/_____/ ____/ ____/ /_/ /
/_____//____/_/ /_/ /_/ \___\_\
/home/xcl/esp32/esp-dl/examples/tutorial/how_to_quantize_model/quantize_streaming_model/kws_model.py:465: FutureWarning: You are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.
model_py.load_state_dict(torch.load("/home/xcl/esp32/esp-dl/examples/tutorial/how_to_quantize_model/quantize_streaming_model/avg_20.pt"))
tensor([[[4.7930e-06, 4.4210e-06]]], grad_fn=<SigmoidBackward0>)
Input 0: name=input, shape=[1, 40, 1]
Input 1: name=cache, shape=[1, 105, 64]
/home/xcl/esp32/esp-dl/examples/tutorial/how_to_quantize_model/quantize_streaming_model/quantize_kws_streaming_model.py:508: FutureWarning: You are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.
input_dataset = torch.load("/home/xcl/esp32/esp-dl/examples/tutorial/how_to_quantize_model/quantize_streaming_model/input_cache_list_shifted_all.pt")
[06:15:02] PPQ Quantization Fusion Pass Running ... Finished.
[06:15:02] PPQ Quantize Simplify Pass Running ... Finished.
[06:15:02] PPQ Parameter Quantization Pass Running ... Finished.
Calibration Progress(Phase 1): 31%|█████████████████████████▋ | 5Calibration Progress(Phase 1): 38%|██████████████████████████████▊ | 6Calibration Progress(Phase 1): 44%|███████████████████████████████████▉ | 7Calibration Progress(Phase 1): 50%|█████████████████████████████████████████ | 8Calibration Progress(Phase 1): 56%|██████████████████████████████████████████████▏ | 9Calibration Progress(Phase 1): 62%|██████████████████████████████████████████████████▋ | 10Calibration Progress(Phase 1): 69%|███████████████████████████████████████████████████████▋ | 11Calibration Progress(Phase 1): 75%|████████████████████████████████████████████████████████████▊ | 12Calibration Progress(Phase 1): 81%|█████████████████████████████████████████████████████████████████▊ | 13Calibration Progress(Phase 1): 88%|██████████████████████████████████████████████████████████████████████▉ | 14Calibration Progress(Phase 1): 94%|███████████████████████████████████████████████████████████████████████████▉ | 15Calibration Progress(Phase 1): 100%|█████████████████████████████████████████████████████████████████████████████████| 16Calibration Progress(Phase 1): 100%|█████████████████████████████████████████████████████████████████████████████████| 16/16 [00:09<00:00, 1.70it/s]
Calibration Progress(Phase 2): 100%|█████████████████████████████████████████████████████| 16/16 [00:42<00:00, 2.68s/it]
Finished.
[06:16:26] PPQ Quantization Alignment Pass Running ... Finished.
[06:16:26] PPQ Passive Parameter Quantization Running ... Finished.
--------- Network Snapshot ---------
Num of Op: [43]
Num of Quantized Op: [37]
Num of Variable: [99]
Num of Quantized Var: [78]
------- Quantization Snapshot ------
Num of Quant Config: [121]
ACTIVATED: [27]
OVERLAPPED: [40]
PASSIVE: [38]
FP32: [16]
Network Quantization Finished.
Analysing Graphwise Quantization Error(Phrase 1):: 100%|███████████████████████████████████| 8/8 [00:03<00:00, 2.02it/s]
Analysing Graphwise Quantization Error(Phrase 2):: 100%|███████████████████████████████████| 8/8 [00:06<00:00, 1.23it/s]
Layer | NOISE:SIGNAL POWER RATIO
/backbone/network.2/cnn.3/Conv: | ████████████████████ | 3.579%
/backbone/network.1/cnn.3/Conv: | ███████████ | 1.918%
/preprocessing/out/out.0/MatMul: | ███ | 0.534%
/backbone/network.3/cnn.3/Conv: | █ | 0.226%
/backbone/network.3/cnn.0/Conv: | █ | 0.140%
/backbone/network.0/cnn.0/Conv: | | 0.105%
/classifier/linear/MatMul: | | 0.086%
/backbone/network.2/cnn.0/Conv: | | 0.078%
/backbone/network.0/cnn.3/Conv: | | 0.077%
/backbone/network.1/cnn.0/Conv: | | 0.035%
Analysing Layerwise quantization error:: 100%|███████████████████████████████████████████| 10/10 [01:13<00:00, 7.33s/it]
Layer | NOISE:SIGNAL POWER RATIO
/preprocessing/out/out.0/MatMul: | ████████████████████ | 0.005%
/backbone/network.0/cnn.3/Conv: | ███████ | 0.002%
/backbone/network.0/cnn.0/Conv: | ███ | 0.001%
/backbone/network.1/cnn.3/Conv: | ███ | 0.001%
/backbone/network.2/cnn.3/Conv: | ██ | 0.000%
/backbone/network.1/cnn.0/Conv: | █ | 0.000%
/classifier/linear/MatMul: | | 0.000%
/backbone/network.2/cnn.0/Conv: | | 0.000%
/backbone/network.3/cnn.3/Conv: | | 0.000%
/backbone/network.3/cnn.0/Conv: | | 0.000%
test_inputs_shape: torch.Size([1, 1, 40]) torch.Size([1, 64, 105])
test_outputs_shape: torch.Size([1, 1, 2]) torch.Size([1, 64, 105])
test_inputs_value: {'input': tensor([[[ 8.8873, 8.1619, 8.0626, 9.1510, 9.7362, 9.8662, 11.0428,
10.6253, 9.4686, 12.0472, 12.7222, 11.7752, 11.8694, 12.9231,
13.7552, 12.9735, 13.2906, 13.9537, 13.7025, 12.6923, 13.9152,
13.3460, 14.1537, 14.5433, 14.8616, 14.3582, 15.3774, 15.3107,
14.6493, 13.8590, 13.8440, 14.5063, 15.1803, 15.0804, 14.6082,
13.6197, 13.4577, 13.1789, 13.4074, 13.5816]]]), 'cache': tensor([[[1.2228, 1.3030, 1.2440, ..., 1.2343, 1.2358, 1.3491],
[0.4020, 0.3417, 0.3197, ..., 0.8657, 0.6790, 1.3203],
[0.0000, 0.0000, 0.0000, ..., 0.3191, 0.5939, 0.6753],
...,
[0.5019, 0.5771, 0.5291, ..., 0.6183, 0.4323, 0.3718],
[0.0000, 0.0000, 0.1158, ..., 0.1437, 0.3306, 0.7760],
[0.0000, 0.0000, 0.0000, ..., 0.0404, 0.0640, 0.1074]]])}
test_outputs_value: {'output': tensor([[[1.4305e-06, 3.0279e-05]]]), 'r_cache': tensor([[[1.0000, 1.0000, 1.0000, ..., 1.2500, 1.3438, 1.0000],
[0.3438, 0.3125, 0.2812, ..., 0.6875, 1.3125, 1.4688],
[0.0000, 0.0000, 0.0000, ..., 0.5938, 0.6875, 1.0625],
...,
[0.5938, 0.5312, 0.5312, ..., 0.4375, 0.3750, 0.3750],
[0.0000, 0.1250, 0.0000, ..., 0.3438, 0.7812, 0.4062],
[0.0000, 0.0000, 0.0000, ..., 0.0625, 0.0938, 0.1250]]])}
[INFO][ESPDL][2025-06-25 06:17:51]: Skip /backbone/network.0/Constant_1_output_0 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_6 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_19 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_11 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip /backbone/network.1/Constant_1_output_0 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_7 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_21 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_13 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip /backbone/network.2/Constant_1_output_0 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_8 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_23 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_15 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip /backbone/network.3/Constant_1_output_0 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_9 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_25 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_17 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip /backbone/network.0/Constant_1_output_0 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_6 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_19 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_11 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip /backbone/network.1/Constant_1_output_0 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_7 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_21 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_13 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip /backbone/network.2/Constant_1_output_0 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_8 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_23 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_15 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip /backbone/network.3/Constant_1_output_0 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_9 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_25 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_17 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip /backbone/network.0/Constant_1_output_0 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_6 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_19 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_11 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip /backbone/network.1/Constant_1_output_0 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_7 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_21 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_13 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip /backbone/network.2/Constant_1_output_0 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_8 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_23 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_15 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip /backbone/network.3/Constant_1_output_0 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_9 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_25 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_17 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: skip not QuantableOperation
[INFO][ESPDL][2025-06-25 06:17:51]: skip not QuantableOperation
[INFO][ESPDL][2025-06-25 06:17:51]: skip not QuantableOperation
[INFO][ESPDL][2025-06-25 06:17:51]: skip not QuantableOperation
[INFO][ESPDL][2025-06-25 06:17:51]: skip not QuantableOperation
[INFO][ESPDL][2025-06-25 06:17:51]: skip not QuantableOperation
[INFO][ESPDL][2025-06-25 06:17:51]: skip not QuantableOperation
[INFO][ESPDL][2025-06-25 06:17:51]: skip not QuantableOperation
[INFO][ESPDL][2025-06-25 06:17:51]: skip not QuantableOperation
[INFO][ESPDL][2025-06-25 06:17:51]: skip not QuantableOperation
[INFO][ESPDL][2025-06-25 06:17:51]: skip not QuantableOperation
[INFO][ESPDL][2025-06-25 06:17:51]: skip not QuantableOperation
[INFO][ESPDL][2025-06-25 06:17:51]: Skip /backbone/network.0/Constant_1_output_0 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_6 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_19 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_11 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: skip not QuantableOperation
[INFO][ESPDL][2025-06-25 06:17:51]: Skip /backbone/network.1/Constant_1_output_0 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_7 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_21 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_13 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip /backbone/network.2/Constant_1_output_0 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_8 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_23 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_15 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: skip not QuantableOperation
[INFO][ESPDL][2025-06-25 06:17:51]: Skip /backbone/network.3/Constant_1_output_0 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_9 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_25 because it's not exportable
[INFO][ESPDL][2025-06-25 06:17:51]: Skip PPQ_Variable_17 because it's not exportable
[WARNING][ESPDL][2025-06-25 06:17:51]: /backbone/Slice_3_output_0 does not bind exponents parameter
[WARNING][ESPDL][2025-06-25 06:17:51]: /backbone/Slice_1_output_0 does not bind exponents parameter
[WARNING][ESPDL][2025-06-25 06:17:51]: input does not bind exponents parameter
[WARNING][ESPDL][2025-06-25 06:17:51]: /global_cmvn/Mul_output_0 does not bind exponents parameter
[WARNING][ESPDL][2025-06-25 06:17:51]: cache does not bind exponents parameter
[WARNING][ESPDL][2025-06-25 06:17:51]: /backbone/Slice_output_0 does not bind exponents parameter
[WARNING][ESPDL][2025-06-25 06:17:51]: /backbone/Slice_2_output_0 does not bind exponents parameter
[WARNING][ESPDL][2025-06-25 06:17:51]: /global_cmvn/Sub_output_0 does not bind exponents parameter
Traceback (most recent call last):
File "/home/xcl/esp32/esp-dl/examples/tutorial/how_to_quantize_model/quantize_streaming_model/quantize_kws_streaming_model.py", line 553, in <module>
quant_ppq_graph = espdl_quantize_onnx(
File "/home/xcl/.espressif/python_env/idf5.3_py3.8_env/lib/python3.8/site-packages/ppq/core/defs.py", line 54, in _wrapper
return func(*args, **kwargs)
File "/home/xcl/.espressif/python_env/idf5.3_py3.8_env/lib/python3.8/site-packages/ppq/api/espdl_interface.py", line 285, in espdl_quantize_onnx
PFL.Exporter(platform=target_platform).export(
File "/home/xcl/.espressif/python_env/idf5.3_py3.8_env/lib/python3.8/site-packages/ppq/parser/espdl_exporter.py", line 126, in export
graph = self.prepare_graph(graph, exporter_patterns, int16_lut_step)
File "/home/xcl/.espressif/python_env/idf5.3_py3.8_env/lib/python3.8/site-packages/ppq/parser/espdl_exporter.py", line 241, in prepare_graph
if (output_exponent[0] - input0_exponent[0] - input1_exponent[0]) < 0:
TypeError: 'NoneType' object is not subscriptableSteps to reproduce the behavior
- git clone了最新的esp-dl,按照tutorial中的流式模型的example修改了quantize_kws_streaming_model.py(quantize_kws_streaming_model.txt);
- 在文件夹下esp-dl/examples/tutorial/how_to_quantize_model/quantize_streaming_model运行代码 python /home/xcl/esp32/esp-dl/examples/tutorial/how_to_quantize_model/quantize_streaming_model/quantize_kws_streaming_model.py --config /home/xcl/esp32/esp-dl/examples/tutorial/how_to_quantize_model/quantize_streaming_model/kws_model_cfg.toml -o /home/xcl/esp32/esp-dl/examples/tutorial/how_to_quantize_model/quantize_streaming_model --target esp32s3
- 好像不能上传onnx文件,我的模型结构如图,因为一直没有办法绑定上参数,我是新手,又不知道哪里有问题,问了gpt,在输入后加了个恒等的conv算子,结果是可以绑定上,但是量化的时候误差达到了100%,测试结果对不上。
- 我的校准数据集总共有1097条[input,cache]组成。其中input的shape为[1,1,40];cache的shape为[1,64,105]。
- 还有一个问题就是,加了恒等算子之后量化出来的模型的输入维度调换变成[1,40,1],[1,105,64];如果flash到板子上,cpp代码中的输入是不是也要reshape一下?
quantize_kws_streaming_model.txt
Project release version
latest
System architecture
Intel/AMD 64-bit (modern PC, older Mac)
Operating system
Linux
Operating system version
Ubuntu 20.04.6 LTS
Shell
Bash
Additional context
这个是我在两个输入后面都加上了恒等conv之后的onnx,以及terminal输出outlog信息
Metadata
Metadata
Assignees
Labels
No labels


