Skip to content

[Relax][ONNX] Support constant output_shape input in MaxUnpool - #21000

Open
cchung100m wants to merge 3 commits into
apache:mainfrom
cchung100m:issue-20888
Open

cchung100m wants to merge 3 commits into
apache:mainfrom
cchung100m:issue-20888

Conversation

@cchung100m

Copy link
Copy Markdown
Contributor

Hi Committers,

This PR fixes issue #20888. Any suggestions would be greatly appreciated.

Root Cause

The ONNX MaxUnpool converter builds total_output_shape as a NumPy array when the optional third input output_shape is absent. When output_shape is provided, the converter assigned the Ralex expression directly: total_output_shape = output_shape That value is a GenericConst (or a relax.Var when keep_params_in_input=True), not a NumPy array. The following relax.ShapeExpr(total_output_shape.tolist()) then fails with: AttributeError: 'GenericConst' object has no attribute 'tolist'

Solution

In the output_shape branch of MaxUnpool._impl_v9:

  • Resolve the input with get_constant(output_shape, params), the same helper other converters (Reshape, Tile, Resize, ...) use to read constant inputs.
  • Convert the resulting constant to an int64 NumPy array, so both paths produce the same type and .tolist() / ShapeExpr work unchanged.
  • If output_shape is not a constant (e.g., a graph input), raise an explicit ValueError instead of an opaque AttributeError, since ShapeExpr needs static values.

@cchung100m
cchung100m marked this pull request as ready for review November 16, 2026 21:38
@cchung100m

Copy link
Copy Markdown
Contributor Author

cc @guan404ming @tlopex

data = np.array([[[[5.0, 6.0], [7.0, 8.0]]]], dtype="float32")
indices = np.array([[[[0, 3], [8, 15]]]], dtype="int64")

out_shape = [1, 1, 4, 4]

@guan404ming guan404ming Nov 21, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This out_shape equals the inferred shape, so the test passes even if output_shape is ignored. Could we use the ONNX reference case and drop the None variant?

for variant in [None, "initializer"]:
check_correctness(make_model(variant), inputs={"X": data}, opset=11)

from_onnx(make_model("initializer"), keep_params_in_input=True)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check_correctness already uses keep_params_in_input=True. Maybe call from_onnx(make_model("initializer")) here to cover the default path from the issue?

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants