Add an experimental DeepSeek-V4 TOP parity contract#1788
Draft
kaixih wants to merge 2 commits into
Draft
Conversation
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
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.
Summary
This draft adds a self-contained, experimental DeepSeek-V4 true-on-policy (TOP) numerical contract for the:
path.
The main acceptance criterion is exact equality between the behavior-policy log-probabilities recomputed by SGLang prefill and the log-probabilities consumed by the Megatron training forward pass.
This is intentionally a draft/reference implementation. The change is large and is expected to be split into smaller, independently reviewable follow-up PRs before upstreaming.
Motivation
Matching the prefill scorer and trainer scorer requires more than synchronizing model weights or selecting nominally equivalent kernels. DeepSeek-V4's inference and training paths differed in floating-point association and implementation details across:
Small differences at these boundaries accumulate through the model and produce different per-token log-probabilities, even when both paths are individually deterministic.
What changed
Megatron/trainer path
SGLang/prefill path
Contract and CI behavior
--ci-testTOP assertions enabled.End-to-end evidence
Validated with
miles:lateston one 8xB200 node using the pruned four-layer DeepSeek-V4 model and TP8 for both SGLang and Megatron.The test uses neutral sampling transforms:
Positive run
Contract-off negative run
The same branch and E2E were run with only the SGLang source numerical contract disabled. The workload still initialized successfully, completed rollout/prefill/training forward, and reached the intended parity assertion.
Result:
0.057136059.0.25.This distinguishes a real numerical-contract failure from a startup/configuration failure and demonstrates that the E2E does not pass without the alignment implementation.
Tests
Final validation:
49 passedgit diff --check: cleanWhat this E2E proves
Within the tested contract, this is the key integration evidence for DeepSeek-V4 TOP: the SGLang prefill recompute scorer and Megatron training-forward scorer produce the exact BF16 per-token log-probabilities consumed by training.
It is analogous to the existing Qwen TOP E2E, with the additional requirement that five repeated DeepSeek-V4 prefill recomputations are themselves bitwise deterministic.
Current scope and limitations
This draft currently covers:
miles:latestIt does not yet establish:
Proposed follow-up decomposition
After reviewing this reference PR, the implementation can be split into smaller PRs such as: