Add coreml_compute_plan.py: report which CoreML ops dispatch to ANE / GPU / CPU#19252
Add coreml_compute_plan.py: report which CoreML ops dispatch to ANE / GPU / CPU#19252john-rocky wants to merge 1 commit intopytorch:mainfrom
Conversation
CoreML decides at compile/load time which device each MIL operation will execute on; that decision is exposed through MLComputePlan in coremltools 9.0+. This script wraps it so users can answer 'why isn't my model running on the ANE?' without writing Swift, which is the recurring question behind issues like pytorch#4091, pytorch#11541, and pytorch#8439. Inputs supported: * .pte — extracts every Core ML partition first. * .mlpackage — compiles to .mlmodelc in a tempdir. * .mlmodelc — analyzed directly. Reports per-op dispatch (ANE / GPU / CPU), an aggregate breakdown, and optionally the op types that did not get assigned to the ANE (--show_non_ane). Authored with Claude.
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/19252
Note: Links to docs will display an error until the docs builds have been completed.
|
|
@pytorchbot label "release notes: apple" |
|
I thought what op runs where is decided at compile time. Is this being extracted from AOT compile or just from lowering? |
|
@kimishpatel Compile time, not runtime — Quoting coremltools' own docs:
So no AOT extraction or runtime profiling involved; just a wrapper that walks |
Summary
CoreML decides at compile/load time which device each MIL operation will
execute on, and coremltools 9.0+ exposes that through
MLComputePlan.The recurring question on the issue tracker is "why isn't my model
running fully on the ANE?" — for example:
llama model is not fully lowered to ANECoreML model is crashing on iPhone GPU, but not on iPhone CPU or macOS GPUANE compile OOMs on certain input shapesCPU Overhead After ANE ExecutionToday the only way for an ExecuTorch user to answer it is to break out
Swift / Xcode. This PR adds a Python wrapper around
MLComputePlansothe answer is one shell command:
Inputs supported:
.pte.mlpackage.mlmodelcin a tempdir, then analyze..mlmodelcThe PTE path reuses the same JSON/named-data extraction logic that
extract_coreml_models.pyuses, and is inlined into the script so it canbe run against a plain CoreML model without depending on the executorch
package.
Test plan
Added
test_coreml_compute_plan.pycovering:_device_name(...)forNoneand a stubMLNeuralEngineComputeDevice._COMPUTE_UNIT_CHOICESmapping (cpu_and_ne/all).analyze_one(...)end-to-end on a tinyrelu(x @ x.T) + x.sum()mlpackage built with
coremltools.convert(...): returns rows forevery dispatched op, with a
mainfunction and the expected MIL optypes (
matmul,relu,add,reduce_sum).I also ran the script against a few hand-built
.mlpackageand.mlmodelcfiles on macOS 26 with coremltools 9.0 and verified theoutput matches what
MLComputePlanreturns directly.Authored with Claude.
cc @kimishpatel @YifanShenSZ @cymbalrush @metascroy