Skip to content

Optimize distributed draft training and decouple attention range from direction - #942

Closed
jiapingW wants to merge 6 commits into
sgl-project:mainfrom
jiapingW:feature/opt-training
Closed

jiapingW wants to merge 6 commits into
sgl-project:mainfrom
jiapingW:feature/opt-training

Conversation

@jiapingW

@jiapingW jiapingW commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator

Replacement stack

This combined PR is split into the following ten stacked PRs. Review and merge them in order. #963 combines the Domino and DSpark optimizations with shared projection controls; #964 is superseded. The original branch and description below remain available as provenance.

Layer PR Scope
1 #957 fix(runtime): retain references across partial and invalid streaming reads
2 #958 fix(training): synchronize DDP once per accumulation window
3 #959 fix(data): omit the implicit Qwen3 instruct system prompt
4 #960 feat(attention): configure draft range and direction independently
5 #961 perf(dflash): opt in to a fused frozen vocabulary head
6 #962 feat(training): support selective checkpoint contexts for frozen projections
7 #963 perf(training): share Domino and DSpark vocabulary projection controls
8 #965 feat(dspine): add an independently registered draft training algorithm
9 #966 feat(runtime): balance complete consumer optimizer windows by estimated cost
10 #967 docs(recipes): add portable RTX PRO5000 draft training examples

Each PR targets the preceding branch and documents actual dependencies. #962 provides selective checkpoint contexts; #963 shares cache_vocab_projection and flatten_vocab_projection between Domino and DSpark. #965 now targets #963. DSpine registration remains independent. New recipes omit max_checkpoints and resolve to unlimited retention (0).

Combined #963 layer: 58 tests passed. The prior full stack at eaa14f102d6a ran 405 targeted integration tests with 2 skips and zero failures/errors. Current scheduling/recipe revision at e35167c693d6: 135 targeted regression tests passed; pre-commit passed. #966 uses two_window_bucketed and two_window_joint_balanced, independently of the training method. These results do not claim full GitHub CI or end-to-end speedups.


Motivation

Improve disaggregated speculative-model training efficiency and make attention configuration explicit and maintainable across DFlash, Domino, DSpine, and DSpark. This PR combines distributed training fixes, DSpine integration, vocabulary-projection optimizations, and portable RTX PRO5000 training recipes, with regression coverage using the repository's unittest runner.

Description updated for PR head 211b87fc7d707e3a628cb95de5c73340af863c04.

Modifications

Training and runtime

  • Fix DDP gradient accumulation by applying no_sync() around both forward and backward; expose DDP bucket sizing.
  • Make streaming reference reads resilient to incomplete records and transient invalid reads without silently dropping samples.
  • Add an opt-in fused plain-DFlash head with BF16 CE handling, plus Domino Liger support and frozen-projection caching.
  • Integrate DSpine model/training support adapted from Add DSpine draft model and training support #917, including configuration, checkpoint conversion, Liger integration, flattened vocabulary projections, and a CE-only prepass for accumulated optimizer windows.
  • Add opt-in DSpark 2-D vocabulary projections and selective frozen-projection caching. The Qwen3-8B example uses causal attention, disables the confidence head, and keeps the CE/L1 objective weights unchanged.

Attention semantics

  • Separate attention range (layer_types: full_attention for global range or sliding_attention for local range) from direction (is_causal: bidirectional or causal).
  • Share visibility rules across dense and Flex Attention training masks, support native eager/SDPA cached inference, and validate checkpoint-resume mask semantics.
  • Preserve legacy training behavior when is_causal is omitted. With an explicit boolean, sliding-window limits apply to both context and draft positions; legacy sliding masks retain the causal draft prefix without applying the window to that prefix.
  • DSpine remains intrinsically causal and rejects is_causal: false. The checked-in Qwen3-8B DSpine config now explicitly declares is_causal: true; this does not change the existing global-causal training computation.
  • Reject unsupported bidirectional sliding-window export rather than silently changing attention semantics. SGLang bidirectional sliding-window support and deployment-specific serving patches are outside this PR.

Consumer dispatch

Document and validate four runtime.consumer_dispatch policies:

Policy Scheduling scope Behavior
round_robin (default) One optimizer window Assign arriving samples cyclically to consumer ranks.
cost_balanced One optimizer window Group samples by estimated cost and balance microbatches across ranks without changing the window's sample membership.
domino_balanced Two optimizer windows Sort samples across both windows, split them into cost buckets, and balance ranks within each resulting window. Domino only.
dspine_balanced Two optimizer windows Jointly balance virtual rank slots, then group similar-cost slots into real windows. Use the candidate only if the estimated sum of per-window maximum rank costs improves over independent cost_balanced windows; otherwise fall back. DSpine only.

