pytorch / pytorch/executorch

Model lowers to CoreML but fails to run

Open
#6,663 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

module: coreml need-user-input triaged
Dominant language
Python
Stars
5k
Forks
1.2k
Avg merge
2d 10h
Merged PRs (30d)
581

Description

🐛 Describe the bug

I try to lower a model to CoreML backend and export to ET, and I get an error about dict not being supported (Failed with error:

InternalError: Failed with error: self.node.meta['spec'] <class 'dict'> is not supported
Here is the node in the graph module:
graph():
    %args_0 : [num_users=1] = placeholder[target=args_0]
    %args_1 : [num_users=1] = placeholder[target=args_1]
    %lowered_module_0 : [num_users=1] = get_attr[target=lowered_module_0]
--> %executorch_call_delegate : [num_users=1] = call_function[target=torch.ops.higher_order.executorch_call_delegate](args = (%lowered_module_0, %args_0, %args_1), kwargs = {})
    %getitem : [num_users=1] = call_function[target=operator.getitem](args = (%executorch_call_delegate, disparity), kwargs = {})
    return (getitem,)

My guess is that it's complaining because the model outputs a dictionary instead of a tensor or a tuple.

So I went ahead and attempted to add model input/output flattening, and now the model (seemingly) successfully lowers and exports to ET.

However, whenever I run the model on an actual iPhone or on an iPhone simulator through the ET benchmark, I get an error/crash. The debug logs in this case appear somewhat cryptic and don't really help me understand what might be going wrong and what to try next:

2024-11-04 23:27:14.011315-0800 Benchmark[84774:28513112] [coreml] Failed to get the home directory when checking model path.
2024-11-04 23:27:14.155523-0800 Benchmark[84774:28512932] [coreml] Failed to get the home directory when checking model path.
2024-11-04 23:27:14.770870-0800 Benchmark[84774:28512932] [e5rt] E5RT encountered an STL exception. msg = Espresso exception: "Invalid state": MpsGraph backend validation on incompatible OS.
2024-11-04 23:27:14.770997-0800 Benchmark[84774:28512932] [coreml] E5RT: Espresso exception: "Invalid state": MpsGraph backend validation on incompatible OS (11)
2024-11-04 23:27:15.089577-0800 Benchmark[84774:28512932] [espresso] [Espresso::handle_ex_] exception=Espresso compiled without MPSGraph engine.
2024-11-04 23:27:15.279468-0800 Benchmark[84774:28512932] [espresso] Failure translating MIL->EIR network: Espresso exception: "Invalid argument": generic_general_slice: Invalid values in end_ids
2024-11-04 23:27:15.281001-0800 Benchmark[84774:28512932] [espresso] [Espresso::handle_ex_plan] exception=Espresso exception: "Invalid argument": generic_general_slice: Invalid values in end_ids status=-6
2024-11-04 23:27:15.281097-0800 Benchmark[84774:28512932] [coreml] Failed to build the model execution plan using a model architecture file '/Users/grinvald/Library/Developer/CoreSimulator/Devices/01AE728A-6725-4C64-B70C-473CB902422F/data/Containers/Data/Application/7FBE2B45-D168-49FC-B9A6-8805DFDC10F3/Library/Caches/executorchcoreml/models/executorch_c23737f2-118a-4805-af73-7eb100c9a8d3_all.mlmodelc/model.mil' with error code: -6.
2024-11-04 23:27:15.281565-0800 Benchmark[84774:28512932] [espresso] [Espresso::handle_ex_] exception=Espresso compiled without MPSGraph engine.
2024-11-04 23:27:15.459874-0800 Benchmark[84774:28512932] [espresso] Failure translating MIL->EIR network: Espresso exception: "Invalid argument": generic_general_slice: Invalid values in end_ids
2024-11-04 23:27:15.461390-0800 Benchmark[84774:28512932] [espresso] [Espresso::handle_ex_plan] exception=Espresso exception: "Invalid argument": generic_general_slice: Invalid values in end_ids status=-6

Does anything informative stand out from the logs? If not, what would should be my next steps in debugging this model lowering?

Versions

Cannot use collect_env.py script because of Meta-specific dev environment.

cc @kimishpatel @YifanShenSZ @cymbalrush

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 with the CoreML lowering/export path and extension/benchmark/apple/Benchmark, then reproduce the reported dictionary-output export and iPhone or simulator crash using the logged environment details. Done means identifying the cause of the unsupported output or runtime failure and documenting or fixing it so the model exports to ET and runs successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
ios, machine-learning, python
Domain
machine-learning, mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.