microsoft / microsoft/onnxruntime

CoreML reshape doesn't work with dynamic shape

Open
#26,328 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

contributions welcome ep:CoreML
Dominant language
C++
Stars
21.9k
Forks
4.2k
Avg merge
4d 11h
Merged PRs (30d)
184

Description

### Describe the issue

Trying to reshape a tensor to `[-1, 2048]` resulted in:
```
[V:onnxruntime:, shape_utils.cc:32 GetShapeImpl] NodeArg [/value/conv/relu] has shape with dynamic dimension
[V:onnxruntime:, base_op_builder.cc:46 IsOpSupported] Operator [Reshape] is not supported by the impl
[V:onnxruntime:, helper.cc:103 GetSupportedNodes] Operator type: [Reshape] index: [109] name: [/value/reshape] supported: [0]
```
Maybe [line 99](https://github.com/microsoft/onnxruntime/blob/main/onnxruntime/core/providers/coreml/builders/impl/reshape_op_builder.cc#L99C1-L100C18) in `reshape_op_builder.cc` should be
```c++
if (!GetShape(*input_defs[0], input_shape, logger))
return false;
```
instead of `GetStaticShape(...)`.

Something similar was also mentioned in https://github.com/microsoft/onnxruntime/issues/21271#issuecomment-2264859467 but without details.

### To reproduce

As far as I can tell, any reshape of a tensor with a dynamic shape falls back to the cpu execution provider.

### Urgency

_No response_

### Platform

Mac

### OS Version

15.3.2

### ONNX Runtime Installation

Released Package

### ONNX Runtime Version or Commit ID

1.23.1

### ONNX Runtime API

C++

### Architecture

ARM64

### Execution Provider

CoreML

### Execution Provider Library Version

_No response_

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in onnxruntime/core/providers/coreml/builders/impl/reshape_op_builder.cc, especially the shape handling around line 99, and compare the reported GetStaticShape behavior with the suggested GetShape change. Reproduce a reshape using a dynamic input shape on CoreML with ONNX Runtime 1.23.1. Done means the reshape is supported by CoreML instead of falling back to the CPU execution provider.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.