Skip to content

Fix Qwen3.5 hybrid attention and add torch GDN fallback - #497

Open
ruijieguo wants to merge 1 commit into
alibaba:mainfrom
ruijieguo:fix/qwen3-27b-hybrid-training
Open

Fix Qwen3.5 hybrid attention and add torch GDN fallback#497
ruijieguo wants to merge 1 commit into
alibaba:mainfrom
ruijieguo:fix/qwen3-27b-hybrid-training

Conversation

@ruijieguo

Copy link
Copy Markdown

Qwen3.5 hybrid attention can fail when tensor parallelism exceeds the number of KV heads. With 24 query heads, four KV heads and TP=8, Megatron-Core 0.16.0 returns three query heads but six output-gate heads per rank. Slice the gate to the same rank-local heads as the query, while preserving results from Megatron versions that already do this correctly.

Add an explicit additional_configs.gdn_backend: torch option for environments where the fused causal-conv1d or FLA delta-rule kernels are unsuitable. It selects Megatron's existing PyTorch paths only for Qwen3.5 GDN layers. The default remains fla, other layers retain their deterministic settings, and checkpoint parameter names are unchanged. FLA is still required for its L2-normalization kernel.

Includes eight distributed regression cases and a reproducible text SFT example for Qwen3.6-27B and Qwen3.8-27B, whose configs use the qwen3_5 architecture.

Validation on eight H800 80 GB GPUs:

  • Eight regression cases passed on each of eight ranks, covering gate shapes and values, backward propagation, BF16 GDN with/without sequence parallelism, train/eval agreement, config persistence/validation, unchanged default kernel selection, and compatibility with an already-correct upstream gate.
  • Each full 27B model completed three BF16 SFT optimizer steps with finite losses, nonzero gradients, and successful checkpoints. Comparing saved checkpoints confirmed actual GDN, full-attention and MLP weight changes on all eight ranks.
  • Both final checkpoints reloaded through AutoModel.from_pretrained and produced finite logits in an eight-rank forward pass.
  • Ruff, Python syntax checks and git diff --check passed.

Tested with PyTorch 2.10.0+cu130, Megatron-Core 0.16.0, Transformers 5.5.4, Transformer Engine 2.14.1 and flash-linear-attention 0.5.0. The example uses TP=8, CP=1 and sequence parallelism, with packing disabled. The arithmetic data exercise execution and checkpointing; these runs do not establish model quality, long-run stability, or RLVR/DPO/vision support. The PyTorch GDN fallback may be slower and use more memory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant