[Feat] Add channels-last layout optimization pass for conv-heavy models#36
Merged
jiahy0825 merged 3 commits intoJun 23, 2026
Conversation
jiahy0825
reviewed
Jun 22, 2026
jiahy0825
reviewed
Jun 22, 2026
8cb57dd to
9a1e5c8
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.
🗂️ PR Category
📝 Description
Motivation
cuDNN's channels-last (NHWC/NDHWC) conv kernels are much faster than contiguous
NC(D)HW on Ampere+, but activations are stored contiguous by default, so cuDNN
pays an internal NCHW⇄NHWC conversion around every conv. Inductor only hoists
this for conv2d (
ndim == 2/ the 4Dlen(...) == 4gate); 5D conv3d hasno native channels-last path, so conv3d-dense models (e.g. VAE decode) keep
paying that per-conv cost.
What this PR adds
ConvChannelsLastPass: an opt-in post-grad ATen pass that brings channels-lastto conv3d (and conv2d) by graph rewriting only — no patching of PyTorch
internals. It sets
layout_optimization=Falseand owns layout itself:aten.clone(memory_format=channels_last(_3d))on each convinput/weight and marks the clone's
meta["val"]channels-last. The clonelowering ignores
memory_format(a TODO inlowering.py), so the signallives purely in the FX meta strides — which
constrain_conv_to_fx_stridesthen reads to pin the conv channels-last, so cuDNN skips its internal
conversions.
zero-cost: the buffer is allocated channels-last directly and fuses into the
neighboring elementwise kernel (silu/groupnorm) instead of adding a copy.
clone_cache); the conversion is hoistedthrough
constant_pad_ndto fuse with the upstream producer.Gating
pass_config.enable_conv_channels_lastis binary:True(default): Registered; its internal heuristics decide at runtime whether to apply (fires only on static, conv-heavy graphs).False: Off (not registered at all).Performance (WAN 2.2 VAE decode, 540p, static)
Tests
test_conv_channels_last_switch.py): Verifies the corrected binary gating (static conv-heavy rewrites; dynamic or conv-sparse skips) and configuration registration. Refactored to leverage shared conftest fixtures and clean out fragile, pass-unrelated integration logic.test_conv_channels_last_perf.py): Uses static, conv-heavy VAE-decode-like workload; achieves 1.22x speedup over vanillatorch.compile(asserts>= 1.20x). Leverages centralizedVAEDecoderLikeand scopedconfig_patchto prevent baseline config leakage.