You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
❓ RuntimeError: [Error thrown at core/conversion/converters/converter_util.cpp:251] Unable to freeze tensor of type Int64/Float64 into constant layer, try to compile model with truncate_long_and_double enabled:
A pre-trained Torch model like Resnet18 was loaded
The model was quantized using pytorch_quantization.quant_modules.initialize()
The quantized model was calibrated
The model was fine-tuned (QAT)
I tried to convert the fine-tuned model to TensorRT using trt_mod = torch_tensorrt.compile(qat_model, inputs=[torch_tensorrt.Input([32, 3, 32, 32])], enabled_precisions={torch.int8})
but I encountered the error below:
File "/home/i2027/anaconda3/envs/p/lib/python3.10/site-packages/torch_tensorrt/_compile.py", line 133, in compile return torch_tensorrt.ts.compile( File "/home/i2027/anaconda3/envs/p/lib/python3.10/site-packages/torch_tensorrt/ts/_compiler.py", line 139, in compile compiled_cpp_mod = _C.compile_graph(module._c, _parse_compile_spec(spec)) RuntimeError: [Error thrown at core/conversion/converters/converter_util.cpp:251] Unable to freeze tensor of type Int64/Float64 into constant layer, try to compile model with truncate_long_and_double enabled
I have checked the model parameters and all of them were of type float32. I don't know why TorchTensorRT complains about Int64/Float64! Please note that I have managed to convert a simple CNN to TensorRT using the method described above successfully. However, I failed to convert an existing torchvision model using the steps above. I will be grateful for any hint.
Environment
PyTorch Version: 2.0.1+cu118
CPU Architecture: x86
OS: Ubuntu 20.04
How you installed PyTorch: pip
Python version: 3.10.11
CUDA version: 12.1
GPU models and configuration: GeForce GTX 1080 - 12 GB
Model parameters and all of them were of type float32.
truncate_long_and_double does not apply just to model weights, it also deals with things such as tensor indexing which in PyTorch/TorchScript happens in int64 but when we convert to tensorrt this needs to be in int32.
What happens if you add truncate_long_and_double=True to your compile settings?
Thank you very much for your response.
If I add the argument truncate_long_and_double=True the accuracy become 10% from 80%.
I don't know the reason but the problem was from PyCharm. I was working with it and it had errors. But when I used the terminal or VSCode there was no problem and no warning/error about int64.
❓ RuntimeError: [Error thrown at core/conversion/converters/converter_util.cpp:251] Unable to freeze tensor of type Int64/Float64 into constant layer, try to compile model with truncate_long_and_double enabled:
pytorch_quantization.quant_modules.initialize()
trt_mod = torch_tensorrt.compile(qat_model, inputs=[torch_tensorrt.Input([32, 3, 32, 32])], enabled_precisions={torch.int8})
but I encountered the error below:
File "/home/i2027/anaconda3/envs/p/lib/python3.10/site-packages/torch_tensorrt/_compile.py", line 133, in compile
return torch_tensorrt.ts.compile(
File "/home/i2027/anaconda3/envs/p/lib/python3.10/site-packages/torch_tensorrt/ts/_compiler.py", line 139, in compile
compiled_cpp_mod = _C.compile_graph(module._c, _parse_compile_spec(spec))
RuntimeError: [Error thrown at core/conversion/converters/converter_util.cpp:251] Unable to freeze tensor of type Int64/Float64 into constant layer, try to compile model with truncate_long_and_double enabled
I have checked the model parameters and all of them were of type float32. I don't know why TorchTensorRT complains about Int64/Float64! Please note that I have managed to convert a simple CNN to TensorRT using the method described above successfully. However, I failed to convert an existing torchvision model using the steps above. I will be grateful for any hint.
Environment
PyTorch Version: 2.0.1+cu118
CPU Architecture: x86
OS: Ubuntu 20.04
How you installed PyTorch: pip
Python version: 3.10.11
CUDA version: 12.1
GPU models and configuration: GeForce GTX 1080 - 12 GB
All pckages versions:
Additional context
The code is available at https://github.com/panahikhas/TensorRT-QAT/blob/main/torch-tensorrt-QAT.py to reproduce the results.
The text was updated successfully, but these errors were encountered: