Skip to content

update(models): batch model-owned attention decode - #2673

Merged
inureyes merged 6 commits into
mainfrom
update/issue-2570-model-owned-batching
Oct 27, 2026
Merged

inureyes merged 6 commits into
mainfrom
update/issue-2570-model-owned-batching

Conversation

@inureyes

@inureyes inureyes commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

AFMoE, DeepSeek-V4, IQuestLoopCoder and Inkling now decode batches with isolated model-owned state; Inkling VLM delegates text decode. Validation rejects malformed or duplicate/missing sequence identities before mutation, and paged shadow accounting follows real cache lengths. Scalar routing remains unchanged.

Review preserved AFMoE's complete fused expert path per row within otherwise-batched layers, removing the initial measured perplexity increase. The trace tool gains an explicit scalar-reference mode because older default batched dispatch dropped sequence IDs; corrected baseline B1 traces and greedy outputs match all three measured checkpoints exactly.

Checkpoint Baseline / final C4 aggregate tok/s B4 top-1 mismatch Decided mismatch
Trinity Nano 98.9 / 202.3 91/256 0/16
Inkling 0.6B 177.4 / 340.9 0/256 0/96
DeepSeek-V4 Flash 6.4 / 15.4 5/256 0/129

Measured on M3 Ultra 512 GB. Trinity B4 perplexity changes -0.726%; substantial undecided-token differences and pre-existing degenerate baseline output prevent a general quality claim. IQuestLoopCoder and Inkling image paths have synthetic/delegation coverage only. Bilingual reports and JSON preserve methods, ladders and limitations.

Focused isolation, multistep, delegation, malformed-input and accounting tests, the final 12-test coverage contract, formatting and targeted clippy passed. Full workspace verification follows at epic integration.

Closes #2570. Part of #2574.

@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:dense Dense transformer decoder arch:moe Sparse mixture-of-experts decoder labels Oct 27, 2026
@inureyes

Copy link
Copy Markdown
Member Author

Security/performance review update:

  • HIGH — fixed: AFMoE, DeepSeek V4, IQuestLoopCoder, Inkling, and Inkling VLM did not synchronize model-owned cache growth into paged shadow state. This left cache-memory accounting and admission at zero for these sequences. Each text family now reports per-layer lengths; V4 uses monotonic offsets because pooled state grows beyond its bounded local window, and the VLM delegates to Inkling text.
  • MEDIUM — fixed: per-row results were joined through left-deep pairwise concatenation chains, producing quadratic intermediate-copy traffic as batch width increased. The affected attention, convolution, decode, and fallback joins now use one n-ary concatenation.
  • Added paged-shadow regression coverage to the shared model-owned multistep harness.

Validation: focused compilation and formatting pass; 5 model/VLM multistep tests, Inkling absent-tail parity, 7 model-owned state tests, and batching classification pass.

Review fix: fb194e37. Real-checkpoint metrics remain with the coordinated epic gate.

@inureyes
inureyes force-pushed the update/issue-2570-model-owned-batching branch from fb194e3 to 4d07635 Compare October 27, 2026 07:44
Run shared projections and feed-forward blocks across AFMoE, DeepSeek V4, IQuestLoopCoder and Inkling rows while keeping each sequence's KV, pooling and convolution state isolated. Delegate Inkling VLM text decode and retain the exact single-row path.

Add multistep isolation, cache admission and pooling-boundary tests, and pin the native coverage classifications. Affected model regressions pass; real-checkpoint measurements remain part of the epic integration gate.

Refs #2570
Validate tensor, cache, and ID cardinality before dispatch and preflight duplicate or missing prepared IDs before per-row fallbacks, preventing malformed calls from advancing only part of a live batch. Preserve B=1 lazy sequence creation and add cross-family atomicity coverage.

Validation: five model-owned multistep tests, mixed Inkling convolution state, coverage classification, shared state tests, clippy, and formatting pass.

Refs #2570
Mirror AFMoE, DeepSeek V4, IQuestLoopCoder, and Inkling cache lengths into paged shadow state so memory accounting and admission observe model-owned allocations. DeepSeek V4 uses monotonic offsets because its pooled state grows beyond the bounded local window, and Inkling VLM delegates the synchronization contract.

Join per-row attention, convolution, and fallback outputs with n-ary concatenation to avoid left-deep copy chains as batch width grows. Add paged-shadow coverage to the shared multistep harness.

Validation: focused five-family multistep, Inkling absent-tail, model-owned state, and batching-classification tests pass; formatting and focused compilation pass.

Refs #2570
Add an explicit B=1 scalar-reference route for logit traces so older model implementations decode from the same sequence-ID state populated during prefill. Reject multi-row and image-arm use to keep existing batched measurements unchanged, and document the diagnostic switch.

