Skip to content

Fix CoreML reshape to support dynamic shapes#27324

Open
ingyukoh wants to merge 2 commits intomicrosoft:mainfrom
ingyukoh:fix-coreml-reshape
Open

Fix CoreML reshape to support dynamic shapes#27324
ingyukoh wants to merge 2 commits intomicrosoft:mainfrom
ingyukoh:fix-coreml-reshape

Conversation

@ingyukoh
Copy link
Contributor

CoreML MIL supports -1 in shape dimensions and can infer at runtime. This fix allows dynamic
input shapes for reshape operations.

Fixes #26328

Description

  • Change GetStaticShape to GetShape to allow dynamic dimensions
  • Only apply ReshapeHelper when input shape is fully static
  • CoreML MIL handles -1 dimensions at runtime

Motivation and Context

Users reshaping tensors to [-1, N] were getting fallback to CPU with warnings about
unsupported reshape operations on dynamic shapes.

CoreML MIL supports -1 in shape dimensions and can infer at runtime.
Change GetStaticShape to GetShape to allow dynamic input shapes,
and only apply ReshapeHelper when the shape is fully static.

Fixes microsoft#26328
Add a test model (Reshape with dynamic M dimension, shape [-1, 2048])
and a corresponding test case in dynamic_input_test.cc to verify the
CoreML EP handles reshape operations with dynamic input shapes.
@ingyukoh
Copy link
Contributor Author

@skottmckay Could you take a look at this? The fix changes GetStaticShape to GetShape in
the reshape op builder and guards ReshapeHelper behind IsStaticShape(), so CoreML MIL can
handle -1 dimensions at runtime for dynamic input shapes. Added a test case and test model
in the second commit.

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.

CoreML reshape doesn't work with dynamic shape

1 participant