Repository navigation
[3/3] feat(training): offline cost-aware scheduling - #988
Open
yushengsu-thu wants to merge 11 commits into
Open
yushengsu-thu wants to merge 11 commits into
yushengsu-thu wants to merge 11 commits into
Conversation
…ware scheduling DSpark historically averages every DP micro-batch round by its own all-reduced token weight (`round`). Cost-aware scheduling regroups rounds by cost, which would make that normalization re-weight tokens by round composition, so the model gains a `step` mode: it hands the trainer additive `loss_terms` and the whole optimizer step is averaged by its global token weight, like DFlash, with no per-micro-batch all-reduce. The mode is chosen automatically (`step` with `training.cost_aware_scheduling`, `round` otherwise) and recorded in the DSpark resume contract.
Checkpoints written before the DSpark resume contract recorded `dspark_loss_normalization` were trained with the per-round normalization. Treat a missing key as `round` so those runs resume unchanged, while a resume that now resolves to `step` (cost-aware scheduling on) is still rejected.
One optimizer window is sorted by a per-sample cost key, cut into DP rounds of similar cost, and each rank takes one contiguous slice. The planner is pure Python so the online dispatcher and the offline sampler can share it.
…ithm scheduling keys `training.cost_aware_scheduling` enables cost-balanced DP rounds; `training.cost_aware_key` picks the per-sample cost (`length`, `anchors`, or `auto` for the key each algorithm declares in its capabilities: `anchors` for the DFlash family, `length` for EAGLE3, P-EAGLE and MTP). The application layer rejects algorithms without a key, EAGLE3 above batch size 1 (its loss is a per-micro-batch mean), and the anchors key on non-anchor objectives. With scheduling on, DSpark resolves to its per-step loss normalization.
The capture producer counts the positions whose own and next token are supervised (the DFlash-family anchor rule) from the prompt's loss mask and stores the count in the ref metadata, next to num_tokens, so the online consumer can schedule by anchors without touching the features.
…-balanced rounds With a scheduling policy the rank-0 distributor plans every secured optimizer window with the shared planner and publishes its rounds to the per-rank inboxes in planned order, so each round holds samples of similar cost. Inboxes are consumed in publish order, so the ack and backpressure accounting is unchanged. A window whose refs carry no anchor count is scheduled by length, and one without any usable cost keeps arrival order. The online consumer records the policy in its checkpoint contract; older checkpoints without the key resume with scheduling off.
Offline refs need one cost per sample before the first epoch is planned. Refs that carry num_tokens and valid_anchors metadata are used as-is; file:// refs are scanned once (input_ids and loss_mask) in parallel threads and cached under output_dir, keyed by the file list, sizes, mtimes and max_length. The disaggregated offline producer records valid_anchors in the ref metadata so its consumer needs no scan.
The offline sampler keeps its seeded per-epoch permutation and DP padding, then regroups each window of rounds before the DP striding so every rank's consecutive micro-batches form the planned rounds. Windows follow the global micro-batch count (gradient accumulation spans epochs) and the drop_last tail keeps its order, so each optimizer step trains on the same samples as without scheduling. `training.cost_aware_window` widens the window beyond one step for offline runs. The builders record the policy, window, max_length and a digest of the per-sample costs in the checkpoint, so a resume whose ordering inputs differ is rejected.
…ne runs CUDA tests through the offline trainer runtime: a DSpark run with scheduling resumes from its checkpoint with the same inputs, and is rejected when max_length changes or scheduling is switched off; EAGLE3 trains at batch size one with the length key. The docs page gains the offline section and the offline measurements.
The offline DSpark rows in "Measured effect" were run with a Qwen3.8-27B target, not Qwen3.5-27B. Co-Authored-By: Claude Opus 5.5 <[email protected]>
yushengsu-thu
requested review from
FlamingoPg,
FrankLeeeee,
shuaills and
sleepcoo
as code owners
October 17, 2026 03:21
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.
Part 3/3 of #955. Stacked on #986 and #987 (just this part).
Same scheduling for offline runs. The sampler keeps its seeded shuffle and DP padding, then regroups each window by cost before striding over ranks, so by default every step still gets the same samples. Costs come from ref metadata or a one-time scan cached under
output_dir.cost_aware_windowcan widen the window past one step, and resume checks the policy,max_lengthand a cost digest. Also fixes the offline benchmark target in the docs (Qwen3.8-27B).Offline, Qwen3-8B, DP4 on 4x H200, samples/s (setup):