Repository navigation
Description
Summary
Follow-up to #588. That PR fixed qwen3_next's offline mlxcel generate path by making the model own its heterogeneous attention + gated-delta cache in ModelOwnedSequenceState, but it only used the internal fallback cache slot (the forward / no-SequenceId path). The server runs concurrent requests with per-SequenceId state isolation, and qwen3_next did not implement the model-owned sequence-id hooks. Concurrent server requests would share (and corrupt) the single internal cache, producing incoherent output.
What was implemented
Mirroring the qwen3_5 / mamba / falcon_h1 model-owned pattern, on Qwen3NextModel's LanguageModel impl:
- A shared inherent
forward_for_sequence(input, Option<SequenceId>)that routes throughModelOwnedSequenceState::with_or_create_sequence_state(None-> internal fallback with prefill reset for offline CLI;Some(id)-> the scheduler's per-sequence state). - Trait overrides:
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. - Full snapshot reuse:
supports_snapshot_reuse = true,snapshot_sequence_state,restore_sequence_state(the existingQwen3NextCache::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 per SequenceId (the mamba / falcon_h1 model, not qwen3_5's batched + paged decode). Full batched decode remains a future perf item.
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: "What is the capital of France?" -> "The capital of France is Paris." and "What is 2 plus 2?" -> "4". Both correct, and the completions were interleaved (both ~5.7s, finishing within 121ms of each other), so per-sequence isolation holds under concurrency. Offline mlxcel generate regression stays coherent; qwen3_next unit tests pass; fmt clean.
Files
- src/models/qwen3_next.rs
Note
Batched decode (supports_batching = true + a batched forward_batched over the gated-delta path) for qwen3_next is a separate, larger performance follow-up and is intentionally out of scope here.
Activity