Skip to content

preprocess issues around MeanReduce/Reshape nodes and negative axes #23868

Open
@Johansmm

Description

@Johansmm

Describe the issue

Preprocess raises an exception in models with negative axis

To reproduce

import onnx 

model = onnx.parser.parse_model("""
    < ir_version: 8, opset_import: [ "" : 20 ] >
    onnx_mock_model (float[1, 1024, 7, 7] X) => (float[N, ?] Y)
    <int64[2] val_1={-1, -2}, int64[2] val_2={1, -1}>{
        mean = ReduceMean(X, val_1)
        Y = Reshape(mean, val_2)
    }
""")

onnx.save(model, "model.onnx")
python -m onnxruntime.quantization.preprocess --input model.onnx --output model.onnx

Error logs:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "onnxruntime/quantization/preprocess.py", line 127, in <module>
    quant_pre_process(
  File "onnxruntime/quantization/shape_inference.py", line 81, in quant_pre_process
    model = SymbolicShapeInference.infer_shapes(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "onnxruntime/tools/symbolic_shape_infer.py", line 2928, in infer_shapes
    all_shapes_inferred = symbolic_shape_inference._infer_impl()
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "onnxruntime/tools/symbolic_shape_infer.py", line 2692, in _infer_impl
    self.dispatcher_[node.op_type](node)
  File "onnxruntime/tools/symbolic_shape_infer.py", line 1640, in _infer_Reshape
    input_sympy_shape = self._get_sympy_shape(node, 0)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "onnxruntime/tools/symbolic_shape_infer.py", line 410, in _get_sympy_shape
    for d in self._get_shape(node, idx):
TypeError: 'NoneType' object is not iterable

Urgency

No response

Platform

Linux

OS Version

20.04

ONNX Runtime Installation

Released Package

ONNX Runtime Version or Commit ID

1.19.2

ONNX Runtime API

Python

Architecture

X64

Execution Provider

Default CPU

Execution Provider Library Version

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    quantizationissues related to quantization

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions