Fix ReplicationPad3d failing at CoreML ML Program runtime#2697
Open
tritolol wants to merge 1 commit into
Open
Conversation
CoreML's ML Program runtime rejects non-constant padding modes (reflect, replicate) when more than 2 dimensions are padded, with: "Padding for more than two dimensions only supports constant mode". Previously, torch.nn.ReplicationPad3d converted silently but failed at prediction time. Add a new mil_backend pass `split_non_constant_pads` that decomposes such pad ops into sequential pads each covering at most 2 dimensions, which CoreML supports. The pass runs in _BACKEND_MIL_PASSES after merge_consecutive_paddings to prevent splits from being merged back. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
413106c to
608c8dd
Compare
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
torch.nn.ReplicationPad3dconverted silently but failed at prediction time with"Padding for more than two dimensions only supports constant mode"split_non_constant_padsthat decomposes non-constant pad ops (reflect/replicate) covering >2 dimensions into sequential pads of ≤2 dimensions each, which CoreML supports_BACKEND_MIL_PASSESaftermerge_consecutive_paddingsso splits aren't merged backTest plan
TestPad::test_replication_pad3d— regression test for symmetric 3D replication paddingTestPad::test_replication_pad3d_asymmetric— regression test for asymmetric 3D replication paddingmil/passes/tests/test_passes.py -kpad tests pass (215 passed)🤖 Generated with Claude Code