[Bug] Context parallel crashes with asymmetric K/V head dims (GQA + enable_mla path)
I maintainer di solito rispondono entro 2 giorni
Nessuno ha ancora preso questa issue.
- #2901 di @beccohov — chiusa senza merge
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 68/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Tranquilla
- Ambito
- distributed-systems, machine-learning
Direzione di ricerca
Inizia da transformer_engine/pytorch/attention/dot_product_attention/context_parallel.py, in particolare dalla logica enable_mla intorno alla riga 1316 e dal reshape dell’output intorno alla riga 1854. Esegui la riproduzione CUDA distribuita fornita con dimensioni K/V asimmetriche e GQA, quindi confronta il percorso CP con quello non-CP. Il lavoro è completato quando il forward pass CP termina correttamente e produce un output con la forma attesa delle attention head.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug
When using DotProductAttention with context parallelism (CP) and asymmetric K/V head dimensions (kv_channels=(k_dim, v_dim) where k_dim != v_dim), the CP forward pass crashes with a shape mismatch in context_parallel.py.
The root cause: enable_mla = k.shape[-1] != v.shape[-1] (here) triggers the MLA code path, which reshapes the attention output using v_shape (derived from the V input tensor with num_kv_heads). However, with GQA the attention output has num_attention_heads (post-expansion), not
num_kv_heads, causing a size mismatch.
This affects models like MiMo-V2-Flash from Megatron Bridge (I'm currently implementing support for it here) which uses head_dim=192 for Q/K but v_head_dim=128 for V with GQA (num_attention_heads=64, num_kv_heads=4).
Steps/Code to reproduce bug
import os
import torch
import transformer_engine as te
from transformer_engine.pytorch.attention.dot_product_attention import DotProductAttention
print(f"TE version: {te.__version__}")
local_rank = int(os.environ.get("LOCAL_RANK", "0"))
torch.cuda.set_device(local_rank)
torch.distributed.init_process_group("nccl")
device = torch.device(f"cuda:{local_rank}")
B, T, num_heads, num_kv_heads = 1, 32, 8, 2
qk_head_dim, v_head_dim = 64, 48 # asymmetric: k != v
cp_group = torch.distributed.group.WORLD
# CP case doesn't work:
attn = DotProductAttention(
num_attention_heads=num_heads,
kv_channels=(qk_head_dim, v_head_dim),
num_gqa_groups=num_kv_heads,
attention_dropout=0.0,
tp_size=1,
tp_group=None,
cp_global_ranks=list(range(torch.distributed.get_world_size())),
cp_group=cp_group,
cp_stream=torch.cuda.Stream(),
softmax_type="vanilla", #"learnable" SWA uses attention sink bias
).to(device)
# non-CP works:
# attn = DotProductAttention(
# num_attention_heads=num_heads,
# kv_channels=(qk_head_dim, v_head_dim),
# num_gqa_groups=num_kv_heads,
# attention_dropout=0.0,
# softmax_type="vanilla", #"learnable" SWA uses attention sink bias
# ).to(device)
q = torch.randn(T, B, num_heads, qk_head_dim, device=device, dtype=torch.bfloat16)
k = torch.randn(T, B, num_kv_heads, qk_head_dim, device=device, dtype=torch.bfloat16)
v = torch.randn(T, B, num_kv_heads, v_head_dim, device=device, dtype=torch.bfloat16)
out = attn(q, k, v, attn_mask_type="causal")
Expected behavior
CP forward should handle asymmetric K/V head dims with GQA correctly. The output reshape at context_parallel.py should use the attention output's actual shape (num_attention_heads) rather than the V input shape (num_kv_heads).
Environment overview (please complete the following information)
- PyTorch: 2.7
- Transformer Engine: 2.13.0
- CUDA: 13.0
Device details
- GPU model
Additional context
Add any other context about the problem here.
- Lingua principale
- Python
- Stelle
- 3.6k
- Fork
- 851
- Merge medio
- 4g 20h
- PR unite (30g)
- 58
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di NVIDIA/TransformerEngine
-
[Bug] group_quantize_fp8_blockwise: mbarrier invalidated before other threads finish waiting on itAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
NVIDIA/TransformerEngine#3647 ·
I maintainer di solito rispondono entro 2 giorni
-
[PyTorch] fp8_cs_quantize fake implementation returns a vector inverse scale instead of a scalarForse già presa @sanjana658 l’ha presa 4 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
NVIDIA/TransformerEngine#3636 · 2 commenti ·
I maintainer di solito rispondono entro 2 giorni
-
[Bug] Backend selection picks FA3 for training with head_dim_qk=192 / v_head_dim=128, but FA3 backward cannot run itForse di nuovo libera @modelpath-dev l’ha presa 38 giorni fa e non c’è nessuna pull request aperta. Apertaattention
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
NVIDIA/TransformerEngine#3481 · 4 commenti ·
I maintainer di solito rispondono entro 2 giorni
-
Increase MAX_TENSOR_NUMApertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
NVIDIA/TransformerEngine#2189 · 7 commenti · 5 reazioni ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
NVIDIA/TransformerEngine#3668 ·
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di NVIDIA/TransformerEngine
Issue simili
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 88/100
gradio-app/gradio#13964 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 93/100
BSData/horus-heresy-3rd-edition#3232 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
jbacalso24/mimry#123 ·
I maintainer di solito rispondono entro 1 giorno
-
p:3-mid pydanty:bug pydanty:is-working
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
pydantic/pydantic-ai#10153 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
good first issue priority: medium size: S testing
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
cubrid-lab/cubrid-cookbook-python#316 ·
I maintainer di solito rispondono entro 1 giorno