Repository navigation
perf(dspark): normalize the loss once per optimizer window - #1171
Open
subhajitdchow wants to merge 1 commit into
Open
subhajitdchow wants to merge 1 commit into
subhajitdchow wants to merge 1 commit into
Conversation
DSpark all-reduced its token denominator on every micro-step. Export loss_terms like DFlash/Domino so TrainerCore normalizes gradients once at the optimizer boundary.
Author
|
@jiapingW can you please take a look at this PR? |
This branch has not been deployed
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
OnlineDSparkModelall-reduces its supervised-token denominator on everymicro-step and normalizes the loss inside the model. With gradient
accumulation this adds one blocking collective per micro-step (16 per optimizer
step at
accumulation_steps: 16), each a cross-rank sync point.DFlash, Domino, MTP and DSpine already return
loss_termsand letTrainerCorenormalize gradients once at the optimizer boundary. DSpark is theonly DFlash-family strategy that does not.
Modifications
OnlineDSparkModelno longer all-reduces per micro-step; it exportsloss_terms = (α_ce·CE + α_l1·L1 + α_conf·conf, local token count), the samecontract as DFlash. The returned loss is the rank-local mean.
_assert_async(global_loss_den > 0): a rank mayhave no supervised tokens in one micro-step, and the trainer already rejects
a non-positive window denominator.
DSparkTrainStrategypassesloss_termstoStepOutput.Gradients are now normalized by the token count of the whole optimizer window
instead of averaging per-micro-step means. This matches DFlash/Domino/EAGLE3
and is identical when micro-steps carry equal token counts.
Related Issues
N/A
Accuracy Test
tests/test_utils/test_dflash_losses.py(CPU) andtests/test_runtime/test_dflash_host_syncs.py(CUDA) check that the DSparkforward issues no
all_reduce, that a zero-token micro-step stays finite,that
TrainerCoregradients equal Σnum/Σden over a window with unequal tokencounts, and that a DSpark micro-step is host-sync-free. The three CPU tests
fail on
mainand pass with this change.new failures relative to
main.on
main(median per-step difference 0.5%), accuracy identical. Runs arebit-deterministic with a warm compile cache, so the difference is the
intended window weighting, not noise.
Benchmark & Profiling
Qwen3-4B DSpark, upstream
offline/colocated/qwen3-4b-dspark.yamlwithnproc_per_node: 8andaccumulation_steps: 16, 1 node of 8× AMD InstinctMI355X (ROCm 7.2, PyTorch 2.14), identical features, seed and data order. Optimizer
step time over steps 20–100:
mainThe median optimizer step time drops from 1.131 s to 1.021 s (−9.7%), and
training throughput improves by 10.8% (1.11×). A second pair of runs gave
the same result (−9.8% step time, +10.9% throughput).
Measured on a single node. Offline features were generated with a HuggingFace
forward pass (same layers and final hidden state) instead of the SGLang capture
plugin.
Checklist