Skip to content

[3/3] feat(training): offline cost-aware scheduling - #988

Open
yushengsu-thu wants to merge 11 commits into
sgl-project:mainfrom
yushengsu-thu:cost-aware/3-offline
Open

yushengsu-thu wants to merge 11 commits into
sgl-project:mainfrom
yushengsu-thu:cost-aware/3-offline

Conversation

@yushengsu-thu

@yushengsu-thu yushengsu-thu commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

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_window can widen the window past one step, and resume checks the policy, max_length and 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):

baseline cost-aware
DFlash 22.16 23.47 +5.9%
DFlash2 22.59 23.96 +6.1%
DSpark 29.42 31.86 +8.3%
Domino 40.55 41.43 +2.2%
EAGLE3, bs 1 11.71 11.78 +0.6%

yushengsu-thu and others added 11 commits October 16, 2026 20:02
…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]>
Copilot AI balanced review requested due to automatic review settings October 17, 2026 03:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants