---
title: QDQ格式模型推理过程中出现ONNXRuntimeError报错
description: "QDQ（Quantize and DeQuantize）格式模型，比如从TensorFlow转换或从PyTorch导出的量化感知训练（QAT）模型，在ONNX Runtime1.8.0及以上的CPU版本环境下推理，出现类似下图的ONNXRuntimeError报错。（QDQ格式模型具体介绍请参见Link(https://onnxruntime.ai/docs/performance/quantization.html)）"
url: https://www.hiascend.com/document/detail/zh/canncommercial/latest/devaids/amct/atlasamct_16_0361.html
sourcePath: /source/zh/canncommercial/900/devaids/amct/atlasamct_16_0361.html
indexId: 05da27dcacc830cedf4f60925583c9d3838100fb6e61b15141e6cf989d4011f165
---
# QDQ格式模型推理过程中出现ONNXRuntimeError报错

#### 问题现象描述

QDQ（Quantize and DeQuantize）格式模型，比如从TensorFlow转换或从PyTorch导出的量化感知训练（QAT）模型，在ONNX Runtime1.8.0及以上的CPU版本环境下推理，出现类似下图的ONNXRuntimeError报错。（QDQ格式模型具体介绍请参见Link(https://onnxruntime.ai/docs/performance/quantization.html)）


#### 原因分析

ONNX Runtime为了提高性能，提供了多种图优化方式，默认情况下，启用所有优化。在执行优化过程中，模型和ONNX Runtime版本间存在不兼容问题，导致上述报错。


#### 解决措施

调用InferenceSession函数执行推理时，配置入参SessionOptions的图优化级别属性值为ORT_DISABLE_ALL，禁用所有优化。```
import onnxruntime as ort
import amct_onnx as amct

amct.AMCT_SO.graph_optimization_level = ort.GraphOptimizationLevel.ORT_DISABLE_ALL
ort_session = ort.InferenceSession('model.onnx', amct.AMCT_SO)
```
