Add vocabulary-parallel logprobs, entropy and KL ops #8791
All Vouch review confidence checks passed
Residual risk 0.19 = Change Risk (0.48) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.48 · 550 lines diff across 6 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.378
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #8791"
general
weight: 0.35
jinyouzhi
Implements PR-1 of #8790.
What
This PR adds
deepspeed.sequence.vocab_parallel_ops. The ops compute per-token quantities on the local logits shard of a vocabulary-parallel LM head (#8173), without gathering the full vocabulary:vocab_parallel_logprobs(logits, index, ...): log-probs of one id per token, or of top-k ids (index[..., k]). Positions equal toignore_indexreturn 0.vocab_parallel_entropy(logits, ...)vocab_parallel_kl_div(student, teacher, reverse=False, ...):KL(teacher‖student), orKL(student‖teacher)withreverse=True. Gradients flow to both inputs.How
[N]-sized per-token statistics: the max, the sum-exp, and then the selected logits, entropy, or KL. The KL op packs the student and teacher statistics into the same collectives.vocab_parallel_logprobsalso validates the shard layout with a small metadata all-gather per call, plus a MIN/MAX pair when the bounds are not passed explicitly. A caller that already validated the layout can passglobal_vocab_sizewith explicit bounds to skip that collective, as withvocab_parallel_cross_entropy.-infcontribute nothing to entropy, KL, or their gradients. A fully-infrow (e.g. padding) has no distribution: it returns NaN but gets zero gradient, so masking its output is safe. Entropy and KL need no shard bounds and also work when a rank's local shard is empty.[N]statistics are saved.Tests
tests/unit/v1/sequence_parallelism/test_vocab_parallel_ops.pyhas 33 tests. Values and gradients are checked against a full-vocab PyTorch oracle in fp32. bf16 inputs are checked against the fp32 oracle with a tolerance.-inf-masked vocabularies (oracle: the reduced vocabulary), and infinite KL when the target has mass on a masked token, including when that mass underflows to 0 in fp32, and zero (not NaN) gradients for ignored or masked fully-infrows in all four ops;global_vocab_sizepath, and double backward raising an error;Ran on 8× Intel Arc Pro B70 (XPU, XCCL): this file plus
test_vocab_parallel_cross_entropy.py, 51 passed. TP=2 tests cover uneven shards and an empty shard on one rank.Memory
1× B70, T=8192, V_local=16032 (128K / TP8), bf16. fwd+bwd peak, excluding inputs:
| Op | Naive PyTorch | This PR | Time (naive → this PR) |
|---|---|---|---|
| logprobs | 1506 MiB | 443 MiB | 7.5 → 21.4 ms |
| entropy | 3012 MiB | 586 MiB | 30.7 → 41.5 ms |
| reverse KL | 3012 MiB | 698 MiB | 37.2 → 70.2 ms |
| forward KL | 2510 MiB | 634 MiB | 24.8 → 64.3 ms |
Limitations