Repository navigation
Do not delegate CoreML reflect/replicate pads beyond the last two dims - #23687
hemanth1999k wants to merge 2 commits into
Conversation
Core ML only supports reflect and replicate padding on the last two dimensions. ReflectionPad3d, ReplicationPad3d, or a reflect pad of just the depth dimension of a 5D input lowered fine, then failed to load: Padding for more than two dimensions only supports `constant` mode The partitioner now overrides support for those pads, so ops_to_not_decompose no longer keeps them whole. They decompose into ops Core ML runs, and the model stays delegated and matches eager. Fixes pytorch#11708 Fixes pytorch#11709
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/23687
Note: Links to docs will display an error until the docs builds have been completed.
|
|
Hi @hemanth1999k! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
|
|
@pytorchbot label "release notes: apple" |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
|
@claude review this code. Do they test that supported padding lower to coreml delegate (call delegate node) and non-supported do not lower (op left in graph with no call deelgate node) |
|
Claude finished @metascroy's task in 1m 14s —— View job Short answer: no. The test never looks at the lowered graph, so it does not check that supported pads end up in an Detailed reviewPR Review: #23687SummaryThe PR makes Testing1. No check on the lowered graph ( For the three unsupported cases, the test checks two things:
Neither check shows where the op runs. The numeric check would pass even if nothing were delegated, and For the supported 2D reflect case (
2. The decomposition probably falls back to portable, not Core ML ( Once For the single-op models in this test, that would mean the whole program runs on portable with no delegate. The fallback is still correct, since it fixes the load failure. But the PR description says the pads "decompose into ops Core ML runs, and the model stays delegated", and that is probably wrong. I couldn't run Python in this environment, so I haven't confirmed this. The assertions in point 1 would answer it for certain, and the description should be updated to match what happens. RecommendationRequest Changes. Add graph-level assertions: a delegate for the 2D reflect case, and the pad op left outside any delegate for the 3D cases. Then correct the description to match what actually happens. |
The pad regression test only checked ops_to_not_decompose and, on macOS, the numerics, so it never showed where the pad ran. Lower every case and assert on the graph: pads Core ML cannot load are decomposed (no pad left in the graph or in the delegate, the index-based decomposition is delegated), and 2D reflect / replicate pads are delegated whole as pad.
|
Added graph assertions modeled on the argmax test.
Without the partitioner change the pad is delegated whole, these assertions fail, and on macOS the program fails to load with "Padding for more than two dimensions only supports |
Summary
Core ML only supports
reflectandreplicatepadding on the last two dimensions.ReflectionPad3d,ReplicationPad3d, or a reflect pad of only the depth dimension of a 5D input currently lower to Core ML without complaint, then fail when the program loads:CoreMLPartitionernow overrides support for these pads (aten.padin reflect/replicate mode with a nonzero pad outside the last two dims, plusreflection_pad3d/replication_pad3d).ops_to_not_decomposetherefore stops keeping them whole, they decompose into ops Core ML runs, and the model stays delegated and matches eager. 1D/2D reflect and replicate pads and constant pads are unchanged.Fixes #11708
Fixes #11709
Test plan
Added
test_nonconstant_pad_beyond_last_two_dims_is_decomposedtobackends/apple/coreml/test/test_coreml_partitioner.py. It coversReflectionPad3d,ReplicationPad3d, and a depth-only reflect pad. For each it checks thataten.pad.defaultis not inops_to_not_decompose, lowers withto_edge_transform_and_lower, runs the program throughexecutorch.runtime.Runtime, and compares with eager (atol/rtol 1e-2 because Core ML computes in fp16). It also checks that a 2D reflect pad is still kept whole.13/13 pass with the change; on main only the new test fails. Run on macOS 26.2, executorch 1.5.1 / main, torch 2.14.0, coremltools 9.0.
ufmtandflake8are clean.Circular 3D pads still raise a ValueError at lowering, as they do on main; that is a separate issue and out of scope here.
cc @nil-is-all