Add vocabulary-parallel fused linear cross entropy #8792
All Vouch review confidence checks passed
Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 591 lines diff across 7 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.382
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #8792"
general
weight: 0.35
jinyouzhi
Follow-up to #8173.
Motivation
After #8173, a vocabulary-parallel LM head still materializes
[tokens, vocab / tp]logits on every rank. Its CE backward also keeps FP32 softmax buffers of the same size. For long sequences and large vocabularies, this is the largest activation in the step. For example, at 256K vocab, TP2, and 16K tokens, the loss path alone peaks at about 28 GiB per rank.Existing fused linear CE kernels do not cover this case. Liger's FLCE is not TP-aware (linkedin/Liger-Kernel#826, linkedin/Liger-Kernel#868). PyTorch's
F.linear_cross_entropychunks only over the batch dimension and takes no process group.What
deepspeed.sequence.linear_cross_entropy.vocab_parallel_linear_cross_entropy(hidden, weight, target, bias=None, tp_group=None, sp_group=None, vocab_start_index=None, vocab_end_index=None, ignore_index=-100, reduction="mean", chunk_size=None)(reductionis"none","sum"or"mean")head(hidden)plus the vocab-parallel CE, takingweight/biasfromVocabParallelLinear. Uneven shards are supported.h @ W_localᵀstraight into FP32 and runs one MAX all-reduce plus one SUM all-reduce (sum-exp and target logit packed together). Only the per-token max and sum-exp are kept.dWblock then comes from one GEMM over all tokens.dhis accumulated in FP32 and all-reduced over TP, matching the column-parallel head's backward. Backward needs no other collectives.dWis held, and backward is an ordinary autograd backward. The cost is one extra logits GEMM.hidden.chunk_sizetrades memory for speed.Validation
tests/unit/v1/sequence_parallelism/test_vocab_parallel_linear_cross_entropy.pyhas 24 tests. Values and gradients are checked againstF.linear+F.cross_entropyon the full vocabulary. Coverage:none/sum/meanreduction with a non-uniform upstream gradient, with and without bias, and forced chunking;F.linearhandles it;Ran on Intel Arc Pro B70 (XPU, XCCL): 30 passed.
test_vocab_parallel_cross_entropy.pystill passes (18 passed).Memory and time
Measured on 1× Intel Arc Pro B70, single-rank shard, H=4096, BF16. Peak is fwd+bwd and excludes inputs, but includes
dW/dh. The baseline ishead.weightlogits followed byvocab_parallel_cross_entropy.| Vocab / TP | Tokens | Baseline | This PR | Time (baseline → this PR) | torch
linear_cross_entropy(no TP, reference) ||---|---|---|---|---|---|
| 128K / TP8 | 8K | 1757 MiB | 569 MiB | 38.9 → 44.0 ms | 269 MiB, 30.3 ms |
| 128K / TP8 | 16K | 3508 MiB | 1008 MiB | 78.1 → 84.1 ms | 412 MiB, 59.7 ms |
| 128K / TP2 | 8K | 7014 MiB | 945 MiB | 158.8 → 173.5 ms | 698 MiB, 124.1 ms |
| 128K / TP2 | 16K | 14028 MiB | 1385 MiB | 316.8 → 331.4 ms | 892 MiB, 229.2 ms |
| 256K / TP2 | 8K | 14336 MiB | 1472 MiB | 314.2 → 370.3 ms | 1222 MiB, 372.2 ms |
| 256K / TP2 | 16K | 28672 MiB | 1921 MiB | 633.6 → 678.9 ms | 1416 MiB, 503.7 ms |
Peak memory drops by 3–15×, and time is 4–18% higher because backward recomputes the logits. The first design computed gradients during forward and accumulated
dWin FP32 over token chunks. That needed an FP32dWbuffer plus a cast copy, which came to about 3× the size ofdW: 3.6 GiB peak at 256K / TP2.Follow-ups
loss_function, so the existing loss hook cannot intercept them. The options are to patch the CausalLM forward behindvocab_parallel_ce_backend: "fused_linear", or to document the functional API only.VocabParallelLinearandSimpleModel, plus multi-rank e2e memory numbers.torch.linear_cross_entropy, e.g. by fusing the softmax-gradient elementwise ops.Limitations
out_dtype=torch.float32) are used where the backend supports them, such as XPU. Other backends, such as CPU, fall back to unfused ops.torch.autocast, the GEMMs run in the autocast dtype, asF.linearwould.cc @delock @PKUWZP