The heuristic uses effective anchor counts and sequence lengths, including microbatch padding. It is not a real-time GPU utilization scheduler or a guarantee of wall-clock improvement.

Two optimizer windows does not mean accumulation_steps=2. For these TP=1 recipes, one global optimizer batch is consumer DP ranks × batch_size × accumulation_steps; the dual-window policies buffer twice that amount but still perform two separate optimizer updates. With 32 ranks and batch size 2, accumulation 2 means 128 samples per update and 256 samples buffered; accumulation 1 means 64 per update and 128 buffered. The dispatch optimization remains applicable with accumulation 1, independently of the DSpine CE prepass used for gradient accumulation.

Dual-window policies require in_flight_high_watermark to cover at least two global batches. They preserve per-rank sample counts, complete accumulation windows, sample coverage, and durable acknowledgement semantics, but can change optimizer-batch membership and the exact training trajectory. Extra buffering can increase startup/supply-wait latency. Even within-window reordering is not a bitwise training-trajectory guarantee.

Recipes, documentation, and tests

  • Rename the six cluster-specific PerfectBlend recipes and run identifiers to rtx-pro5000; document them as RTX PRO5000 examples. The 32-consumer/8-producer examples retain their training hyperparameters.
  • Replace hard-coded filesystem paths with repository/working-directory-relative paths. shared/ must refer to the same shared storage on every node; cache/ and runs/ are node-local. Service addresses remain configurable examples. These run identifiers do not rename existing checkpoints.
  • Keep the qwen3-instruct default system prompt empty and update both standard-conversation and tool-use token/loss-mask ground truths accordingly.
  • Convert all eight added model test modules to unittest.TestCase, using subTest, standard temporary directories, and unittest assertions/skips. Preserve the parameter combinations and numerical tolerances; no pytest dependency is required by these tests.
  • Update the DFlash loss-test stub for the new direction resolver, document training.domino_cache_projection, extend the DSpark config inventory, and add relative-path and explicit-DSpine-causality regression checks.
  • Keep .deployment/ ignored. Local deployment/evaluation scripts and their dedicated acceptance-aggregation test are not part of the PR's final diff.

Related Issues

  • Related to Add DSpine draft model and training support #917 (Add DSpine draft model and training support): this branch includes an adapted integration, not an automatic replacement or closure of that PR.
  • No issue is automatically closed by this PR.

Accuracy Test

Local validation uses Python 3.11, PyTorch 2.13.0+cu130, and Transformers 5.12.1. Results are separated by revision and scope rather than presented as a full-suite pass:

Validation Revision Result
Targeted model/runtime/configuration unittest regression 13f3bd6 320 tests: 318 passed, 2 skipped; 56.772 seconds
Qwen3 empty-system tokenizer regressions and template registry 13f3bd6 6 passed; official Qwen3-0.6B tokenizer cached locally because direct Hugging Face access from the test host timed out
Full unittest discovery/import check 13f3bd6 1,436 tests collected, zero import errors; collection only, not a full execution
Explicit DSpine causal-config follow-up, attention and DSpine regressions 211b87f 34 passed; 2.973 seconds

The main regression command at 13f3bd6 was:

CUDA_VISIBLE_DEVICES=0 OMP_NUM_THREADS=4 PYTHONPATH=. python -m unittest \
  tests.test_modeling.test_dflash_attention_direction \
  tests.test_modeling.test_dflash_sliding \
  tests.test_modeling.test_dflash_eager_attention \
  tests.test_modeling.test_flex_attention_backend \
  tests.test_modeling.test_dspark_causal \
  tests.test_modeling.test_dspark_optimizations \
  tests.test_modeling.test_dspine \
  tests.test_modeling.test_dspine_accumulation \
  tests.test_modeling.test_dspine_distributed \
  tests.test_modeling.test_dspine_liger \
  tests.test_modeling.test_dspine_optimizations \
  tests.test_utils.test_dflash_mask \
  tests.test_utils.test_domino_optimizations \
  tests.test_utils.test_dflash_losses \
  tests.test_utils.test_dflash2_fused_head \
  tests.test_algorithms.test_builtin_providers \
  tests.test_scripts.test_gate_orchestration \
  tests.test_runtime.test_checkpoint_resume \
  tests.test_config.test_schema \
  tests.test_config.test_example_draft_config_wiring \
  tests.test_config.test_recipe_readme \
  tests.test_runtime.test_package_architecture \
  tests.test_runtime.test_ref_distributor \
  tests.test_runtime.test_streaming_ref_channel \
  tests.test_training.test_ddp_accumulation -v

The latest config follow-up was checked with:

CUDA_VISIBLE_DEVICES=0 OMP_NUM_THREADS=4 PYTHONPATH=. python -m unittest \
  tests.test_config.test_example_draft_config_wiring \
  tests.test_modeling.test_dflash_attention_direction \
  tests.test_modeling.test_dspine -q

