Open
Description
🐛 Describe the bug
Negative dim values other than -1 are not handled correctly on CoreML. It errors out during lowering.
Repro:
import torch
from executorch.backends.apple.coreml.partition import CoreMLPartitioner
from executorch.exir import to_edge_transform_and_lower, EdgeCompileConfig, to_edge
from executorch.extension.pybindings.portable_lib import _load_for_executorch_from_buffer
class Model(torch.nn.Module):
def __init__(self):
super().__init__()
def forward(self, x):
return torch.cumsum(x, dim=-3) # First dim (third from last)
model = Model()
inputs = (
torch.randn(2, 2, 2),
)
eager_outputs = model(*inputs)
#print(f"Eager: {eager_outputs.shape} {eager_outputs}")
ep = torch.export.export(model.eval(), inputs)
print(ep)
print(f"EP: {ep.module()(*inputs)}")
lowered = to_edge_transform_and_lower(
ep,
partitioner=[CoreMLPartitioner()],
compile_config=EdgeCompileConfig(_check_ir_validity=False)
).to_executorch()
print(lowered.exported_program())
et_model = _load_for_executorch_from_buffer(lowered.buffer)
et_outputs = et_model([*inputs])[0]
et_outputs - eager_outputs
Output:
File [~/miniconda3/envs/executorch/lib/python3.10/site-packages/coremltools/converters/mil/mil/ops/defs/iOS15/tensor_operation.py:166](http://localhost:8888/lab/tree/~/miniconda3/envs/executorch/lib/python3.10/site-packages/coremltools/converters/mil/mil/ops/defs/iOS15/tensor_operation.py#line=165), in cumsum.type_inference(self)
163 def type_inference(self):
164 # Check range of axis
165 if self.axis.val < -1 or self.axis.val > self.x.rank - 1:
--> 166 raise ValueError(
167 "axis should be in the range [-1, {}]".format(self.x.rank - 1)
168 )
170 return self.x.sym_type
ValueError: axis should be in the range [-1, 2]
Versions
coremltools version 8.3
executorch commit 67b6009 (Jun 14)