Skip to content

fix: opt Qwen3-Next out of no-ID chunked prefill - #2295

Merged
inureyes merged 3 commits into
mainfrom
fix/issue-2285-qwen3-next-chunking
Oct 13, 2026
Merged

inureyes merged 3 commits into
mainfrom
fix/issue-2285-qwen3-next-chunking

Conversation

@inureyes

@inureyes inureyes commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Opt Qwen3-Next out of chunked prefill for cache-less no-sequence-ID callers, whose multi-token forwards reset the model-owned GatedDelta and KV state.
  • Add a one-layer GatedDelta model loaded through Qwen3NextModel::from_weights that proves independent no-ID prompts reset to offset 3 while a stable sequence ID continues to offset 5.

Validation

  • The CUDA mlxcel and mlxcel-surgery library test graph builds successfully, and qwen3_next_loaded_model_chunking_contract_is_safe passes 1/1 under the GPU lock.
  • Rust formatting and diff checks pass; independent implementation review reports no findings.
  • The repository contract gate passes, including 123 Python tests and 49 WebUI contract tests. An initial timing-sensitive GPU guard sample missed a short foreign process during concurrent native compilation; its isolated retry and the broad contract rerun passed without code changes.

Current DirectEngine prefill keeps one stable sequence ID across its pieces, so its state handling is safe. PrefillCaps consumes this model-wide false capability for every token-ID prefill plan, however, so DirectEngine and cache-less callers both build one whole-prompt graph instead of bounded chunks and can use more transient memory for long prompts.

Closes #2285

Qwen3-Next resets its model-owned GatedDelta and KV state when a multi-token forward carries no sequence ID. Advertise the conservative single-pass policy so cache-less callers cannot silently discard earlier prompt pieces while preserving independent-prompt resets and stable sequence-ID continuation.

Add a one-layer GatedDelta model loaded from deterministic nonzero weights. The regression forces both paths and verifies offset 3 after two independent no-ID prompts and offset 5 after two forwards with one sequence ID. The CUDA library test graph builds, the focused GPU test passes, and formatting and diff checks pass.

Refs #2285
@inureyes inureyes added status:review Under review type:bug Bug fixes, error corrections, or issue resolutions priority:medium Medium priority area:models Model architectures, weights, loading, metadata area:inference Generation, sampling, decoding (incl. speculative, DRY) labels Oct 13, 2026
`PrefillCaps` consumes the model-wide chunking capability for every token-ID prefill plan. Clarify that DirectEngine's stable sequence ID makes its state handling safe while the false capability still forces DirectEngine and cache-less callers to build one whole-prompt graph.

This changes only the source comment, PR documentation, and bilingual reports. The prior focused GPU test and contract results remain applicable.

Refs #2285
@inureyes
inureyes merged commit 90d78fc into main Oct 13, 2026
27 checks passed
@inureyes inureyes added status:done Completed and removed status:review Under review labels Oct 13, 2026
@inureyes
inureyes deleted the fix/issue-2285-qwen3-next-chunking branch October 13, 2026 15:47
inureyes added a commit that referenced this pull request Oct 20, 2026
…2493)

* fix(models): continue Qwen3-Next cache across multi-token forwards

Qwen3NextModel::forward_for_sequence reset the model-owned GatedDelta and KV state on every multi-token forward that carried no sequence id, so one multi-token forward behind a populated cache ran from an empty state while the same tokens forwarded one at a time behind it continued the cache. This is the shape speculative-decode verification uses, and teacher-forced traces on Qwen3-Next-80B-A3B-4bit showed width 5 behind 512 tokens of context reading perplexity 980 while widths 1 and 256 read 27 and 24.

Drop the reset so a no-ID multi-token forward continues the fallback cache, matching the Qwen3.5 model, and remove the no-ID chunked-prefill opt-out #2295 added while the reset existed. Callers that start a new prompt reset through reset_runtime_state (the logit-trace and perplexity harnesses already do); server requests isolate per sequence through SequenceId.

Validated with a synthetic eight-layer Qwen3-Next test that compares one T=5 forward against five T=1 forwards from the same post-prefill state (fails on main, passes here), and with fixed-versus-reverted traces on the real checkpoint: width 5 gives ppl 18.68 (was 980.26) and widths 1 and 256 are unchanged at 27.140 and 24.059.

Refs #2463

* docs(models): fix orphaned qwen3_next comment and in_proj_qkvz formula

Convert the issue-2463 chunked-prefill decision note orphaned onto `eos_token_ids` when the `supports_chunked_prefill` override was deleted from a rustdoc comment into a plain `//` comment, and correct the `hybrid_weights` fixture comment's `in_proj_qkvz` width formula to `[2*nk*dk + 2*nv*dv, hidden]` (q, k, v, z per k-head group, 48 rows for the fixture), matching the `[48, 16]` tensor. The docs sweep found no stale chunked-prefill claim to update. Validation: cargo fmt --all -- --check, cargo clippy -p mlxcel --profile test-fast --features cuda -- -D warnings, and the 16 qwen3_next lib tests pass under gpu-lock with MLX_ENABLE_TF32=0 and --test-threads=1.

Refs #2463

* docs: add PR 2493 technical report
@inureyes inureyes added this to the 0.8 milestone Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:inference Generation, sampling, decoding (incl. speculative, DRY) area:models Model architectures, weights, loading, metadata 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): correct the no-ID chunked prefill contract

1 participant