Skip to content

Fix GQAttention input redistribution disabled by x -> x_BLD rename - #3708

Merged
acisseJZhong merged 1 commit into
pytorch:mainfrom
acisseJZhong:fix-gqa-fused-qkv-sharding-key
Jun 18, 2026
Merged

acisseJZhong merged 1 commit into
pytorch:mainfrom
acisseJZhong:fix-gqa-fused-qkv-sharding-key

Conversation

@acisseJZhong

@acisseJZhong acisseJZhong commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

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.

…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`).
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jun 18, 2026
@acisseJZhong
acisseJZhong requested a review from pianpwk June 18, 2026 04:33
@acisseJZhong
acisseJZhong merged commit 9ccbb57 into pytorch:main Jun 18, 2026
26 of 32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/8gpu CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants