Skip to content

feat(models): batch recurrent decode across sequence state - #2685

Merged
inureyes merged 7 commits into
mainfrom
feature/issue-2573-batch-recurrent-decode
Oct 27, 2026
Merged

inureyes merged 7 commits into
mainfrom
feature/issue-2573-batch-recurrent-decode

Conversation

@inureyes

@inureyes inureyes commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Mamba1/Falcon-Mamba, Jamba, LFM2/LFM2-MoE, RecurrentGemma and RWKV7 now decode independent sequence state in native batches. LFM2-VL delegates to its tower, including atomic rejection of non-ID multi-row calls. Scalar routing, mixed-state fallback, recurrent ownership and paged attention accounting are preserved.

Four real checkpoints retain byte-identical B1 greedy text and all 256 recorded B1 trace rows. Metal concurrency-four aggregate throughput improves 2.22–3.27x; B4 has zero decided-position disagreements. LFM2-VL matches all three full solo/concurrent messages. RecurrentGemma and RWKV7 have synthetic coverage only.

Results, raw traces, serving ladders, exact VLM inputs and runtime hashes are recorded in the benchmark summary, with bilingual reports under TECHNICAL_REPORTS/2685-*. A VLM replay runner makes the workload reproducible. The remaining class D clamp reasons are documented.

Implementation/security reviews, focused Metal regressions, typecheck, scoped clippy and formatting pass. Benchmark tools pass 18 CPU tests and evidence hashes are verified. After integration with #2686, the complete workspace suite passes 14,251 tests with zero failures and 457 ignored; full workspace Clippy and formatting also pass. Two Metal tests needed a shared default-device lock to avoid parallel CPU-test interference; production runtime is unchanged. Measurements identify their actual source revisions separately from later wrapper/test/documentation changes.

Closes #2573

@inureyes inureyes added status:review Under review type:performance Performance improvements priority:medium Medium priority area:models Model architectures, weights, loading, metadata area:inference Generation, sampling, decoding (incl. speculative, DRY) modeltype:text Text-only language model modeltype:vlm Vision-language model arch:hybrid Hybrid attention stack (linear/sliding/full or attention+SSM interleave) arch:ssm State-space / recurrent model (Mamba, RWKV) labels Oct 27, 2026
@inureyes

Copy link
Copy Markdown
Member Author

PR Finalization Update

  • Tests: strengthened the LFM2-VL regression to prove a rejected multi-row non-ID call leaves model-owned text state unchanged; the focused Metal test passes.
  • Documentation: reviewed the existing continuous-batching guide; it already covers all five recurrent families and LFM2-VL delegation, so no additional documentation change was needed.
  • Format: cargo fmt --all -- --check and git diff --check pass.

Broader real-checkpoint, serving, and VLM replay evidence remains in the parent epic verification pass. The PR remains draft for that final evidence and dependency ordering.

inureyes added a commit that referenced this pull request Oct 27, 2026
Qwen3-Next, Qwen3.5, Bailing MoE Linear, Kimi Linear and Kimi K3 now batch decode across isolated recurrent sequence state. Qwen3.5 and Kimi K3 VLM wrappers delegate to their towers. Qwen3.5 paged accounting counts attention KV storage and excludes recurrent GDN slots, avoiding fictitious page reservations.

All six measured configurations retain byte-identical B1 greedy text and all 256 recorded B1 trace rows. Metal serving aggregate tokens/s at concurrency 1/2/4:

| Checkpoint / storage | Baseline | Candidate | B4 decided disagreement |
|---|---|---|---|
| Qwen3-Next 80B A3B | 69.7 / 66.6 / 80.6 | 71.1 / 103.3 / 148.1 | 0/126 |
| Ring-mini Linear | 140.0 / 179.2 / 177.8 | 159.6 / 298.8 / 460.8 | 1/118 |
| Qwen3.5 4B / default | 109.5 / 188.8 / 168.6 | 112.6 / 225.3 / 357.9 | 0/117 |
| Qwen3.5 35B A3B / default | 87.4 / 138.8 / 122.5 | 89.3 / 165.7 / 262.9 | 0/113 |
| Qwen3.5 4B / dense | 110.9 / 191.8 / 170.3 | 112.7 / 225.3 / 361.8 | 0/117 |
| Qwen3.5 35B A3B / dense | 88.7 / 146.2 / 123.9 | 89.5 / 166.5 / 262.9 | 0/113 |

