Repository navigation
Add shape suffix annotations to attention module - #3443
Merged
Merged
Conversation
acisseJZhong
force-pushed
the
fix_attention_shape_annotation
branch
from
May 28, 2026 18:09
b35f16c to
9a5459a
Compare
acisseJZhong
marked this pull request as ready for review
May 28, 2026 18:11
acisseJZhong
requested review from
fegin,
tianyu-l,
wconstab and
wwwjn
as code owners
May 28, 2026 18:11
tianyu-l
approved these changes
May 28, 2026
acisseJZhong
force-pushed
the
fix_attention_shape_annotation
branch
2 times, most recently
from
June 16, 2026 22:02
f20722c to
799b399
Compare
fegin
approved these changes
Jun 16, 2026
fegin
left a comment
Contributor
There was a problem hiding this comment.
Should we do 1) create a doc for coding convention, 2) update CLAUDE.md to add the convention/
acisseJZhong
force-pushed
the
fix_attention_shape_annotation
branch
2 times, most recently
from
June 16, 2026 22:23
2200b62 to
6cf44ed
Compare
acisseJZhong
force-pushed
the
fix_attention_shape_annotation
branch
from
June 16, 2026 23:21
6cf44ed to
404bf7f
Compare
Contributor
Author
|
updated CLAUDE.md and CONTRIBUTING.md. The 8gpu feature tests are failing on main, 8 gpu model tests should be fixed by #3681 |
acisseJZhong
added a commit
that referenced
this pull request
Jun 18, 2026
fixed attention qkv notation after #3443 where the RL unit test was skipped
acisseJZhong
added a commit
to acisseJZhong/torchtitan
that referenced
this pull request
Jun 18, 2026
…x rename The shape-suffix rename in pytorch#3443 changed GQAttention.forward's first parameter from `x` to `x_BLD`, but set_gqa_attention_sharding still keyed the input redistribution under "x". The redistribution engine matches in_src/in_dst keys against the actual forward parameter names (via inspect.signature), so in_*_shardings.get("x_BLD") returned None and the attention block's "gather x to Replicate on TP" became a silent no-op. Under SP this left the activation Shard(1) entering the QKV projection. The non-fused QKVLinear has no input check and silently tolerated it, but the fused path's in_src check rejected it, failing the 8-GPU qwen3_fsdp+tp+cp_no_sp_fused_qkv integration test: ValueError: FusedQKVLinear.x: input DTensor has placements (Shard(dim=1),), but in_src_shardings expects (Replicate(),). Fix: key the GQAttention input redistribution under "x_BLD" so the gather runs. With the gather restored, the FusedQKVLinear wrapper config is redundant -- the in_dst was a Replicate->Replicate no-op, and the tuple out_src is a no-op under default/full_dtensor and raises under spmd_types -- so remove it; the fused branch now mirrors the non-fused one (colwise on wqkv only). q/k/v outputs stay Shard(2) via DTensor view/split propagation and are validated at the inner-attention and qk-norm boundaries. Affects all GQAttention models (qwen3, llama3); gpt_oss is unaffected (its Attention.forward still uses `x`).
acisseJZhong
added a commit
that referenced
this pull request
Jun 18, 2026
…3708) ## Summary `set_gqa_attention_sharding` keyed the attention input redistribution under `"x"`, but #3443 renamed `GQAttention.forward`'s first parameter to `x_BLD`. The redistribution engine looks up `in_src`/`in_dst` by the actual forward parameter name, so the lookup missed and the "gather x to Replicate on TP" silently no-op'd. Under sequence parallelism the activation reached the QKV projection still `Shard(1)`, which the fused path rejected: ``` ValueError: FusedQKVLinear.x: input DTensor has placements (Shard(dim=1),), but in_src_shardings expects (Replicate(),). ``` ## Changes - Key the GQAttention input redistribution under `x_BLD` so the gather runs. - Drop the now-redundant `FusedQKVLinear` wrapper config (its `in_dst` was a no-op and its tuple `out_src` does nothing in default/full_dtensor and raises under spmd_types); the fused branch now matches the non-fused one.
HosseinKaviani-H
pushed a commit
to HosseinKaviani-H/torchtitan_local
that referenced
this pull request
Jun 23, 2026
Follow core torchtitan convention (PR pytorch#3443): name Q/K/V/out tensors with shape suffixes (q_BLNH native layout, q_BNLH flex-kernel layout) and add a legend comment. Pure rename + ASCII-ize the layout-transition comments; no behavior change.
HosseinKaviani-H
pushed a commit
to HosseinKaviani-H/torchtitan_local
that referenced
this pull request
Jun 29, 2026
Follow core torchtitan convention (PR pytorch#3443): name Q/K/V/out tensors with shape suffixes (q_BLNH native layout, q_BNLH flex-kernel layout) and add a legend comment. Pure rename + ASCII-ize the layout-transition comments; no behavior change.
HosseinKaviani-H
pushed a commit
to HosseinKaviani-H/torchtitan_local
that referenced
this pull request
Jun 30, 2026
Follow core torchtitan convention (PR pytorch#3443): name Q/K/V/out tensors with shape suffixes (q_BLNH native layout, q_BNLH flex-kernel layout) and add a legend comment. Pure rename + ASCII-ize the layout-transition comments; no behavior change.
HosseinKaviani-H
pushed a commit
to HosseinKaviani-H/torchtitan_local
that referenced
this pull request
Jul 7, 2026
Follow core torchtitan convention (PR pytorch#3443): name Q/K/V/out tensors with shape suffixes (q_BLNH native layout, q_BNLH flex-kernel layout) and add a legend comment. Pure rename + ASCII-ize the layout-transition comments; no behavior change.
HosseinKaviani-H
pushed a commit
to HosseinKaviani-H/torchtitan_local
that referenced
this pull request
Jul 8, 2026
Follow core torchtitan convention (PR pytorch#3443): name Q/K/V/out tensors with shape suffixes (q_BLNH native layout, q_BNLH flex-kernel layout) and add a legend comment. Pure rename + ASCII-ize the layout-transition comments; no behavior change.
HosseinKaviani-H
pushed a commit
to HosseinKaviani-H/torchtitan_local
that referenced
this pull request
Jul 9, 2026
Follow core torchtitan convention (PR pytorch#3443): name Q/K/V/out tensors with shape suffixes (q_BLNH native layout, q_BNLH flex-kernel layout) and add a legend comment. Pure rename + ASCII-ize the layout-transition comments; no behavior change.
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.
Summary
Add shape suffix annotations to
attention.pyfollowing the Noam Shazeer shape suffix convention, matching the style introduced for MoE in #3425.Each attention backend's layout transformation is now explicit in variable names:
_BLNH: shared input/output layout (batch, seq, heads, head_dim)_TNH: VarlenAttention packed layout (T = B*L)_BNLH: FlexAttention / SDPA heads-first layoutNo functional changes — rename only.
Test plan
pre-commit run --all-files