Repository navigation
fix(speculative): refuse model-owned families in the classic walk - #2535
Merged
Merged
Conversation
The classic draft-model walk drops a rejected draft block by trimming the external KV caches of both models. A family that keeps its sequence state elsewhere (Qwen3-Next's recurrent layers, model-owned caches, families that opt out of padded prefill) keeps the rejected tokens, so later rounds condition on stale positions, and the can_trim_prompt_cache asserts pass trivially on the placeholder caches. SpeculativeGenerator::generate now checks the target and the draft with prompt_lookup_unsupported_reason, the rule Engine::verify_rounds_unsupported already applies, before any state change or forward pass, and returns a new SpeculativeGenerateError naming the refused model and the reason. The generate CLI maps the error into a message that points at plain generation. Tests cover a refused target and a refused draft for both reason branches, asserting no forward ran. Closes #2495
Member
Author
Implementation Review SummaryIntent
Findings AddressedNone needed: no CRITICAL or HIGH findings. Remaining Items
Verification
|
The classic --draft-model path now checks the target against the shared rollback rule before printing "Loading draft model" and loading the checkpoint, so a refused target no longer pays for a full draft load. The in-generate gate stays the authority and also covers the draft. The CLI error text is shared by both sites. SpeculativeGenerator::generate now resets its own caches and counters before the gate, so a reused generator does not keep a previous successful call's tokens after a refused one. The explicit --draft-kind error notes that the classic path refuses targets whose state a cache trim cannot roll back. Tests add a padded-prefill opt-out state (the Gemma 4 / Llama 4 shape) to both refusal tests and a reuse test for the stale-token case. With the in-generate gate removed, the refusal tests fail. Validation: cargo test --profile test-fast -p mlxcel-core --lib speculative:: (178 passed), cargo test --profile test-fast -p mlxcel --bin mlxcel commands::generate (101 passed), clippy -D warnings clean on both packages. Refs #2495
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.
Summary
The classic
--draft-modelwalk drops a rejected draft block by trimming the external KV caches of both models. On a family whose sequence state lives elsewhere (Qwen3-Next's recurrent GDN layers, model-owned caches) the trim rolls nothing back, so later rounds condition on stale positions, and thecan_trim_prompt_cacheasserts pass trivially on the placeholder caches. This takes fix option 1 from the issue: refuse such models instead of trying to rewind them, since GDN state cannot be rewound exactly by a trim.SpeculativeGenerator::generateresets the generator, then checks the target and the draft withprompt_lookup_unsupported_reason(the ruleEngine::verify_rounds_unsupportedalready applies) before any prefill or forward, and now returnsResult<_, SpeculativeGenerateError>. The error hasTargetUnsupportedandDraftUnsupportedvariants carrying the reason string and is re-exported from themlxcelcrate next toSpeculativeGenerator. Resetting first means a reused generator does not keep the tokens of an earlier successful call after a refused one.mlxcel generate --draft-modelrefuses an unsupported target before it loads the draft checkpoint, and maps a refusal fromgenerate(which also covers the draft) through the same error text. The message points at plain generation without--draft-model; it does not suggest--prompt-lookupor the engine drafters, because they refuse the same models. The explicit--draft-kinderror that recommends the classic path now says it refuses such targets.generatemust handle theResult(the type is already deprecated, refactor: run mlxcel generate on the engine and retire CxxGenerator #2176). The existingcan_trim_prompt_cacheand empty-prompt asserts are unchanged.Test plan
cargo test --profile test-fast -p mlxcel-core --lib speculative::: 178 passed.generate_refuses_a_model_owned_target_before_any_forwardandgenerate_refuses_a_model_owned_draft_before_any_forwardloop over all three reasons of the rule (no batched decode, a model-owned layout on a batchable model, no padded prefill), assert the error names the refused model with the rule's reason, and assert neither mock'sforwardran.refused_call_clears_tokens_from_a_previous_successruns a dense call and then a refused call on one generator. The distribution tests nowexpecttheOk, so a refused dense mock cannot pass silently.None,speculative::testsgives 15 passed, 3 failed (the three tests above); restored afterwards. Each refusal loop stops at its first failing state kind, so only that case was observed failing.cargo test --profile test-fast -p mlxcel --bin mlxcel commands::generate: 101 passed, 1 ignored.cargo clippy --profile test-fast -p mlxcel-core --lib --tests -- -D warningsandcargo clippy --profile test-fast -p mlxcel --lib --bin mlxcel --tests -- -D warnings: clean.cargo fmt --all --checkUnverified: no real Qwen3-Next (or other model-owned checkpoint) run through
mlxcel generate --draft-model; the refusal is exercised through mock models at theSpeculativeGenerator::generateentry point, and the CLI's early target check is covered by compilation and code reading only. TheLoadedModelwrapper used by the CLI delegatessupports_batching,sequence_state_layout, andsupports_padded_prefillto the model (read, not executed).Closes #2495