feat(ml): speculative decoding across the tier ladder - #77
Merged
Merged
Conversation
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).
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.
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 newSpeculativeModel—translate()untouched (open/closed at the model boundary; the block loop and stats are the strategy).acceptBlockis 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.
translate, stats consistent.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.