Skip to content

[preprocess] Pad is not folded in Conv when opset_import is > 20 #23973

@Johansmm

Description

@Johansmm

Describe the issue

Preprocess does not fold 'Pad' in 'Conv' when model has an opset version higher than 20.

To reproduce

def test_pad(op_version=22):
    path = "opt_model.onnx"
    model = onnx.parser.parse_model(
        """
        <ir_version: 9, opset_import: ["": {op_version}]>
        agraph (float[1, 3, 10, 10] X) => (float[1, ?, ?, ?] Y){{
            pad_values = Constant<value_ints=[0,0,1,1,0,0,1,1]>()
            pad = Pad(X, pad_values)
            Y = Conv(pad, W)
        }}
        """.format(
            op_version=op_version
        )
    )
    w = onnx.numpy_helper.from_array(np.ones((3, 3, 3, 3), "float32"), "W")
    model.graph.initializer.extend([w])

    ort_quant.quant_pre_process(model, path, skip_symbolic_shape=True)

    opt_model = onnx.load(path)
    current_nodes = [node.op_type for node in opt_model.graph.node]
    print([node.op_type for node in opt_model.graph.node])
    assert current_nodes == ["Conv"], f"Wrong. Current nodes: {current_nodes}."

test_pad(op_version=18) # This pass
test_pad(op_version=21) # This raises an exception

Urgency

No response

Platform

Linux

OS Version

Ubuntu 22.04

ONNX Runtime Installation

Released Package

ONNX Runtime Version or Commit ID

1.21.0

ONNX Runtime API

Python

Architecture

X64

Execution Provider

Default CPU

Execution Provider Library Version

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleissues that have not been addressed in a while; categorized by a bot

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions