Repository navigation
Studio: skip QKV fusion when projections are kept packed - #17132
Merged
Merged
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
This was referenced Nov 8, 2026
danielhanchen
added a commit
that referenced
this pull request
Nov 8, 2026
…ichever rank fails first (#17151) ## Summary `Repo tests (CPU, rest)` fails on some PRs at a test #15880 added yesterday. Today that includes #17129 and #17132, neither of which touches context parallelism: ``` tests/test_remote_moe_shims.py:920: in test_without_context_parallelism_idle_experts_stall_ddp E AssertionError: Regex pattern did not match. E Expected regex: 'not close|finished reduction|did not receive grad' E Actual message: '-- Process 1 terminated with the following error: ... File "tests/test_remote_moe_shims.py", line 895, in _moe_ddp_worker assert got.grad is not None, name # a zero gradient, never None, for DDP AssertionError: experts.0.gate_proj.weight ``` The test is a negative control. With context parallelism off, each rank leaves the experts its peer routes to with a `None` gradient, so DDP without `find_unused_parameters` never reduces that bucket. The test expects the run to fail, and it does, every time. Which error the test sees depends on which of the two spawned ranks fails first: - the rank that **used** an expert holds an unreduced local gradient, and `assert_close` fails with `not close`, which the regex accepts; - the rank that left the **same** expert idle reaches `assert got.grad is not None` first, and that assertion's message is just the parameter name, which the regex does not accept. `torch.multiprocessing.spawn` reports whichever process dies first. So the test passes or fails on scheduling, while the product behaviour it checks is identical either way. Context parallelism itself is correct. The positive test next to it, with context parallelism on, passes. ## Change `tests/test_remote_moe_shims.py`, test only: - The worker's gradient assertion says what it found: `f"{name}: no gradient"`. - The negative control's regex also accepts `no gradient`, with a comment on why both ranks' errors are the same finding. The control still fails if context-parallel-off training ever stops stalling DDP, because then nothing raises at all. ## Testing | | result | |---|---| | main, with rank 0 delayed 3 s before its checks so rank 1 fails first (the CI case) | fails: `Regex pattern did not match`, `Process 1 terminated` | | this branch, same delay | passes | | this branch, `tests/test_remote_moe_shims.py` | 49 passed |
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.
Follow-up to #17067.
Problem
Max speed fuses QKV projections through diffusers'
fuse_qkv_projections, which reads each projection's.weightand concatenates them into new denseto_qkv/to_added_qkvLinears. The guard in_fuse_qkv(and the matchingfused_qkv_added_bytesestimate) only recognisedNativeWeightOnlyLinear. APackedBlockLinearfrom #17067 materialises a dense matrix from its.weightproperty, so a packed nvfp4 / mxfp8 transformer got persistent dense QKV copies next to its packed buffers, exactly when packed storage was picked to keep resident memory down.Reproduced with a tiny real
FluxTransformer2DModelwhose Q/K/V are packed:_fuse_qkvreturned True and added a densetransformer_blocks.0.attn.to_qkv(96 x 32).Fix
One predicate,
_quantised_projections(pipe), used by both_fuse_qkvandfused_qkv_added_bytes: True when any denoiser (every DiT, and the pipe's U-Net, which the pipe-level fuse also reaches) holds a native weight-only Linear or a packed block Linear. Fusion is then skipped with the existing log line, and the headroom estimate stays at 0 for such pipes. Dense pipes fuse as before.Tests
test_qkv_fusion_skips_packed_projections: a packed denoiser is not fused, a dense one still is.test_qkv_fusion_of_a_packed_flux_builds_no_dense_to_qkv: tiny realFluxTransformer2DModelwith packed Q/K/V, byte count unchanged and noto_qkv/to_added_qkvmodule after_fuse_qkv.origin/maintest_diffusion_packed_block.py,test_diffusion_native_quant.py,test_diffusion_drop_unfused_qkv.py,test_diffusion_speed.py,test_diffusion_deferred_headroom.pytest_unpinned_torchao_host_copy_is_a_distinct_wrapper_over_the_same_data, a torchao version mismatch on this host, unrelated and the same onmain)No runtime path inside a compiled region changes: the check runs once at optimisation time in eager.
tests/test_diffusion_packed_block.pyon a Kaggle T4 (CUDA cases included): 31 passed.