fix(mlx_lm.server): fail fast when --draft-model set with non-trimmable cache#1455
Open
tejkas wants to merge 1 commit into
Open
fix(mlx_lm.server): fail fast when --draft-model set with non-trimmable cache#1455tejkas wants to merge 1 commit into
tejkas wants to merge 1 commit into
Conversation
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
Fixes #1446.
mlx_lm.server with --draft-model accepts startup and /v1/models, then crashes during the first completion with
This issue would affect hybrid-attention models such as
qwen3_5_moewhich useArraysCacheon their linear-attention layers, which cannot be trimmed. Speculative decoding needs trimming to roll back rejected draft tokens.Since the user provides
--draft-modelexplicitly, opting to fail fast here makes more sense (as opposed to say, silently disabling speculation). There are two other options named in the issue which don't strike me as particularly feasible at this time:use/select a trimmable cache for this path: The model's linear attention layer requires recurrent state https://sebastianraschka.com/llm-architecture-gallery/hybrid-attention/ which cannot be simply replaced by a trimmable cache structure.support trimming the cache type used by these Qwen hybrid-attention models: Similar to above, a cache for linear attention models cannot be easily trimmed (it would probably require checkpointing of the recurrent state, resulting in memory blowup).Implementation
Built the check into a small helper
_ensure_speculation_supported(prompt_cache, model_path)with related unit tests using a mock cache (optionally, could inline the check but this seemed more testable).Tests
Added 3 unit tests (ensure check rejects non-trimmable caches, allows trimmable, and that the error message names the cache type in question). No model download.
Happy path cases remain covered by existing
TestServerandTestServerWithDraftModeltest classes.Verified Locally
With this fix, the server now fails at startup, before serving any request, instead of crashing mid-generation.