Repository navigation
fix(qwen3-next): server per-sequence (SequenceId) cache isolation - #601
Merged
Merged
Conversation
Follow-up to #588. The offline generate fix used only the model-owned internal fallback cache; the server runs concurrent requests per SequenceId, which qwen3_next did not implement, so concurrent requests shared and corrupted the internal cache. Implement the model-owned seq-id hooks like qwen3_5/mamba/falcon_h1: a shared forward_for_sequence(Option<SequenceId>) via with_or_create_sequence_state, plus forward_with_sequence_id, forward_with_embeddings_and_sequence_id, prepare_sequence_state, release_sequence_state_by_id, sequence_state_layout(model_owned), and snapshot reuse (supports_snapshot_reuse + snapshot/restore_sequence_state). supports_batching stays false (no batched gated-delta forward; the scheduler drives one sequence per forward, still isolated per SequenceId). Validated on mlxcel-server with two interleaved concurrent requests: Paris and 4, both correct and isolated.
be-free-snowboy
pushed a commit
to freestylejs/snowbrain-mlxcel
that referenced
this pull request
Oct 27, 2026
…blup#601) Follow-up to lablup#588. The offline generate fix used only the model-owned internal fallback cache; the server runs concurrent requests per SequenceId, which qwen3_next did not implement, so concurrent requests shared and corrupted the internal cache. Implement the model-owned seq-id hooks like qwen3_5/mamba/falcon_h1: a shared forward_for_sequence(Option<SequenceId>) via with_or_create_sequence_state, plus forward_with_sequence_id, forward_with_embeddings_and_sequence_id, prepare_sequence_state, release_sequence_state_by_id, sequence_state_layout(model_owned), and snapshot reuse (supports_snapshot_reuse + snapshot/restore_sequence_state). supports_batching stays false (no batched gated-delta forward; the scheduler drives one sequence per forward, still isolated per SequenceId). Validated on mlxcel-server with two interleaved concurrent requests: Paris and 4, both correct and isolated.
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
Follow-up to #588. That PR made qwen3_next's offline
mlxcel generatepath correct by giving the model aModelOwnedSequenceState, but it only used theinternalfallback cache slot (the no-SequenceIdforwardpath). The server runs concurrent requests with per-SequenceIdisolation, and qwen3_next did not implement the model-owned sequence-id hooks, so concurrent server requests would share and corrupt the single internal cache and produce incoherent output.Closes #600
Changes
Mirroring the qwen3_5 / mamba / falcon_h1 model-owned pattern, on
Qwen3NextModel'sLanguageModelimpl:forward_for_sequence(input, Option<SequenceId>)routing throughModelOwnedSequenceState::with_or_create_sequence_state(None-> internal fallback with prefill reset, for offline CLI / benchmark;Some(id)-> the scheduler's per-sequence state).forward(delegates withNone),forward_with_sequence_id,forward_with_embeddings_and_sequence_id(text-only, embeddings unused),prepare_sequence_state,release_sequence_state_by_id,sequence_state_layout=model_owned.supports_snapshot_reuse = true,snapshot_sequence_state,restore_sequence_state(Qwen3NextCache::snapshot_into/restore_fromalready handle both the attentionKVCacheand linearGatedDeltaCachevariants).supports_batchingstaysfalse: qwen3_next has no batched gated-delta forward, so batched decode would corrupt the shared cache. The scheduler drives one sequence per forward viaforward_with_sequence_id, still fully isolated perSequenceId.Validation
mlxcel-server -m models/qwen3-next-80b-a3b-instruct-4bit --alias qwen3-next --no-warmup: two concurrent/v1/chat/completionsrequests with different prompts returned "The capital of France is Paris." and "4", both correct. The completions were interleaved (both ~5.7 s, finishing within 121 ms of each other), so per-sequence isolation holds under concurrency.mlxcel generateregression: still coherent ("Paris").cargo test --release --features metal,accelerate qwen3_next: 10 pass.cargo fmt --all -- --check: clean.Out of scope
Batched decode (
supports_batching = true+ a batchedforward_batchedover the gated-delta path) for qwen3_next is a separate, larger performance follow-up.Files