Coverage includes causal isolation, dense/Flex masks, native cached inference, legacy resume compatibility, loss/gradient comparisons, DSpine accumulation and distributed normalization, configuration portability, and template ground truths.

Previously recorded DSpark full-shape optimization validation used synthetic features with length 8192, batch/GPU 2, accumulation 2, 512 anchors, block size 16, and objective chunk size 128. Gradient relative L2 was 0.0078301 and gradient cosine 0.99996935, across 60 parameter tensors (1,126,417,664 elements). BF16 flattening is not bitwise identical. The recorded DSpine isolated projection test had logit/gradient relative L2 0 and gradient cosine 1.0 for its tested synthetic input.

These numerical tests are not downstream task-accuracy results. No fresh end-to-end acceptance-length or task-accuracy benchmark has been run on the latest PR head.

At the description update on 2026-10-08, latest-head lint passed; the full CI unit-test job was still running. A full-suite pass is not claimed here.

Benchmark & Profiling

Previously recorded measurements on NVIDIA RTX PRO5000 72GB Blackwell; these are not fresh measurements of the latest commit and not 32-GPU end-to-end speedup claims:

Measurement Baseline Optimized Scope
DSpark optimizer step, flattened projection + selective cache 3.8564 s 3.2428 s Single GPU; synthetic features; length 8192, batch 2, accumulation 2, 512 anchors, block 16, objective chunk 128; mean of steps 2–3, first step excluded; separate processes
DSpark peak allocated memory 45.956 GiB 52.641 GiB Same comparison; caching trades memory for less recomputation
DSpine vocabulary projection forward 131.714 ms 11.224 ms Isolated BF16 synthetic benchmark, dimensions (128, 15, 4096, 151936)
DSpine vocabulary projection forward + backward 209.265 ms 24.189 ms Same isolated projection benchmark

The short DSpark comparison corresponds to 18.92% higher throughput. A separate length-4096 synthetic profile measured 3.6273 s per DSpark step, including approximately 1.2107 GPU-seconds of vocabulary projection and 1.0150 GPU-seconds of vocabulary-loss/elementwise work; no-kernel time was approximately 0.0074 s. This motivated projection/cache changes, not a claim that producer starvation explained the measured slowdown.

Evidence was recorded in local dspark-optimization-validation-20261007-summary.json, dspark-domino-profile-20261007-summary.json, and dspine-optimization-validation/summary.json. Raw traces, local validation scripts, run records, and checkpoints are intentionally outside the repository. Controlled final-head end-to-end benchmarks and downstream accuracy evaluation remain follow-up work; no universal performance improvement is claimed.

Checklist

Fix DDP accumulation synchronization and expose bucket tuning. Add opt-in fused DFlash CE, Domino Liger kernels and projection caching, balanced consumer dispatch, and no-system Qwen3 template alignment. Include regression tests and training documentation.

Validation: 148 tests passed, 12 GPU tests skipped, 75 subtests passed with CUDA disabled.
Integrate PR sgl-project#917 functionality while preserving DFlash and Domino optimizations. Add DSpine Liger support, flattened vocabulary projection, CE-only accumulation prepass, and balanced consumer dispatch. Include L20N training recipes and regression coverage.

Validation: 150 CPU tests and 125 subtests passed; 18 GPU-dependent tests skipped. Synced files verified against the L20N-7 training checkout.
@jiapingW
jiapingW requested a review from maocheng23 October 8, 2026 06:27
jiapingW added a commit that referenced this pull request Oct 14, 2026
jiapingW added a commit that referenced this pull request Oct 14, 2026
yushengsu-thu added a commit to yushengsu-thu/SpecForge that referenced this pull request Oct 15, 2026
…nce-head skeleton

Adopt the hyperparameters of the published Qwen3-8B dense DSpark run
(jiapingW/Qwen3-8b-dspark-SpecForge): block 16, confidence head off,
0.1 CE + 0.9 L1, loss_decay_gamma 7, AdamW 6e-4 cosine, NO_SHARD DDP,
Liger kernels, 6 epochs, global batch 132 on 6 ranks. Its is_causal,
dspark_flatten_projection, dspark_cache_projection and ddp_bucket_cap_mb
come from the unmerged PR sgl-project#942 and are deliberately not used.

- configs/qwen3-8b-dspark-noconf-b16.json (dense) and
  configs/qwen3-8b-dspark-moe-noconf-b16.json (8 x 4096 top-1 MoE) replace
  configs/qwen3-8b-dspark-moe.json
- recipes renamed to *-noconf-b16-*; tests, README and runbook follow
yushengsu-thu added a commit to yushengsu-thu/SpecForge that referenced this pull request Oct 15, 2026
…ystem prompt

Follow the published jiapingW run now that PR sgl-project#942 is merged: the draft is
configs/qwen3-8b-dspark-dense-1-8-causal-noconf-b16.json (its causal config
with intermediate_size 1536), the yaml sets dspark_flatten_projection,
dspark_cache_projection and ddp_bucket_cap_mb 128, and the corpus cache is
rebuilt without a system prompt.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
yushengsu-thu added a commit to yushengsu-thu/SpecForge that referenced this pull request Oct 15, 2026
… into the MoE 8-expert experiment branch

Brings is_causal (configurable draft attention range/direction), dspark_flatten_projection /
dspark_cache_projection, ddp_bucket_cap_mb, the DDP once-per-window synchronization (sgl-project#958, which
replaces this branch's prepare_micro_step fix; the matching test is dropped), the removal of the
implicit qwen3-instruct system prompt (sgl-project#959), balanced consumer optimizer windows (sgl-project#966) and the
DSpine algorithm. Conflicts in specforge/training/backend.py and controller.py were resolved in
favour of the PR.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
yushengsu-thu added a commit to yushengsu-thu/SpecForge that referenced this pull request Oct 15, 2026
…atten/cache projection, bucket 128, cost-balanced dispatch)

configs/qwen3-8b-dspark-moe-8x1536-top1-causal-noconf-b16.json adds is_causal: true to the 8 x 1536 top-1
MoE config, mirroring configs/qwen3-8b-dspark-causal-noconf-b16.json from PR sgl-project#942. The recipe switches to it
and sets ddp_bucket_cap_mb 128, dspark_flatten_projection / dspark_cache_projection true and
runtime.consumer_dispatch cost_balanced as in the PR's reference recipe. The launcher uses a new dataset
cache directory because PR sgl-project#942 drops the implicit qwen3-instruct system prompt.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
yushengsu-thu added a commit to yushengsu-thu/SpecForge that referenced this pull request Oct 15, 2026
yushengsu-thu added a commit to yushengsu-thu/SpecForge that referenced this pull request Oct 15, 2026
… to exp_read.me

Same base as the dense-1/8 branch (PR sgl-project#942 stack sgl-project#957-sgl-project#963 merged there, DDP-wrapped draft lookup for MoE
metrics, managed-local NCCL port pin); the experiment log is exp_read.me like on dense-1/8.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
yushengsu-thu added a commit to yushengsu-thu/SpecForge that referenced this pull request Oct 15, 2026
…raining) into the MoE 8-expert experiment branch"

This reverts commit 247e6f2, reversing
changes made to eb8d74a.
yushengsu-thu added a commit to yushengsu-thu/SpecForge that referenced this pull request Oct 15, 2026
…yers 1-7 of the sgl-project#942 split), matching the dense-1/8 branch

The combined PR sgl-project#942 merge was reverted in the previous commit; this takes the split stack instead
(sgl-project#957 streaming-read fixes, sgl-project#958 DDP sync once per accumulation window, sgl-project#959 no implicit qwen3-instruct
system prompt, sgl-project#960 is_causal, sgl-project#961 fused DFlash head, sgl-project#962 selective checkpoint contexts, sgl-project#963 shared
flatten_vocab_projection / cache_vocab_projection), so the MoE arm carries exactly the same upstream code
as the dense-1/8 arm. Conflicts in specforge/training/backend.py and controller.py resolved in the stack's
favour.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
yushengsu-thu pushed a commit to yushengsu-thu/SpecForge that referenced this pull request Oct 15, 2026
yushengsu-thu pushed a commit to yushengsu-thu/SpecForge that referenced this pull request Oct 15, 2026
yushengsu-thu pushed a commit to yushengsu-thu/SpecForge that referenced this pull request Oct 15, 2026
yushengsu-thu added a commit to yushengsu-thu/SpecForge that referenced this pull request Oct 15, 2026
… cost-balanced consumer dispatch with the 4-quanta in-flight window

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@jiapingW jiapingW closed this Oct 18, 2026
maocheng23 pushed a commit that referenced this pull request Oct 21, 2026
khazic pushed a commit to khazic/SpecForge_lao that referenced this pull request Oct 22, 2026
jiapingW added a commit that referenced this pull request Oct 22, 2026
khazic pushed a commit to khazic/SpecForge_lao that referenced this pull request Oct 22, 2026
khazic pushed a commit to khazic/SpecForge_lao that referenced this pull request Oct 22, 2026
yushengsu-thu pushed a commit to yushengsu-thu/SpecForge that referenced this pull request Nov 9, 2026
yushengsu-thu pushed a commit to yushengsu-thu/SpecForge that referenced this pull request Nov 9, 2026
yushengsu-thu pushed a commit to yushengsu-thu/SpecForge that referenced this pull request Nov 18, 2026
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.

1 participant