Skip to content

Expert weight-gradient GEMMs: per-call transpose staging costs more than the GEMM #43

Closed

Description

@feitreim

Expert weight-gradient GEMMs: per-call transpose staging costs more than the GEMM

Profile (B200, L=12 B=8 T=2048 D=3072 HD=128 FF=4096 E=8 K=2 C=4096, §10.1; totals are 12-block sums):

span ms share of the ~410 ms non-attention step
backward.experts.gate_up_weight_gemm 47.65 11.6%
backward.experts.down_weight_gemm 26.46 6.5%
(compare) forward.experts.gate_up_gemm 20.74 —

The gate_up weight-grad span covers ≈ 1.98e13 FLOP → ≈ 416 TFLOP/s, ~18% of bf16 peak, while the forward expert GEMM — same tcgen05 pipeline, same shapes family — runs ≈ 956 TFLOP/s (~42%). The difference is not the MMA: the weight-gradient path (expert_linear_backward, and identically GpuLinear::backward_into for the block linears) quantizes both operands and then runs two full transpose_bf16_pairs passes to build the K-contiguous lhs_t/rhs_t panels the f32_accumulate kernel wants, every call, every block. At E·C = 2N rows × up-to-8192 columns that staging traffic rivals the GEMM itself.

This is the same disease the lm-head already shows in miniature (backward.lm_head.transpose_dlogits, a pure-movement transpose feeding the weight GEMM) — worth fixing with the same cure.

Sketch

The #35 capability audit already established that v0.2.1's tcgen05 MMA descriptors carry transpose_a/transpose_b bits. A TN variant of the accumulate kernel (dW += Aᵀ·B with A and B consumed in their native row-major layouts via descriptor transpose and/or TMA box geometry) eliminates both explicit transposes; the quantize passes remain (fp32 master activations → bf16 pairs) but drop from quantize + transpose × 2 to quantize × 2. If the descriptor route hits a layout constraint the fallback is a fused quantize-transpose kernel (one pass instead of two), worth roughly half the win.

Applies to, in descending value: expert gate_up/down weight grads, block-linear (qkv/o_proj) weight grads (backward.qkv_proj.weight_gemm 15.6 ms includes the same staging), lm-head dlogits transpose.

Gates

  • Expert + block-linear + lm-head parity gates unchanged (bit-level accumulate semantics may shift within bf16 tolerance — existing atol/rtol apply).
  • §10.1 same-container profile: expect the two expert weight-grad spans to land near their forward counterparts' efficiency (~2× reduction, ≈ −40 ms/step at B=8).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions