Repository navigation
feat(training): cost-aware scheduling (online + offline) and DSpark step-level loss normalization - #955
Closed
yushengsu-thu wants to merge 11 commits into
Closed
feat(training): cost-aware scheduling (online + offline) and DSpark step-level loss normalization#955yushengsu-thu wants to merge 11 commits into
yushengsu-thu wants to merge 11 commits into
Conversation
yushengsu-thu
force-pushed
the
dspark-loss-normalization
branch
from
October 13, 2026 09:34
8b6cab8 to
fdcc2ed
Compare
…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.
yushengsu-thu
force-pushed
the
dspark-loss-normalization
branch
from
October 13, 2026 12:57
3fcf007 to
12c3553
Compare
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.
9 tasks
yushengsu-thu
marked this pull request as ready for review
October 16, 2026 00:37
yushengsu-thu
requested review from
FlamingoPg,
FrankLeeeee,
shuaills and
sleepcoo
as code owners
October 16, 2026 00:37
Contributor
Author
Throughput: cost-aware scheduling vs. baseline (Qwen3-8B, 4x H200)Steady-state training throughput in samples/s, summed over all trainer ranks. Each row compares the default dispatch with
Each configuration ran once, and step time varies by about ±2-3% within a run, so gains of about 3% or less should be read as no change. Models
Dataset
|
This was referenced Oct 17, 2026
curnane-lab
reviewed
Oct 17, 2026
Comment on lines
+81
to
+97
| def scan_feature_files( | ||
| paths: Sequence[str], max_len: int, *, workers: int = _SCAN_WORKERS | ||
| ) -> Dict[str, FileEntry]: | ||
| """Scan ``paths`` in parallel threads (I/O bound: mmap + two small tensors).""" | ||
| entries: Dict[str, FileEntry] = {} | ||
| total = len(paths) | ||
| with ThreadPoolExecutor(max_workers=max(1, workers)) as pool: | ||
| scanned = pool.map(lambda path: scan_feature_file(path, max_len), paths) | ||
| for count, (path, entry) in enumerate(zip(paths, scanned), 1): | ||
| entries[path] = entry | ||
| if count % 1000 == 0 or count == total: | ||
| logger.info( | ||
| "cost-aware scheduling: indexed %d/%d feature files", | ||
| count, | ||
| total, | ||
| ) | ||
| return entries |
Collaborator
There was a problem hiding this comment.
Does that actually go through mmap, as the comment on scan_feature_files claims? If it materializes every tensor, the one-time index build is a full dataset read per rank — 20k feature files is a lot of I/O, multiplied by DP size since every rank scans independently
Collaborator
|
Closed due to PR 966 is merged |
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.
Motivation
This PR is the first of three:
round, today's behaviour, stays bit for bit otherwise)RefDistributor)Design
Split
If need, this PR carries three parts; they can also be reviewed as three stacked PRs (1 is independent, 3 depends on 2).
round, today's behaviour, stays bit for bit otherwise); resolved mode in the resume contract, old checkpoints resume asroundcost_aware_scheduling/cost_aware_keyconfig, per-algorithm key declaration and validation,RefDistributordispatches planned rounds, producer recordsvalid_anchorscost_aware_window, offline resume contract