Skip to content

Fix symbolic nearest1d upsample output rank - #2840

Open
ZedingZhang wants to merge 1 commit into
apple:mainfrom
ZedingZhang:fix/symbolic-nearest1d-output-rank
Open

Fix symbolic nearest1d upsample output rank#2840
ZedingZhang wants to merge 1 commit into
apple:mainfrom
ZedingZhang:fix/symbolic-nearest1d-output-rank

Conversation

@ZedingZhang

Copy link
Copy Markdown

Summary

  • preserve statically known output dimensions in the Torch upsample dialect shape inference
  • keep genuinely dynamic output dimensions symbolic
  • add a TorchExport regression test for symbolic nearest-neighbor 1D interpolation followed by Conv1d
  • add direct shape-inference coverage for both nearest and bilinear Torch dialect ops

Root cause

The PyTorch frontend implements 1D nearest-neighbor interpolation by expanding the input with a dummy width dimension, invoking the 2D Torch upsample dialect op with output_width=1, and squeezing that dimension afterward.

The dialect op previously replaced both output dimensions with fresh symbols unconditionally. As a result, the dummy width was inferred as symbolic even though it was the constant 1. The following squeeze could not remove it during type inference, so Conv1d received a rank-4 input and failed conversion.

This change preserves the concrete value when an output dimension is known, while continuing to create a symbol for a dynamic dimension.

Tests

python -m pytest \
  coremltools/converters/mil/mil/tests/test_programs.py::TestMILBasic::test_get_dialect_namespaces \
  coremltools/converters/mil/mil/tests/test_programs.py::TestMILBasic::test_torch_upsample_preserves_static_output_dimension \
  coremltools/converters/mil/mil/tests/test_programs.py::TestMILBasic::test_invalid_dialect_namespaces_error_out \
  coremltools/converters/mil/frontend/torch/test/test_torch_ops.py::TestUpsample::test_upsample_nearest1d_with_symbolic_output_size_followed_by_conv1d -q

5 passed

The new end-to-end regression test fails with the reported convolution shape error before the fix and passes afterward. It also asserts that the generated MIL convolution receives a rank-3 input.

Fixes #2837

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.

Nearest F.interpolate with a symbolic output size stays rank 4 and breaks the following conv1d

1 participant