Skip to content

[Bug][Relax][ONNX] Dynamic MaxPool SAME_UPPER attempts int(SizeVar) #20398

Description

@Nanmur

Summary

A PP-OCRv6-derived ONNX graph contains a 2-D MaxPool whose spatial width is symbolic and whose attributes are:

kernel_shape = [2, 2]
strides      = [1, 1]
auto_pad     = SAME_UPPER

relax.frontend.onnx.from_onnx fails before producing a Relax module because the MaxPool importer converts every input shape dimension to a Python int. This is invalid when a dimension is a symbolic TIR Var.

The failure is reproducible with the minimal public graph below; no model file is required.

Expected behavior

The Relax ONNX frontend should import this valid ONNX MaxPool with symbolic spatial dimensions, without materializing symbolic dimensions as Python integers.

Actual behavior

Error converting operator MaxPool, with inputs: [x]
...
File "python/tvm/relax/frontend/onnx/onnx_frontend.py", line 3996, in _get_input_spatial_shape
    return _np.array([int(d) for d in tensor.ty.shape], dtype="int64")[2:]
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'Var'

Minimal reproduction

import onnx
from onnx import TensorProto, helper
from tvm.relax.frontend.onnx import from_onnx

x = helper.make_tensor_value_info("x", TensorProto.FLOAT, ["N", 3, 48, "W"])
y = helper.make_tensor_value_info("y", TensorProto.FLOAT, ["N", 3, 48, "W"])
node = helper.make_node(
    "MaxPool",
    ["x"],
    ["y"],
    kernel_shape=[2, 2],
    strides=[1, 1],
    auto_pad="SAME_UPPER",
)
graph = helper.make_graph([node], "dynamic_same_maxpool", [x], [y])
model = helper.make_model(graph, opset_imports=[helper.make_operatorsetid("", 11)])

from_onnx(model)

Environment

TVM: v0.26.0 (c7b458e946bc4266915da582457476bdcd9705ae)
ONNX: 1.22.0
OS: Windows
Frontend: tvm.relax.frontend.onnx.from_onnx

Related issues

Triage

  • needs-triage
  • type: bug

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions