Megatron-LM icon indicating copy to clipboard operation
Megatron-LM copied to clipboard

[ENHANCEMENT] Opt-in PyTorch grouped weight gradients for SM90 BF16 MoE experts

Open ggboooy opened this issue 1 month ago • 0 comments

Is your feature request related to a problem? Please describe.

On SM90, the legacy TE BF16 MoE expert path can dispatch grouped weight gradients as one cuBLASLt GEMM per expert across internal streams. At 64 local experts, this introduces significant eager submission overhead, particularly for shorter expert token counts.

Describe the solution you'd like

Add an opt-in MCore TEGroupedLinear path using PyTorch grouped matmul for weight gradients, keeping TE forward/dgrad GEMMs and the same expert parameters/checkpoint keys. Reuse packed activations and prepare cumulative offsets in forward with a nonblocking pinned-memory copy.

The proposed initial scope is eager SM90 BF16 without bias, fused main-grad accumulation, delayed wgrad, offload, grouped parameter storage or expert TP/GTP. Unsupported invocations should retain the original TE implementation.

Describe alternatives you've considered

  • Keep the current TE per-expert cuBLASLt dispatch.
  • Optimize the corresponding path upstream in Transformer Engine.
  • Use the native TE GroupedTensor/op-fuser backend, which is a separate implementation and is not compared by the prototype benchmark.
  • DeepGEMM K-grouped gradients, which require additional layout/padding handling in this workload.

Additional context

A prepared implementation has passed 36 focused tests on each of two SM90 GPUs, including native-TE comparisons, accumulation/recompute, fallback, checkpoint contracts and bit-exact replay under contention.

Isolated module benchmarks use 80 real expert-token distributions from Qwen3.5-35B-A3B (8K/32K source sequences, 64 experts), with newly generated BF16 input values. In the tested cases, dW speedups range from 1.327x to 5.144x; complete GroupedLinear forward/backward speedups range from 1.422x to 1.538x. These are isolated eager calls, not whole-model training throughput. The proposal includes the fixtures and benchmark runner.

Assisted-by: OpenAI Codex

ggboooy avatar Oct 11 '26 15:10 ggboooy