CoreML partitioner errors out with 8-bit integer types
Open
Nobody has claimed this yet.
backend tester
module: coreml
- Dominant language
- Python
- Stars
- 5k
- Forks
- 1.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 581
Description
🐛 Describe the bug
When partitioning a model with Core ML that contains int8 or uint8 into abs, the partitioner will error out with a KeyError. The backend should ideally either correctly handle it (if supported) or not partition it.
Repro:
import torch
from executorch.backends.apple.coreml.partition import CoreMLPartitioner
from executorch.exir import to_edge_transform_and_lower
from executorch.extension.pybindings.portable_lib import _load_for_executorch_from_buffer
class Model(torch.nn.Module):
def forward(self, x):
return torch.abs(x)
model = Model()
inputs = (torch.randint(0, 255, (1,10)).to(torch.uint8),)
lowered = to_edge_transform_and_lower(
torch.export.export(model, inputs),
partitioner=[CoreMLPartitioner()],
).to_executorch()
et_model = _load_for_executorch_from_buffer(lowered.buffer)
et_model([*inputs])
Output:
File [~/miniconda3/envs/executorch/lib/python3.10/site-packages/coremltools/converters/mil/frontend/torch/exir_utils.py:60](http://localhost:8888/lab/tree/~/miniconda3/envs/executorch/lib/python3.10/site-packages/coremltools/converters/mil/frontend/torch/exir_utils.py#line=59), in _construct_ct_tensor_type_from_torch(name, tensor, symbol_name_to_ct_range_dim)
55 def _construct_ct_tensor_type_from_torch(
56 name: str,
57 tensor: torch.Tensor,
58 symbol_name_to_ct_range_dim: Dict[str, RangeDim],
59 ) -> TensorType:
---> 60 coreml_dtype = TORCH_DTYPE_TO_MIL_DTYPE[tensor.dtype]
61 if coreml_dtype == types.int16:
62 coreml_dtype = types.int32
KeyError: torch.uint8
Versions
Nightly
cc @kimishpatel @YifanShenSZ @cymbalrush @metascroy
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with CoreMLPartitioner in executorch.backends.apple.coreml.partition and run the provided uint8 abs reproduction to trace the KeyError. Done means the backend either handles supported int8 and uint8 inputs or leaves unsupported inputs unpartitioned, with coverage for the reported case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning, mobile-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100