Repository navigation
[VocabTP] Add vocabulary-parallel generalized JSD with Triton kernels - #8958
Merged
Merged
Conversation
Codex Review SummaryThis 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. |
jinyouzhi
force-pushed
the
vocab-parallel-jsd-core
branch
from
October 30, 2026 15:04
1036bdc to
f5a2c5a
Compare
Support generalized teacher-student JSD with local gradients, eager fallback, and CUDA/XPU Triton kernels. Add dense-reference, tensor-parallel and optimizer parity tests plus usage documentation. Signed-off-by: Jin, Youzhi <youzhi.jin@intel.com>
delock
self-requested a review
November 4, 2026 00:28
delock
reviewed
Nov 4, 2026
| kwargs['device'] = target_device | ||
| tensor: Tensor = fn(*args, **kwargs) | ||
| if target_fp_dtype is not None and tensor.is_floating_point(): | ||
| if target_fp_dtype is not None and kwargs.get("dtype") is None and tensor.is_floating_point(): |
Collaborator
There was a problem hiding this comment.
Why we need this behavior change? This seems not related to vocab parallel.
Collaborator
|
Hi @jinyouzhi , thanks for the PR. There seems to be a unrelated hunk in this PR, can you take a look? Thanks! |
This change is tracked separately in deepspeedai#8959 (fixes deepspeedai#8948). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Jin, Youzhi <youzhi.jin@intel.com>
delock
approved these changes
Nov 7, 2026
delock
enabled auto-merge
November 8, 2026 15:10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Teacher-student training compares the models' next-token distributions, not
just the probability of a single ground-truth token. DeepSpeed already offers
vocabulary-parallel forward/reverse KL, but does not support the interior
0 < beta < 1generalized Jensen-Shannon divergence used by GKD-styledistillation. Applying a local softmax independently on each vocabulary shard
does not compute the intended full-vocabulary objective.
TRL currently has two relevant implementations on its main branch:
experimental.GKDTrainercomputes generalized JSD from materialized logits;DistillationTraineruses completion filtering and tiled LM-head projectionto compute KL/JSD without materializing full logits. Those implementations do
not call DeepSpeed's vocabulary-parallel divergence ops. In particular,
support for DeepSpeed/ZeRO or FSDP parameter sharding is not itself support
for a vocabulary-parallel softmax and divergence.
This PR supplies the missing Core logits-based primitive, as a building block
for teacher-student workloads and a possible subsequent TRL integration. It
does not claim to integrate TRL or replace its memory-efficient tiled loss.
Refs #8790.
Changes
vocab_parallel_jsd(student_logits, teacher_logits, beta=0.5, tp_group=None), returning FP32 per-token divergence replicated on TP ranks.Reuse global normalization and reduce the two KL-to-mixture expectations
together. Recompute probabilities in registers during backward rather than
retaining full FP32 probability tensors; keep bounded eager chunks as fallback.
Triton capability flag or existing-op dispatch.
shards, empty local shards, and non-contiguous causal-shift views.
selects reverse KL. These are explicit endpoint branches, not continuous
limits of the weighted interior JSD.
the caller, following the existing vocabulary-parallel per-token ops.
Not a duplicate
interior-beta generalized JSD. The new API reuses their KL endpoints.
This PR does not edit
runtime/rollout/opsd.pyor its tests.does not change Examples, cache handling, rollout or trainer integration.
no LM-head projection changes or loss-function hooks.
Scope and limitations
This is a new opt-in logits-based API; existing ops and training defaults are
unchanged. Unlike the existing single-pass KL forward, JSD needs global
normalization before evaluating the nonlinear mixture: statistics and
divergence are two input passes. It still consumes materialized local logits.
Top-k restriction, pointwise
clipping, differing student/teacher shard layouts, fused-linear divergence,
DeepCompile support and automatic TRL integration are not included.
Every TP rank must supply identically ordered student/teacher vocabulary
shards and backpropagate the same replicated per-token loss.
Validation
Hardware: up to 4 Intel Arc Pro B70 GPUs, XCCL, driver 1.15.39122+11,
torch 2.14.0.dev20260804+xpu, Intel Triton 3.8.0. Final validation: 67 CPU
regressions passed, 11 fused XPU cases passed, and 4 distributed cases passed
at each of TP1/2/4. Existing entropy/KL Triton-only tests still skip on XPU
because their accelerator-wide flag remains disabled; JSD uses its own checked
Intel backend dispatch. The final TP cases cover FP32/BF16 interior JSD versus
an FP64 oracle, empty shards/disjoint support, and head SGD update parity.
On NVIDIA L20, driver 580.173.02, torch 2.14.1+cu130 (CUDA 13.0),
Triton 3.8.0, NCCL: the full test file passed, 113 passed with no skips.
This includes all JSD TP1/2/4 cases and FP32/FP16/BF16 single-device kernels.
The existing
dsconda environment was used without dependency changes;tested source hashes match the local implementation and tests.
Scoped pre-commit hooks and diff checks pass. Numerical checks use an
independent FP64 dense PyTorch reference, nonuniform vocabulary partitions,
FP32/BF16, both-input gradients and frozen inputs. Additional cases cover
disjoint support, undefined masked rows, empty local shards, empty token
batches, causal-shift views, independent large logit shifts and row chunking.
Three SGD updates of a sharded head match the dense reference at TP1/2/4.
This head-only training test does not exercise a DeepSpeed Engine or ZeRO.
Exploratory logits-only forward+backward A/B on B70, N=1024,
V=151936, BF16, beta=0.3, frozen teacher:
Five warmups and ten measured trials, synchronized wall time; per-trial MAX
over TP ranks, independently for time and memory. Resident input allocations
are included in peak. Student gradients are included. All arms start with sharded logits, and the dense arm includes
their gather; it is not TRL's existing chunked-projection implementation.
Losses and local student gradients match before timing. Clocks were not
pinned. This benchmark excludes head projection, backbone, optimizer and
rollout; it demonstrates only an op-level comparison, not full-training or
TRL speedup. Reproduction script and raw JSON/logs are retained locally and
should be attached to the PR when submitted. KL's Triton kernels are enabled
only in the XPU benchmark for comparison; their production dispatch is unchanged.
L20, same workload and protocol:
L20 clocks were also not pinned; these remain exploratory op-level timings.
All 15 CUDA sm89 offline kernel compilations pass (FP32/FP16/BF16 and both/
student-only/teacher-only backward variants), in addition to the actual L20
runtime validation above.
Not validated: ZeRO stages, offload, PP/SP,
DeepCompile, real-model convergence or TRL integration. No end-to-end speedup
or convergence claim is made.
AI assistance
Implementation, test preparation and this description were prepared with
GitHub Copilot CLI. Human review and independently run tests are required
before submission.