apple / apple/coremltools

Support for Rank-0 (input None)

Open
#1,765 6 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
Python
Stars
5.4k
Forks
850
Avg merge
4d 5h
Merged PRs (30d)
10

Description

I am trying to convert microsoft/trocr-small-handwritten (PyTorch)

Link to Colab Notebook: https://colab.research.google.com/drive/1fuvyNc63c2NXy0TjB6T3fGSC6wLZPJwC?usp=sharing (Ignore the ONNX Section)

I can successfully trace both the encoder and decoder models, and even successfully export the encoder model, but the decoder model errors out with: `ValueError: Rank-0 (input None) is unsupported`

```
import coremltools as ct

ct_enc_model = ct.convert(traced_encoder, inputs=[ct.ImageType(shape=xenc.shape)])
```

```
ct_dec_model = ct.convert(traced_decoder,
inputs=[
ct.TensorType(shape=input_ids.shape),
ct.TensorType(shape=attention_mask.shape),
ct.TensorType(shape=encoder_hidden_states.shape),
ct.TensorType(shape=pad_size.shape)
])

WARNING:coremltools:Tuple detected at graph output. This will be flattened in the converted model.
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
[](https://localhost:8080/#) in
----> 1 ct_dec_model = ct.convert(traced_decoder,
2 inputs=[
3 ct.TensorType(shape=input_ids.shape),
4 ct.TensorType(shape=attention_mask.shape),
5 ct.TensorType(shape=encoder_hidden_states.shape),

10 frames
[/usr/local/lib/python3.8/dist-packages/coremltools/converters/mil/mil/program.py](https://localhost:8080/#) in __init__(self, sym_shape, dtype, name, allow_rank0_input)
161 if len(sym_shape) == 0:
162 if not allow_rank0_input:
--> 163 raise ValueError('Rank-0 (input {}) is unsupported'.format(name))
164 else:
165 logger.warning('Rank-0 (input {}) is unsupported in coreml. You might run into error while\

ValueError: Rank-0 (input None) is unsupported
```

The reason I have labelled this as a question is because I am unsure if not supporting Rank-0 is a bug or if this is just unsupported by coremltools altogether.

Contributor guide

Open the contributing guide

Research direction

Reproduce the decoder conversion with the linked Colab notebook, ignoring its ONNX section, then inspect coremltools/converters/mil/mil/program.py around the allow_rank0_input check shown in the traceback. Determine whether rank-0 inputs can be supported or are a Core ML limitation; done means the issue has a documented resolution and, if support is feasible, verified conversion behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.