# Fake quantization ONNX model parse ERROR using TensorRT 8

**URL:** <https://forums.developer.nvidia.com/t/fake-quantization-onnx-model-parse-error-using-tensorrt-8/190129>\
**Category:** TensorRT\
**Created:** [September 26, 2021, 3:15pm UTC](https://forums.developer.nvidia.com/t/fake-quantization-onnx-model-parse-error-using-tensorrt-8/190129 "2021-09-26T15:15:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex.spivakovsky](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@alex.spivakovsky](https://forums.developer.nvidia.com/u/alex.spivakovsky)\
**Post date:** [September 26, 2021, 3:15pm UTC](https://forums.developer.nvidia.com/t/fake-quantization-onnx-model-parse-error-using-tensorrt-8/190129/1 "2021-09-26T15:15:22Z")

</div>

## Description

A clear and concise description of the bug or issue.

## Environment

**TensorRT Version** : 8.0.1.6  
**GPU Type** : 2080  
**Nvidia Driver Version** : 470.63.01  
**CUDA Version** : 11.3  
**CUDNN Version** : 8.0  
**Operating System + Version** : Ubuntu 18.04  
**Python Version (if applicable)**: 3.7  
**PyTorch Version (if applicable)**: 1.9

Hello,  
I had successfully per-channel quantized and exported calibrated int8 model using pytorch quantization toolbox and torch ONNX export (using op-13).  
The QuantizeLinear related to quantized weights blocks of the model include a Tensor with output dimension same as the number of channels of the layer they represent, thus also having an axis attribute set by the ONNX export  
function fake\_quantize\_per\_channel\_affine defined in the op-13.  
However when I load the ONNX file, the checker fails with the following error:

**Traceback (most recent call last):**  
\*\* File “/vayaalgo/Work/Pruning/Convert2TRT/main.py”, line 244, in \*\*  
\*\* import\_ONNX()\*\*  
\*\* File “/vayaalgo/Work/Pruning/Convert2TRT/utils/models\_quant.py”, line 15, in import\_ONNX\*\*  
\*\* engine = backend.prepare(depthnet, device=‘CUDA:0’)\*\*  
\*\* File “/usr/local/lib/python3.7/dist-packages/onnx\_tensorrt-8.0.1-py3.7.egg/onnx\_tensorrt/backend.py”, line 235, in prepare\*\*  
\*\* File “/usr/local/lib/python3.7/dist-packages/onnx/backend/base.py”, line 74, in prepare\*\*  
\*\* onnx.checker.check\_model(model)\*\*  
\*\* File “/usr/local/lib/python3.7/dist-packages/onnx/checker.py”, line 91, in check\_model\*\*  
\*\* C.check\_model(model.SerializeToString())\*\*  
**onnx.onnx\_cpp2py\_export.checker.ValidationError: Unrecognized attribute: axis for operator QuantizeLinear**

**==\> Context: Bad node spec: input: “features\_0\_0.weight” input: “465” input: “1337” output: “468” name: “QuantizeLinear\_7” op\_type: “QuantizeLinear” attribute { name: “axis” i: 0 type: INT }**

How to solve this issue?

---

<div class="post-metadata">

**Author:** ![NVES](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/nves/32/14043_2.png) [@NVES](https://forums.developer.nvidia.com/u/NVES)\
**Post date:** [September 26, 2021, 5:08pm UTC](https://forums.developer.nvidia.com/t/fake-quantization-onnx-model-parse-error-using-tensorrt-8/190129/2 "2021-09-26T17:08:37Z")

</div>

Hi,  
Request you to share the ONNX model and the script if not shared already so that we can assist you better.  
Alongside you can try few things:

> **[Quick Start Guide — NVIDIA TensorRT](https://docs.nvidia.com/deeplearning/tensorrt/latest/getting-started/quick-start-guide.html)**

1. validating your model with the below snippet

# check\_model.py

import sys  
import onnx  
filename = yourONNXmodel  
model = onnx.load(filename)  
onnx.checker.check\_model(model).  
2) Try running your model with trtexec command.  
[https://github.com/NVIDIA/TensorRT/tree/master/samples/opensource/trtexec](https://github.com/NVIDIA/TensorRT/tree/master/samples/opensource/trtexec)  
In case you are still facing issue, request you to share the trtexec “”–verbose"" log for further debugging  
Thanks!

---

<div class="post-metadata">

**Author:** ![alex.spivakovsky](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@alex.spivakovsky](https://forums.developer.nvidia.com/u/alex.spivakovsky)\
**Post date:** [September 26, 2021, 6:13pm UTC](https://forums.developer.nvidia.com/t/fake-quantization-onnx-model-parse-error-using-tensorrt-8/190129/5 "2021-09-26T18:13:37Z")

</div>

[quantized\_depthnet.onnx](https://forums.developer.nvidia.com/uploads/short-url/jVWS0n1qluTjHamRfbWqre8WZa7.onnx) (7.7 MB)  
Hello,  
Please find the attached ONNX file describing my model.  
The model = onnx.load(filename) command loads the model, however onnx.checker.check\_model(model) fails with the same error as above: **onnx.onnx\_cpp2py\_export.checker.ValidationError: Unrecognized attribute: axis for operator QuantizeLinear**

---

<div class="post-metadata">

**Author:** ![spolisetty](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/spolisetty/32/14047_2.png) [@spolisetty](https://forums.developer.nvidia.com/u/spolisetty)\
**Post date:** [September 27, 2021, 1:26pm UTC](https://forums.developer.nvidia.com/t/fake-quantization-onnx-model-parse-error-using-tensorrt-8/190129/6 "2021-09-27T13:26:40Z")

</div>

Hi,

Looks like there is something wrong with pytorch to onnx conversion. Please refer following link/user guide to make sure you’re converting correctly.  
[https://docs.nvidia.com/deeplearning/tensorrt/pytorch-quantization-toolkit/docs/userguide.html#export-to-onnx](https://docs.nvidia.com/deeplearning/tensorrt/pytorch-quantization-toolkit/docs/userguide.html#export-to-onnx)

Thank you.
