Repository navigation
Commit c8cf0bc
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
- tests
- functional_tests
- launch_scripts/h100/active
- test_groups/training
- unit_tests/training/post_training
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
32 | 36 | | |
33 | 37 | | |
34 | 38 | | |
| |||
37 | 41 | | |
38 | 42 | | |
39 | 43 | | |
| 44 | + | |
40 | 45 | | |
41 | 46 | | |
42 | 47 | | |
0 commit comments