Repository navigation
fix(speculative): hybrid draft finalize, window/logits checks, MTP round reset (#72 follow-ups) - #73
Merged
Merged
Conversation
…P round reset - SpeculativeTokenIterator finalize now rewinds a hybrid draft cache: snapshot its recurrent state at the round start, then restore and re-feed the emitted tokens, as the main cache already does. - Reject a hybrid draft whose sliding window can't hold a round's rewind (maxSize - keep < numDraftTokens + 1) at init instead of trapping mid-round. - Reject a main model that keeps fewer logit rows than a verify pass reads (FalconH1 num_logits_to_keep) via a new TrailingLogitsLanguageModel protocol. - MTPTokenIterator resets its committed count and round start before each round, so a round that returns before verifying commits nothing. - CI: drop the Gemma4StabilizationTests gate, which selected no tests. - Tests: MTP finalize after partial + fallback rounds, deep lookahead with MTP cache trims, non-hybrid finalize, empty round, generateMTP stop token; draft finalize and second-finalize checks; seeded Gemma4 draft perturbation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Keep SpeculativeTokenIterator's doc comment on the iterator: move SpeculativeDecodingError above it. - Enforce the hybrid-draft window bound only for numDraftTokens >= 2; one draft never rewinds the draft cache. - Tests: assert the draft position exactly after finalize (min(before, emitted)), drop the loose Gemma4 offset disjunct, and add a deterministic partly accepted round (0 < accepted < numDraftTokens) with lookahead. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Member
Author
|
Pushed 06e5c07 addressing the review: doc comment kept on 🤖 Generated with Claude Code |
1 of 4 tasks
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.
Proposed changes
Follow-ups from the review of #72 (the 12 lows). They are grouped by what changes.
Fixes
SpeculativeTokenIterator.finalizeGenerationrewound the draft cache only with a per-layer trim. That can't take unemitted drafts out of a recurrent (Mamba) layer. The draft's recurrent state anddraftYare now snapshotted at round start; finalize restores them and re-feeds the emitted tokens, as the main cache already does.numDraftTokens + 1single-token writes. A wrappedRotatingKVCachecan only give backmaxSize - keeprows, so a smallmaxKVSizeused to trap at the "Speculative draft rewind was partial" precondition mid-generation. Init now throws instead. The bound is tight: withnumDraftTokens3,maxKVSize7 traps when the check is loosened by one, and 8 runs.MTPTokenIteratornow resetscommittedPendingTokenCountandroundStartbefore each round. Before, a verify round that returned early (emptycallMTP) left the previous round's count, and finalize then rewound tokens that had already been emitted.num_logits_to_keep. Adds aTrailingLogitsLanguageModelprotocol in MLXLMCommon, which FalconH1 conforms to.SpeculativeTokenIteratorrejects a main model that returns fewer logit rows than a verify pass reads (numDraftTokens + 1). FalconH1 defaultsnum_logits_to_keepto 1.Gemma4StabilizationTestsgate. No such suite has ever existed, so the gate selected 0 tests.Gemma4Testsstill gates the PLE math.Tests (
MTPSpeculativeDecodingTests,Gemma4Tests,FalconH1Tests)CountingDraftingModelthat exposes MTP caches.full_attention_interval1).generateMTPstops on an EOS token mid-round; the loop's finalize leaves the caller's cache holding only the emitted tokens.processedTokenCounts unchanged; main lookahead ≥ 2 (accepted ≥ 2) must occur.withRandomState, and the test asserts draft offsets and the draft timeline.Verification
swift test --no-parallel: all new tests pass.AllowedToolOutputRouterTests(ordinaryTagLikeTextRemainsAResponse,nearProtocolMarkersSuppressWithoutStrippingOrdinaryTags). They fail the same way on main 9d5041a and are unrelated to this PR.Checklist
pre-commit run --all-filesto format my code / installed pre-commit prior to committing changesAI usage
accurately describes the code changes.
🤖 Generated with Claude Code