Skip to content

fix(qwen3-next): server per-sequence (SequenceId) cache isolation - #601

Merged
inureyes merged 1 commit into
mainfrom
fix/600-qwen3-next-server-seqid
Jul 2, 2026
Merged

inureyes merged 1 commit into
mainfrom
fix/600-qwen3-next-server-seqid

Conversation

@inureyes

@inureyes inureyes commented Jul 2, 2026

Copy link
Copy Markdown
Member

Summary

Follow-up to #588. That PR made qwen3_next's offline mlxcel generate path correct by giving the model a ModelOwnedSequenceState, but it only used the internal fallback cache slot (the no-SequenceId forward path). The server runs concurrent requests with per-SequenceId isolation, 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's LanguageModel impl:

  • A shared inherent forward_for_sequence(input, Option<SequenceId>) routing through ModelOwnedSequenceState::with_or_create_sequence_state (None -> internal fallback with prefill reset, for offline CLI / benchmark; Some(id) -> the scheduler's per-sequence state).
  • Trait overrides: forward (delegates with None), 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.
  • Snapshot reuse: supports_snapshot_reuse = true, snapshot_sequence_state, restore_sequence_state (Qwen3NextCache::snapshot_into / restore_from already handle both the attention KVCache and linear GatedDeltaCache variants).
  • supports_batching stays false: qwen3_next has no batched gated-delta forward, so batched decode would corrupt the shared cache. The scheduler drives one sequence per forward via forward_with_sequence_id, still fully isolated per SequenceId.

Validation

  • mlxcel-server -m models/qwen3-next-80b-a3b-instruct-4bit --alias qwen3-next --no-warmup: two concurrent /v1/chat/completions requests 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.
  • Offline mlxcel generate regression: 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 batched forward_batched over the gated-delta path) for qwen3_next is a separate, larger performance follow-up.

Files

  • src/models/qwen3_next.rs

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.
@inureyes inureyes added the status:done Completed label Jul 2, 2026
@inureyes
inureyes merged commit 89fb493 into main Jul 2, 2026
4 checks passed
@inureyes
inureyes deleted the fix/600-qwen3-next-server-seqid branch July 2, 2026 00:31
@inureyes inureyes self-assigned this Aug 31, 2026
@inureyes inureyes added type:bug Bug fixes, error corrections, or issue resolutions priority:medium Medium priority labels Sep 7, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority:medium Medium priority status:done Completed type:bug Bug fixes, error corrections, or issue resolutions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(qwen3-next): server per-sequence (SequenceId) cache isolation

1 participant