Skip to content

CoreML doesn't handle negative dim values correctly in cumsum #11716

@GregoryComer

Description

@GregoryComer
Member

🐛 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)

cc @kimishpatel @YifanShenSZ @cymbalrush @metascroy

Activity

added
module: coremlIssues related to Apple's Core ML delegation and code under backends/apple/coreml/
on Jun 16, 2025
added theissue type on Jun 16, 2025
metascroy

metascroy commented on Jul 7, 2025

@metascroy
Contributor

Closing this issue as low-priority. CoreML does not support this op with these args, and this is clear to the user from the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    backend testerThis bug was found by the backend test suite.module: coremlIssues related to Apple's Core ML delegation and code under backends/apple/coreml/

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @GregoryComer@metascroy

        Issue actions

          CoreML doesn't handle negative dim values correctly in cumsum · Issue #11716 · pytorch/executorch