Pack Megatron SFT batches with shared prefix trees - #905
Merged
Merged
Conversation
Keep RL orchestration unchanged; prepare SFT payloads on CPU before rank fanout and schedule packed rows without changing optimizer-update identity. Preserve token labels and tree ancestry in dense and CP preparation. Validation: 53 existing packing/tokenization/local-SFT tests, exact supervised target/context preservation, and real BF16 tiny-Llama packed/unpacked loss and gradient parity pass. Full-model and distributed qualification remain in progress.
MCore updates routing bias independently of optimizer LR. Fixed-input H200 controls showed 13.1% gradient drift at LR zero, falling below 0.62% after restoring and freezing the bias. Preserve the pretrained routing correction used by inference; it is not part of the exported adapter.
Keep the RL packing default unchanged. Retain SFT geometry when differing supervision boundaries make bin-local rebuilding nonmonotonic. Cover exact target/context multiplicity and distributed dummy scheduling; check frozen router bias state. Validation: 53 existing tests and randomized CPU packing controls pass; tiny Llama BF16 CP1, CP2, DP2, PP2/VPP2 numerical checks pass. Full Lightning job and full-depth numerical qualification remain under investigation; no tolerance was relaxed.
AOT erases standalone wait_stream graphs, allowing compiled consumers to read unfinished shared-expert outputs. Keep input and output handoffs eager while preserving compiled side-stream computation. Add a deterministic delayed-producer regression using the real MCore output handoff.
FurtherAI
had a problem deploying
to
trainer-rank-gpu-validation
September 16, 2026 02:39 — with
GitHub Actions
Failure
FurtherAI
deployed
to
trainer-rank-gpu-validation
September 16, 2026 02:52 — with
GitHub Actions
Active
PeterWofford
deployed
to
trainer-rank-gpu-validation
September 16, 2026 17:49 — with
GitHub Actions
Active
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
Automatically prefix-pack Megatron SFT batches after tokenization and supervision-mask selection, without changing what callers submit or what constitutes an optimizer update.
batch_sizeremains examples per optimizer update;packed_sequence_lengthis a per-row capacity, not an executed minimum. Packing neither silently truncates examples nor combines optimizer batches to fill capacity.Correctness Fixes Found During Qualification
wait_stream()graphs, allowing consumers to read unfinished shared-expert outputs. Keep the two ownership handoffs eager while retaining compiled math and side-stream overlap. The retained CUDA regression uses the real MCore output handoff and a delayed producer; without the fix, a computation expected to return 4 returns stale data (2).Validation
Qualification is pinned to
78d835a5abc54bb07b8be80603495312f66e094d; this is not a claim of a new all-handler workflow pass.Existing focused tests (53), formatting/type/lock checks, and the final exact-context test also passed during qualification. The real job verifies learning rates 1e-6/2e-6/3e-6, per-update progress, finite results, and adapter/optimizer persistence.
Numerical Scope
No thresholds were relaxed, production precision was not changed, and natural-routing full-depth comparisons are not reported as all passing.
Two independent effects explain the remaining differences:
These controls distinguish packing/normalization/backward correctness from changes in the selected MoE branches. No production route replay was added to SFT.
Diff Scope
13 files, +573/-49 lines: production +247/-49, integration tests +304, documentation +22. The implementation consists of the SFT packing adapter, typed submission and row scheduling, and the small correctness fixes above; it does not introduce another training orchestrator.