Skip to content

Channels last: absorb boundary layout copies into the method contract - #22027

Merged
rascani merged 3 commits into
gh/rascani/9/headfrom
gh/rascani/19/head
Aug 21, 2026
Merged

Channels last: absorb boundary layout copies into the method contract#22027
rascani merged 3 commits into
gh/rascani/9/headfrom
gh/rascani/19/head

Conversation

@rascani

@rascani rascani commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

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.

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Aug 21, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/22027

Note: Links to docs will display an error until the docs builds have been completed.

❌ 12 Pending, 10 Unrelated Failures, 1 Unclassified Failure

As of commit 07f2fd3 with merge base 8b93850 (image):

UNCLASSIFIED FAILURE - DrCI could not classify the following job because the workflow did not run on the merge base. The failure may be pre-existing on trunk or introduced by this PR:

FLAKY - The following job failed but was likely due to flakiness present on trunk:

BROKEN TRUNK - The following jobs failed but was 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.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 21, 2026
@github-actions github-actions Bot added ciflow/trunk module: arm Issues related to arm backend labels Aug 21, 2026
@linux-foundation-easycla

Copy link
Copy Markdown

CLA Missing ID

[ghstack-poisoned]
[ghstack-poisoned]
@rascani
rascani merged commit 70adb8d into gh/rascani/9/head Aug 21, 2026
@rascani
rascani deleted the gh/rascani/19/head branch August 21, 2026 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. module: arm Issues related to arm backend module: rocm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant