Skip to content

Fix ReplicationPad3d failing at CoreML ML Program runtime#2697

Open
tritolol wants to merge 1 commit into
apple:mainfrom
tritolol:fix/replication-pad3d-runtime-failure
Open

Fix ReplicationPad3d failing at CoreML ML Program runtime#2697
tritolol wants to merge 1 commit into
apple:mainfrom
tritolol:fix/replication-pad3d-runtime-failure

Conversation

@tritolol
Copy link
Copy Markdown
Contributor

@tritolol tritolol commented May 14, 2026

Summary

  • Fixes torch.nn.ReplicationPad3d fails at runtime when there is padding #2571: torch.nn.ReplicationPad3d converted silently but failed at prediction time with "Padding for more than two dimensions only supports constant mode"
  • Adds a new MIL backend pass split_non_constant_pads that decomposes non-constant pad ops (reflect/replicate) covering >2 dimensions into sequential pads of ≤2 dimensions each, which CoreML supports
  • The pass runs in _BACKEND_MIL_PASSES after merge_consecutive_paddings so splits aren't merged back

Test plan

  • TestPad::test_replication_pad3d — regression test for symmetric 3D replication padding
  • TestPad::test_replication_pad3d_asymmetric — regression test for asymmetric 3D replication padding
  • Full TestPad suite passes (26 passed, 2 skipped for NN backend which doesn't support this case)
  • All mil/passes/tests/test_passes.py -k pad tests pass (215 passed)

🤖 Generated with Claude Code

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

torch.nn.ReplicationPad3d fails at runtime when there is padding

1 participant