Validation:
- cargo test --example logit_trace --features metal,accelerate --no-run
- MLXCEL_DEVICE=cpu target/debug/examples/logit_trace-67558ff49447647f tests::scalar_reference_requires_one_text_batch_row --exact
- cargo clippy --example logit_trace --features metal,accelerate -- -D warnings
- cargo fmt --check
- python3 scripts/ci/check_env_var_docs.py

Refs #2570
@inureyes
inureyes force-pushed the update/issue-2570-model-owned-batching branch from 15bacea to 1460ca0 Compare October 27, 2026 08:31
Probe the same full-fused expert path used by scalar decode before dispatching an AFMoE native batch. Compatible quantized experts run that complete scalar MoE path per row, while disabled or unsupported configurations retain the existing whole-batch expert graph; attention and surrounding layers remain batched.

Add a float-expert regression that pins both the explicit gate and unsupported-kernel fallback, and document the mixed native/per-row behavior.

Validation:
- cargo test --lib --features metal,accelerate --no-run
- target/debug/deps/mlxcel-f1ed1a8cbe111893 models::afmoe::tests::small_float_moe_keeps_the_native_batched_expert_path --exact --nocapture
- target/debug/deps/mlxcel-f1ed1a8cbe111893 models::afmoe::tests::model_owned_batched_multistep --exact --nocapture
- cargo clippy --lib --tests --features metal,accelerate -- -D warnings
- cargo fmt --check

Refs #2570
Record release measurements, corrected scalar-reference trace methodology, and the fused-expert quality fix for Trinity. Preserve full comparisons and disclose unmeasured paths and pre-existing checkpoint quality limitations.

Refs #2570, #2574.
@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 08:53
@inureyes
inureyes merged commit 122f2e5 into main Oct 27, 2026
31 checks passed
@inureyes
inureyes deleted the update/issue-2570-model-owned-batching branch October 27, 2026 08:57
inureyes added a commit that referenced this pull request Nov 24, 2026
…3392)

## Summary

Inkling 2 now runs one forward over every row of a batch instead of one forward per row, and batches cold prompts in a padded prefill cohort. At 8 concurrent requests the server's aggregate throughput on Mini goes from 25.9 to 62.7 tok/s (native) and from 30.3 to 62.7 tok/s (4-bit); concurrency 1 is unchanged.

- Batched forward (`src/models/inkling2/batched.rs`): projections, convolutions, residual mixes, Mini's loop messages and experts run over `[B, L]`; only the attention core (relative mask, sliding window, sink, log scaling) runs per row against its own KV cache, as Inkling 1 does (#2673). Convolution histories are stacked left-padded to the longest row, and each row gets back exactly the history its own forward keeps, so per-row trims and the speculative rollback stay exact.
- One row routes to `forward_with_sequence_id`, so the B = 1 graph, the #3369 kernel gates (short convolution `B <= 4`, head preparation and grouped experts `B == 1`) and the DSpark verify path are unchanged. B > 4 takes the ops convolution.
- Padded prefill: the server right-pads its cohort, and every Inkling 2 mask and convolution is causal, so real positions never read padding. A batched forward of more than one token keeps as many convolution rows as it appends (`conv::WideHistoryScope`), so `trim_state` removes any row's padding exactly. `supports_batched_prefill` and `supports_padded_prefill` are true, also through the VL wrapper. The cost is that this history is held from the cohort forward until the next decode step drops it.

## Validation

M3 Ultra, every GPU run under the shared lock; details in `docs/benchmark_results/inkling2-batched-decode-m3ultra-2026-11-24.md`.

- Tiny looped model (f32): B = 3 rows at 3, 12 and 30 tokens (one past the window), with a trim on one row and a row leaving mid-batch, match their single-row decodes. A 3-row cohort right-padded to 48 (25 and 43 padding rows, past the 16-row margin) matches unpadded prefill in last-row logits, KV, convolution state and the following decode. The bound is 2e-4 (observed 3e-5). Padding on the wrong side of the stacked history fails both tests by about 3.
- Traces, B = 1 against B = 4 and B = 8: 0/98 decided disagreements on both checkpoints, 2 to 7 undecided ones out of 256 (largest gap 0.19). The B = 1 traces of main and this branch are byte-identical, and greedy text is identical on both checkpoints.
- Free-running server requests at temperature 0 no longer always equal their solo answers under concurrency: they split after 47 to 238 characters at near-ties. The same splits appear with `--max-batch-prefill 1`, so they come from batched decode arithmetic, not the padded prefill.
- Selectors: `--lib inkling` (168), `--lib coverage_tests` (18), `--lib prefill_cohort` (23), `--lib pad_trim` (4); clippy `--lib --tests`, fmt and the CI contract scripts pass. `make verify` is left to the orchestrator.

Closes #3377
@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:dense Dense transformer decoder arch:moe Sparse mixture-of-experts decoder 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 model-owned attention-cache families

1 participant