pytorch / pytorch/executorch

CoreML int32 mm with fixed arg fails to load at runtime

Open
#11,691 1 comment 0 reactions 0 assignees View on GitHub

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

The following model fails to load at runtime with the following error:

[ETCoreMLModelManager.mm:528] Cache Miss: Model with identifier=executorch_c6fd42cf-7a82-4833-969f-e39c113b0890_all was not found in the models cache.
[ETCoreMLModelLoader.mm:69] [Core ML] Failed to load model from compiled asset with identifier = executorch_c6fd42cf-7a82-4833-969f-e39c113b0890_all Failed to build the model execution plan using a model architecture file '[/Users/gjcomer/Library/Caches/executorchcoreml/models/execu](http://localhost:8888/Users/gjcomer/Library/Caches/executorchcoreml/models/execu)$
[backend_delegate.mm:288] [Core ML] Model init failed The file “model.mlmodelc” couldn’t be opened because there is no such file.
[coreml_backend_delegate.mm:193] CoreMLBackend: Failed to init the model.
[method.cpp:113] Init failed for backend CoreMLBackend: 0x23

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 __init__(self):
        super().__init__()
        self.weight = torch.randint(0, 100, (8, 8)).to(torch.int32)
    def forward(self, x):
        return torch.mm(x, self.weight)

model = Model()
inputs = (
    torch.randn(8, 8).to(torch.int32),
)

eager_outputs = model(*inputs)
print(f"Eager: {eager_outputs.shape} {eager_outputs}")

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_outputs = et_model([*inputs])[0]

et_outputs - eager_outputs
Versions

coremltools version 8.3
executorch commit https://github.com/pytorch/executorch/commit/67b6009d6b3b67eee775c8ed2fe30eae6e0bb65c (Jun 14)

cc @kimishpatel @YifanShenSZ @cymbalrush @metascroy

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the failure with CoreMLPartitioner and the provided int32 torch.mm model. Trace the reported load path through ETCoreMLModelManager.mm, ETCoreMLModelLoader.mm, backend_delegate.mm, and coreml_backend_delegate.mm. Done means the lowered model loads at runtime and its output can be compared with eager_outputs.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning, mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.