Channels last: absorb boundary layout copies into the method contract - #22034
Open
rascani wants to merge 1 commit into
Open
Channels last: absorb boundary layout copies into the method contract#22034rascani wants to merge 1 commit into
rascani wants to merge 1 commit into
Conversation
Contributor
Author
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/22034
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New Failure, 6 Unrelated FailuresAs of commit 6a5005d with merge base 8b93850 ( NEW FAILURE - The following job has failed:
BROKEN TRUNK - The following jobs failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This was referenced Aug 21, 2026
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.
A layout region formed by ToContiguousChannelsLastPass is bracketed by
channels_last.permute_copy. Interior copies cancel against each other, but
the ones sitting on a method input or output have nothing to cancel against
and survive. On the 36-case matrix in
backends/transforms/test/test_to_contiguous_channels_last_pass.py they cost
+18 permutes against a no-layout-pass baseline of 138.
This pass deletes those copies and declares the corresponding input or output
channels-last instead, which moves the transpose to the caller — free whenever
the caller already holds the data in that layout. That takes the in-graph count
to 137, one below the baseline.
Read that number carefully, because most of it is a transfer rather than a
saving. Absorption removes 19 permutes from the graph and creates 17 obligations
on the caller; only the difference is genuinely eliminated, and it comes from
fan-out, where one placeholder feeding several branches needs several copies but
only one contract entry. For a caller that already holds NHWC the other 17 are
free, and for a delegate the boundary is internal so they disappear entirely,
but neither is true by construction. The test pins both totals, since an
in-graph count on its own could be driven to zero by handing the caller
unlimited work.
Two things about the design are worth stating because the obvious alternatives
are worse. First, ordering: permuting the boundary up front and hoping the
copies cancel during formation only reaches 151, and regresses more cases than
it fixes, because graphs with no layout anchors get copies inserted that nothing
can ever cancel. Absorbing after formation is what pays. Second, fan-out: a
residual block feeds one placeholder to several branches, each with its own
copy, and skipping those leaves most of the win on the table — handling them is
the difference between 141 and 137.
The copy need not be adjacent to the boundary. Quantized graphs interpose a
per-tensor quantize or dequantize, which reorders nothing, so the search walks
through those and relabels them on the way. Per-channel quantization is
excluded: its axis is dimension-dependent.
Because this changes what callers must pass and what they get back, the pass
reports the applied permutations rather than leaving them to be inferred. No
in-tree pipeline runs it yet.
Authored with Claude Code.