Repository navigation
update(models): batch model-owned attention decode - #2673
Merged
Merged
Conversation
Member
Author
|
Security/performance review update:
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: |
inureyes
force-pushed
the
update/issue-2570-model-owned-batching
branch
from
October 27, 2026 07:44
fb194e3 to
4d07635
Compare
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
force-pushed
the
update/issue-2570-model-owned-batching
branch
from
October 27, 2026 08:31
15bacea to
1460ca0
Compare
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
inureyes
marked this pull request as ready for review
October 27, 2026 08:53
12 tasks done
This was referenced Nov 22, 2026
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
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.