Skip to content

feat(ml): speculative decoding across the tier ladder - #77

Merged
ronaldtse merged 2 commits into
mainfrom
feat/speculative-decode
Sep 11, 2026
Merged

ronaldtse merged 2 commits into
mainfrom
feat/speculative-decode

Conversation

@ronaldtse

Copy link
Copy Markdown
Contributor

Implements the runtime lever from the DeepSeek-V4.1-Flash learnings pass (rababa TODO.impl/01): our shipped tier ladder already contains a drafter/verifier pair, so speculative decode needs no training.

Design. Mechanics on IMFModel (encode, draft, review), policy in a new SpeculativeModeltranslate() untouched (open/closed at the model boundary; the block loop and stats are the strategy). acceptBlock is pure and unit-tested.

Output preservation. The verifier's argmax decides every position, so results equal the verifier's plain-path greedy by construction. On quantized artifacts that can differ from the KV path at near-ties — inside the golden-v1 quality-parity scoping, documented in the module header.

Tests.

  • Acceptance rule: full accept, mid-block correction, position zero, EOS paths, empty block (synthetic logits as data).
  • Tiny-fixture session, drafter == verifier: full acceptance, byte-identical to translate, stats consistent.
  • Opt-in real-pair e2e (SECRYST_SPEC_E2E=1): layerdrop-1.0-int4 → small-2.1-int8, acceptance > 0.9 asserted; passing locally.

Probe numbers behind the tier decision (CPU, golden-v1 rows): acceptance 0.97–1.00, ~8.5–8.9 tokens per verifier pass at K=8.

SpeculativeModel composes a drafter and a verifier IMFModel: the
drafter proposes blockSize tokens, the verifier decides them all in
one full-sequence pass. Greedy verification is output-preserving, so
the result equals the verifier's own greedy regardless of drafter
quality; the drafter only buys speed.

- IMFModel gains the mechanics: encode (shared normalization entry),
  draft (greedy continuation from a forced prefix), review (per-block
  positional argmax verdicts). translate() is unchanged.
- acceptBlock is a pure function: leading matches accepted, the
  verifier's pick returned at the first divergence.
- Tests: pure acceptance rule on synthetic logits, tiny-fixture
  session with drafter == verifier (full acceptance, output identical
  to translate), and an opt-in real-pair e2e
  (SECRYST_SPEC_E2E=1, layerdrop-int4 -> small-2.1-int8; measured
  acceptance > 0.9 on the shipped artifacts).
@ronaldtse
ronaldtse merged commit 53e0201 into main Sep 11, 2026
8 checks passed
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