Add coreml_compute_plan.py: report which CoreML ops dispatch to ANE / GPU / CPU#19252
Open
john-rocky wants to merge 1 commit intopytorch:mainfrom
Open
Add coreml_compute_plan.py: report which CoreML ops dispatch to ANE / GPU / CPU#19252john-rocky wants to merge 1 commit intopytorch:mainfrom
john-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. This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.