Skip to content

Commit c8cf0bc

Browse files
committed
fix(training): adopt the Megatron-Core loss contract for DSpark
Return the unnormalized micro-batch numerator plus num_tokens and reducible [numerator, denominator] reporting pairs, instead of dividing by a locally reduced denominator. Megatron-Core calls the loss once per micro-batch, so a locally normalized value accumulates a mean of micro-batch means and biases the objective whenever micro-batches carry different supervised-token counts. The unbiased global mean needs calculate_per_token_loss=True, which assert_per_token_loss_config now enforces at the integration point. Chunk the FP32 probability L1 so the softmax temporaries are bounded by chunk_tokens * vocab rather than the full [batch, num_blocks, block_size, vocab] tensor, recomputing each chunk in the backward. Three such tensors at reference scale are several GiB of forward temporaries before autograd storage. Correct the objective's documentation: the training term is the raw weighted L1 of paper Eq. 10, and the factor 1/2 belongs only to the Eq. 8 acceptance label. The implementation already did this; the docstring and the design page did not. A disjoint-distribution regression now asserts l1_loss == 2 with accept_rate == 0 so the two cannot drift apart again. Rewrite the 2-GPU functional test around the new contract: two ranks, two micro-batches each, uneven supervised-token counts, asserting both that the global-token gradient matches the single-process reference and that the per-micro-batch normalization does not. Add a dedicated L0 launch script so CI actually selects the test, using a single pytest coordinator because the test self-spawns its ranks. Signed-off-by: khazic <khazzz1c@gmail.com>
1 parent e49c1aa commit c8cf0bc

5 files changed

Lines changed: 557 additions & 193 deletions

File tree

‎src/megatron/bridge/training/post_training/dspark/__init__.py‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
1717
This package holds the pure-``torch`` pieces of DSpark draft training: the
1818
sequential (Markov / RNN) and confidence heads (:mod:`heads`) and the three-term
19-
CE / TV / confidence objective with its acceptance metrics (:mod:`loss`). The
19+
CE / L1 / confidence objective with its acceptance metrics (:mod:`loss`). The
2020
parallel-aware draft backbone and the Megatron-Core forward-step / provider wiring
2121
are separate, GPU-validated concerns. See ``docs/training/dspark-speculative-decoding.md``.
2222
"""
@@ -28,7 +28,11 @@
2828
VanillaMarkov,
2929
build_markov_head,
3030
)
31-
from megatron.bridge.training.post_training.dspark.loss import DSparkForwardOutput, dspark_loss
31+
from megatron.bridge.training.post_training.dspark.loss import (
32+
DSparkForwardOutput,
33+
assert_per_token_loss_config,
34+
dspark_loss,
35+
)
3236

3337

3438
__all__ = [
@@ -37,6 +41,7 @@
3741
"GatedMarkovHead",
3842
"RNNHead",
3943
"VanillaMarkov",
44+
"assert_per_token_loss_config",
4045
"build_markov_head",
4146
"dspark_loss",
4247
]

0 commit comments

Comments
 (0)