apple / apple/coremltools

Using RangeDim in TensorSpec shape

Open
#890 3 comments 0 reactions 0 assignees View on GitHub
bug Flexible Shape
Dominant language
Python
Stars
5.4k
Forks
850
Avg merge
4d 5h
Merged PRs (30d)
10

Description

It would be nice to use a `RangeDim` directly in the `mb.TensorSpec()` shape here instead of the symbol indirection:

```
flexible = ct.RangeDim()
@mb.program(input_specs=[mb.TensorSpec(shape=(1, 100, 100, flexible.symbol)),])
def prog(x):
return x
```

Context:

I'm trying to write a converter for a model type with flexible input dimensions, because the automatic conversion doesn't work and it's not worth me fixing it (I'm already generating the Pytorch model from _yet another_ framework, flashlight/wav2letter, so I'd rather generate the right ops directly for MIL than try to make the stacked abstractions make sense)

I originally got it working with the old-style NeuralNetworkBuilder, but couldn't figure out how to specify flexible input features. I just found the MIL builder and ported my code to that. It seems to accept a `RangeDim` in the program decorator for flexible input shape as shown, but only if I use the `.symbol` property on a `RangeDim` (which I had to dig around in source to find). Passing the `RangeDim` directly feels more intuitive to me.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the mb.TensorSpec shape example with ct.RangeDim() and its .symbol in the program decorator. Trace the RangeDim and TensorSpec entry points to see how shape values are validated; done means a RangeDim can be passed directly and produces the same flexible input shape.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.