microsoft / nni

An open source AutoML toolkit for automate machine learning lifecycle, including feature engineering, neural architecture search, model compression and hyper-parameter tuning.
https://nni.readthedocs.io
MIT License
14.06k stars 1.82k forks source link

when I run quantization_speedup.py in /examples/tutorials, get erros like this: #4938

Open Shining-Tears opened 2 years ago

Shining-Tears commented 2 years ago

IndexError Traceback (most recent call last) /home/chenwz/code/pycharm/test2.ipynb Cell 6' in <cell line: 4>() 2 input_shape = (32, 1, 28, 28) 3 engine = ModelSpeedupTensorRT(model, input_shape, config=calibration_config, batchsize=32) ----> 4 engine.compress() 5 test_trt(engine)

File ~/.conda/envs/nni-wenze/lib/python3.8/site-packages/nni/compression/pytorch/quantization_speedup/integrated_tensorrt.py:291, in ModelSpeedupTensorRT.compress(self) 288 assert self.input_shape is not None 290 # Convert pytorch model to onnx model and save onnx model in onnxpath --> 291 , self.onnx_config = fonnx.torch_to_onnx(self.model, self.config, input_shape=self.input_shape, 292 model_path=self.onnx_path, input_names=self.input_names, output_names=self.output_names) 294 if self.calib_data_loader is not None: 295 assert self.calibrate_type is not None

File ~/.conda/envs/nni-wenze/lib/python3.8/site-packages/nni/compression/pytorch/quantization_speedup/frontend_to_onnx.py:144, in torch_to_onnx(model, config, input_shape, model_path, input_names, output_names) 142 # Load onnx model 143 model_onnx = onnx.load(model_path) --> 144 model_onnx, onnx_config = unwrapper(model_onnx, index2name, config) 145 onnx.save(model_onnx, model_path) 147 onnx.checker.check_model(model_onnx)

File ~/.conda/envs/nni-wenze/lib/python3.8/site-packages/nni/compression/pytorch/quantization_speedup/frontend_to_onnx.py:82, in unwrapper(model_onnx, index2name, config) 80 mul_nd = model_onnx.graph.node[idx-1] ... ---> 82 index = int(onnx.numpy_helper.to_array(const_nd.attribute[0].t)) 83 if index != -1: 84 name = index2name[index]

IndexError: list index (0) out of range

Environment:

Configuration:

Log message:

How to reproduce it?:

Shining-Tears commented 2 years ago

not change the tutorial file

Raychen0617 commented 2 years ago

I got the same error, do you find the solution?

Shining-Tears commented 2 years ago

@Raychen0617 Hi, You can reduce the pytorch version to 1.9.0

Raychen0617 commented 2 years ago

Hi, @matudouchen after reducing my pytorch version to 1.9.1, I got another error running quantization_quick_start_mnist.py

[07/15/2022-06:54:23] [TRT] [W] DynamicRange(min: -0.424213, max: 2.82149). Dynamic range should be symmetric for better accuracy. Traceback (most recent call last): File "quantization_quick_start_mnist.py", line 93, in engine.compress() File "/opt/conda/lib/python3.7/site-packages/nni/compression/pytorch/quantization_speedup/integrated_tensorrt.py", line 298, in compress context = self._tensorrt_build_withoutcalib(self.onnx_path) File "/opt/conda/lib/python3.7/site-packages/nni/compression/pytorch/quantization_speedup/integrated_tensorrt.py", line 348, in _tensorrt_build_withoutcalib engine = build_engine(onnx_path, self.onnx_config, self.extra_layer_bits, self.strict_datatype) File "/opt/conda/lib/python3.7/site-packages/nni/compression/pytorch/quantization_speedup/integrated_tensorrt.py", line 198, in build_engine handle_gemm(network, i, config) File "/opt/conda/lib/python3.7/site-packages/nni/compression/pytorch/quantization_speedup/integrated_tensorrt.py", line 82, in handle_gemm pre_in_tensor.dynamic_range = (tracked_min_input, tracked_max_input) AttributeError: 'NoneType' object has no attribute 'dynamic_range'