Ring-mini has 22/256 total top-1 disagreements, including one reference gap of 2.312; corpus PPL changes 58.3837→57.1854 (-2.052%). Disabling fused MoE in a separate diagnostic removes decided disagreements (0/114), consistent with width-dependent quantized-kernel arithmetic; production numbers remain unchanged. This is not full numerical equivalence. Qwen3.5 image B1 matches baseline exactly; B4 has 2/64 top-1 and 0/15 decided disagreements. Free-form VLM solo/concurrent messages match 2/3 in both baseline and candidate: counting-prompt reasoning drifts in both versions, while solo messages across revisions match 3/3. Kimi Linear/K3 remain synthetic-only.

Implementation/security review, seven focused GPU tests, fourteen coverage checks, scoped clippy and formatting pass. Release build and all serving ladders pass. Raw evidence, runtime hashes, reproducible inputs and bilingual reports are recorded under `benchmarks/epic-2574/` and `TECHNICAL_REPORTS/2686-*`. Final combined workspace verification follows integration with #2685 under epic #2574.

Closes #2572
Stack per-sequence recurrent caches for native batched decode in Mamba1, Jamba, LFM2, RecurrentGemma, and RWKV7 while preserving scalar routing and mixed-state fallbacks.

Synchronize paged shadow lengths, delegate LFM2-VL state ownership, and cover isolation, transition, rotating-window, MoE routing, and wrapper contracts.

Refs #2573
Delegate the wrapper's non-ID batched entry to the LFM2 text tower so multi-row calls fail closed instead of sharing fallback recurrent state.

Cover the rejected call followed by an identified batch to prove prepared state remains usable.

Refs #2573
Compare the identified batched logits after a rejected non-ID wrapper call with a fresh text-tower reference so the regression proves validation occurs before model-owned state mutation.

Validation:
- cargo test --profile test-fast --features metal,accelerate lfm2_vl_delegates_native_batching_contract_to_text_tower -- --nocapture (1 passed)
- cargo fmt --all -- --check
- git diff --check

Refs #2573
Archive four baseline/candidate checkpoint pairs and exact LFM2-VL requests, responses, image and runtime provenance. Add a reproducible VLM runner, bilingual implementation reports and the aggregate comparison table; explicitly retain pending integrated validation and unmeasured model limitations.

Eight CPU replay tests and binary asset checks pass. Raw command output is preserved byte-for-byte, including trailing blank lines. Refs #2573 and #2574.
Document the class D clamp set for epic #2574 and explain each remaining single-row capability override. Replace stale NemotronNAS, LongCat and OCR state descriptions with their current cache or request-boundary constraints; distinguish Gemma 4's loaded-model fallback from batching-capable runtimes.

Only comments and documentation change. Formatting and diff checks pass. Refs #2574.
Hold the shared MLX default-device lock before checking Metal availability and through each switch gate/up graph. Parallel CPU-device tests can otherwise make the kernel predicate change between the initial check and dispatch, producing intermittent false declines.

Focused Metal tests pass: two passed and one real-checkpoint case remained ignored. Refs #2573 and #2574.
Combine 23 measured configurations across 21 checkpoints and preserve all numerical limitations. Record the passing integrated workspace gate, Clippy, reproducible benchmark tests and 792 verified raw artifacts after resolving the test-only Metal device race.

The full suite passes 14,251 tests with zero failures and 457 ignored. Measured runtime provenance remains unchanged. Refs #2574, #2572 and #2573.
@inureyes
inureyes force-pushed the feature/issue-2573-batch-recurrent-decode branch from 109e5e9 to c6464a2 Compare October 27, 2026 12:30
@inureyes inureyes added status:done Completed and removed status:review Under review labels Oct 27, 2026
@inureyes
inureyes marked this pull request as ready for review October 27, 2026 12:31
@inureyes
inureyes merged commit 6759cea into main Oct 27, 2026
31 checks passed
@inureyes
inureyes deleted the feature/issue-2573-batch-recurrent-decode branch October 27, 2026 12:32
@inureyes inureyes mentioned this pull request Nov 22, 2026
5 tasks done
@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

arch:hybrid Hybrid attention stack (linear/sliding/full or attention+SSM interleave) arch:ssm State-space / recurrent model (Mamba, RWKV) area:inference Generation, sampling, decoding (incl. speculative, DRY) area:models Model architectures, weights, loading, metadata modeltype:text Text-only language model modeltype:vlm Vision-language model priority:medium Medium priority status:done Completed type:performance Performance improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(models): batched decode for Mamba1, Jamba, LFM2, RG-LRU and RWKV7

1 participant