Repository navigation
feat(dspine): add an independently registered draft training algorithm - #965
Conversation
b1705cf to
b326574
Compare
… cost-balanced consumer dispatch with the 4-quanta in-flight window Co-Authored-By: Claude Fable 5.1 <[email protected]>
b326574 to
244e31d
Compare
244e31d to
b326574
Compare
| @@ -0,0 +1,81 @@ | |||
| """Package an independent DSpine reference checkpoint as a SpecForge draft.""" | |||
There was a problem hiding this comment.
It used for continue train but is useless now. I'll delete it.
| if not self.draft_model.transfer_ready.item(): | ||
| self.draft_model.initialize_transfer_space(self.lm_head.weight) | ||
|
|
||
| def _attention_mask( |
There was a problem hiding this comment.
The attn_mask should be common util right? Then we should just import it?
| ) | ||
|
|
||
|
|
||
| def resume_contract(_config, draft_model, training_model): |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Do we really need this window replay?
f8b7482 to
554a0f1
Compare
b326574 to
dbacebb
Compare
ba3e31d to
0cce12b
Compare
8c0a361 to
c0fef19
Compare
0cce12b to
a61355a
Compare
f14cc77 to
addf84e
Compare
addf84e to
7b5493b
Compare
| 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 = ( |
There was a problem hiding this comment.
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.
| + alignment_scale * alignment | ||
| ) | ||
| count = supervised.sum().float() | ||
| ratios = { |
There was a problem hiding this comment.
I have updated it.
| ) | ||
| return self._backward_step(out) | ||
|
|
||
| self._prepared_steps.append(out) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Right, now default uses the immediate path and the replay is used when out.replay_loss is not None.
Resolves controller.py against sgl-project#965's window replay: TrainerCore keeps both _prepared_steps and the step hooks.
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_lossinterface. 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 previousexp(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 --checkpassed.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.