Repository navigation
Conversation
…k support Signed-off-by: Jin, Youzhi <youzhi.jin@intel.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b740bbd759
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| dist.all_reduce(upper, op=dist.ReduceOp.MAX, group=tp_group) | ||
| if not torch.equal(lower, upper): | ||
| raise ValueError("TP peers must provide identical targets and position masks") | ||
| if (valid & ((target < 0) | (target >= vocab_size))).any().item(): |
There was a problem hiding this comment.
Skip the duplicate TP range synchronization
When tp_group is parallel, the same invalid-target predicate has already been globally reduced and checked at lines 226-229, so reaching this line proves it is false on every peer. Recomputing it with .any().item() on every scoring forward forces an additional device-to-host synchronization in the per-microbatch TP training path; run this local check only in the non-TP branch or reuse the previously computed result.
AGENTS.md reference: AGENTS.md:L40-L40
Useful? React with 👍 / 👎.
Summary
Add
vocab_parallel_linear_logprobs, an opt-in primitive that computes FP32per-token selected log-probabilities and optional entropy directly from hidden
states and resident vocabulary-sharded LM-head parameters.
Refs #8790 and the third request in
#8942 (comment).
positions in the LM head while retaining them as backbone context.
recompute projection tiles in backward without retaining full local logits.
uneven/empty vocabulary shards. Return unreduced scores; the caller owns
causal alignment, masking policy and loss.
Scope and related work
Existing vocab-parallel scoring ops consume materialized logits; fused-linear
CE does not expose selected-token scores and entropy. This complements the
sequence chunking in deepspeedai/DeepSpeedExamples#1023 and the rollout/GRPO
work in #9037; it does not change either architecture or implement a GRPO loss.
Duplicate searches found no existing streamed-scoring PR.
Hidden gradients are reduced inside this primitive exactly once: pass original
decoder hidden states, not the head's TP backward-reduction mapping.
An opt-in
allow_empty_shardsargument extends the existing metadata helper;existing callers keep their previous behavior.
Validation
Hardware: 2 x NVIDIA L20, physical GPUs 0 and 3, driver
580.173.02.Software: Python
3.10.22, PyTorch2.14.1+cu130, Transformers5.17.0,pytest
9.1.1.git diff --checkCUDA coverage includes TP2 FP32/BF16 scores and hidden/head/bias gradients,
uneven/empty shards, all-masked/zero-token batches and collective input errors.
A TP1 ZeRO-0 Engine test matches dense loss, gradients and parameters over
three AdamW updates. Additional FP32 integration tests cover:
shards, and ZeRO-0/2. Over three SGD updates, scores, reconstructed shared
gradients/weights and final-normalization gradients/weights match the dense
reference. The test verifies that AutoTP preserves the shared Parameter.
including an all-masked microbatch on one rank. Full averaged gradients and
parameters match the dense reference over three AdamW updates.
The 10 skips are existing JSD cases whose world-size list includes four ranks;
only the requested two GPUs were visible. Both test commands completed
successfully: 94.71 seconds for the final new suite, 291.60 seconds for regression.
Draft limitations
Only resident linear heads are supported; ZeRO-3 parameters are rejected.
No automatic trainer integration, sequence-sharded hidden states, quantized
heads, higher-order gradients or implicit model-specific/sampling transforms.
The distribution is full-vocabulary softmax after temperature; matching rollout
scores requires a separately agreed probability contract.
Bounded projection tiles do not bound total memory: compaction retains the scored
hidden states, and head gradients accumulate in a full local-shard FP32 buffer.
Eager tile launches, per-token-chunk collectives and input-validation
synchronization are additional costs that need end-to-end measurement.
Not qualified: new scoring with FP16 loss scaling, BF16 ZeRO-2 integration,
ZeRO-1, offload, complete external GRPO/TRL consumers, other accelerators,
or combined TP x DP, PP/SP/EP.
Full-step throughput, peak memory, token capacity and convergence have not
been benchmarked; no improvement in those metrics is claimed. Those
measurements and a real consumer remain follow-ups before ready-for-review.
Potential follow-ups (not implemented in this PR)
These are separate directions for discussion and qualification, not claims of
support or commitments to expand this PR:
integration with Add a multi-turn GRPO example with tool calling, and port OPSD to the per-sample rollout API DeepSpeedExamples#1023, keeping rollout and GRPO
loss in the example. Compare full-step throughput, peak memory and token
capacity against its existing sequence-chunked head and a sequence-chunked
vocab-parallel baseline; validate training numerics before claiming a benefit.
0ac80058as the initial contract reference. Potential additions include logit scaling
and soft-capping in the correct order, TP-global
support_idsnormalization,multiple
score_ids,log_sum_sq_probs,mean_logits,is_top1, and anexplicit FP32 projection option. Match padding, tie-breaking, numerical
stability and differentiable/non-differentiable output semantics, with dense
and TRL-reference output/gradient tests at TP1/TP2.
alignment, loss normalization, MoE auxiliary loss and PEFT/generation behavior
in TRL or its integration layer, rather than in this Core primitive. Backend
selection must be TP-aware: an unsupported path must not silently normalize
over only a local vocabulary shard. Full TRL fused-head compatibility is not
provided by the current primitive.
head materialization/release across forward and recomputed backward.
Separately qualify BF16 ZeRO-2 integration, FP16 loss scaling, offload and
combined parallel layouts; define contracts for non-plain heads before
claiming support.
independent initially; consider consolidating common streamed-projection
machinery when more consumers justify it. Streamed dense KL/JSD would be a
separate primitive, potentially relevant to
Add vocabulary-parallel KL support to OPSD DeepSpeedExamples#1019: selected-token scores and entropy cannot
replace its exact full-vocabulary distillation loss. Profile the actual
bottleneck before prioritizing that extension.
Prepared with GitHub Copilot CLI assistance.