Skip to content

feat(dspine): add an independently registered draft training algorithm - #965

Merged
maocheng23 merged 7 commits into
mainfrom
codex/pr942-09-dspine
Oct 27, 2026
Merged

maocheng23 merged 7 commits into
mainfrom
codex/pr942-09-dspine

Conversation

@jiapingW

@jiapingW jiapingW commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Add DSpine as an independently registered draft-training algorithm, with adjacent injection, persistent transfer codes, candidate refinement, and checkpoint/resume metadata. It reuses DSpark target-feature adapters and the shared DFlash-family attention-mask builder.

Gradient accumulation uses a graph-free CE prepass followed by RNG-preserving replay with one window-level alignment coefficient. A generic trainer callback keeps this behavior in the DSpine strategy. Explicit Liger opt-in uses the shared resolver; native kernels remain the default.

Backbone CE/L1, top-k IDs, and argmax reuse the public eager ce_l1_loss interface. DSpine retains candidate refinement, alignment, and weighted reduction. Equal draft/teacher distributions now produce zero L1 and its zero subgradient, avoiding rounding residuals from the previous exp(log_softmax) path.

Stack: main → #960 → #961 → #963 → #965. One DSpine adaptation commit on #963. Attention semantics, loss fusion, and Domino/DSpark Liger support belong to the parent PRs. The unused checkpoint converter, flattened projection, projection cache, and selective checkpoint contexts are excluded.

Before the loss-sharing refactor, full-stack validation on H20 (Python 3.12, PyTorch 2.14.1+cu130, Liger 0.8.5): 285 tests passed, 3 skipped (FlashAttention 2 unavailable and two Blackwell-only tests). Coverage includes DSpine loss/gradient parity, two-process DDP accumulation, FSDP BF16 replay with FP32 buffers, Liger, checkpoint/resume, shared masks, DFlash2, and fused DFlash/DSpark losses. Black 24.10.0, isort 5.13.2, and git diff --check passed.

This PR provides training and transition scoring. Native serving/verifier integration and full-model throughput or acceptance benchmarks are outside its scope. Adapted from #942, which credits #917; this PR does not close #917.

Latest loss-sharing validation: 43 targeted tests passed on H20. Across 64 ordinary before/after objective and two-update training comparisons (FP32/BF16, vocabularies 32/151936, top-k 3/16, chunking, accumulation 1/2/4), FP32 maximum training-loss difference was 1.91e-6 and gradient relative L2 difference was 1.77e-7; BF16 training loss, gradients, and updated parameters matched exactly. A separate equal-distribution regression checks zero L1 and zero L1 gradient.

@jiapingW jiapingW changed the title [9/11] feat(dspine): add an independently registered draft training algorithm [8/10] feat(dspine): add an independently registered draft training algorithm Oct 14, 2026
@jiapingW
jiapingW force-pushed the codex/pr942-09-dspine branch from b1705cf to b326574 Compare October 14, 2026 09:00
@jiapingW
jiapingW changed the base branch from codex/pr942-08-dspark-optimizations to codex/pr942-07-domino-optimizations October 14, 2026 09:00
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]>
@maocheng23
maocheng23 force-pushed the codex/pr942-09-dspine branch from b326574 to 244e31d Compare October 21, 2026 21:54
@maocheng23 maocheng23 changed the title [8/10] feat(dspine): add an independently registered draft training algorithm [DSpine 1/4] feat(model): add DSpine architecture and checkpoint conversion Oct 21, 2026
@maocheng23 maocheng23 changed the title [DSpine 1/4] feat(model): add DSpine architecture and checkpoint conversion [8/10] feat(dspine): add an independently registered draft training algorithm Oct 21, 2026
@maocheng23
maocheng23 force-pushed the codex/pr942-09-dspine branch from 244e31d to b326574 Compare October 21, 2026 22:10
Comment thread scripts/convert_dspine_checkpoint.py Outdated
@@ -0,0 +1,81 @@
"""Package an independent DSpine reference checkpoint as a SpecForge draft."""

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why do we need this

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It used for continue train but is useless now. I'll delete it.

Comment thread specforge/algorithms/dspine/model.py Outdated
if not self.draft_model.transfer_ready.item():
self.draft_model.initialize_transfer_space(self.lm_head.weight)

def _attention_mask(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The attn_mask should be common util right? Then we should just import it?

Comment thread specforge/algorithms/dspine/model.py Resolved
Comment thread specforge/algorithms/dspine/model.py Resolved
)


def resume_contract(_config, draft_model, training_model):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

builder, contract, provider should be reused from common right

backward/step) plus the grad-accumulation boundary. ``TrainerController`` owns
the lifecycle: fit / evaluate / save_checkpoint. EAGLE3 and DFlash share this
unchanged — only the strategy differs.
``TrainerCore`` owns strategy forward/loss, optional window replay, backend

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do we really need this window replay?

@jiapingW
jiapingW force-pushed the codex/pr942-07-domino-optimizations branch from f8b7482 to 554a0f1 Compare October 22, 2026 01:25
@jiapingW
jiapingW requested a review from zyksir as a code owner October 22, 2026 01:25
@jiapingW
jiapingW force-pushed the codex/pr942-09-dspine branch from b326574 to dbacebb Compare October 22, 2026 03:03
@jiapingW jiapingW changed the title [8/10] feat(dspine): add an independently registered draft training algorithm feat(dspine): add an independently registered draft training algorithm Oct 22, 2026
@jiapingW
jiapingW changed the base branch from codex/pr942-07-domino-optimizations to codex/pr942-02-ddp-accumulation October 22, 2026 03:03
Base automatically changed from codex/pr942-02-ddp-accumulation to main October 22, 2026 03:18
@jiapingW
jiapingW force-pushed the codex/pr942-09-dspine branch from ba3e31d to 0cce12b Compare October 22, 2026 05:46
@jiapingW
jiapingW changed the base branch from main to codex/pr942-07-domino-optimizations October 22, 2026 05:47
@jiapingW
jiapingW force-pushed the codex/pr942-07-domino-optimizations branch from 8c0a361 to c0fef19 Compare October 22, 2026 06:03
@jiapingW
jiapingW force-pushed the codex/pr942-09-dspine branch from 0cce12b to a61355a Compare October 22, 2026 06:03
@jiapingW
jiapingW force-pushed the codex/pr942-09-dspine branch 2 times, most recently from f14cc77 to addf84e Compare October 22, 2026 06:38
@jiapingW
jiapingW force-pushed the codex/pr942-09-dspine branch from addf84e to 7b5493b Compare October 22, 2026 06:52
Base automatically changed from codex/pr942-07-domino-optimizations to main October 26, 2026 08:06
Comment thread specforge/algorithms/dspine/model.py Outdated
target_candidates = target_candidates / mass.unsqueeze(-1).clamp_min(1e-30)
covered = candidates == labels.unsqueeze(-1)
refined_ce = -(refined_log_probabilities * covered).sum(dim=-1)
refined_l1 = (

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could we reuse ce_l1_loss for refinement? Student and teacher probabilities currently follow different numerical paths, so identical candidate logits can produce rounding residuals and nonzero L1 gradients. Using scores and gathered teacher logits gives both sides the same softmax computation. Please preserve the candidate-mass gate and missing-label CE mask.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

+ alignment_scale * alignment
)
count = supervised.sum().float()
ratios = {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit, add "acc"?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I have updated it.

)
return self._backward_step(out)

self._prepared_steps.append(out)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The replay requirement makes sense for DSpine, but this adds a second execution mode and additional window state to train_step. Could we isolate the preparation/replay logic in a helper and keep the immediate path straightforward? Please also reject switching modes within an accumulation window in both directions; currently only replay → immediate is guarded. Backward and optimizer stepping should remain owned by the controller

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Right, now default uses the immediate path and the replay is used when out.replay_loss is not None.

@maocheng23
maocheng23 merged commit eaa6b03 into main Oct 27, 2026
6 checks passed
@maocheng23
maocheng23 deleted the codex/pr942-09-dspine branch October 27, 2026 23:06
yushengsu-thu added a commit to yushengsu-thu/SpecForge that referenced this pull request Oct 28, 2026
Resolves controller.py against sgl-project#965's window replay: TrainerCore keeps
both _prepared_steps and the step hooks.
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