Repository navigation
feat(models): native batched decode and padded prefill for Inkling 2 - #3392
Merged
Merged
Conversation
Inkling 2 served B > 1 by running each row as its own forward and declined padded prefill, so concurrent requests got no batching gain. A batched forward now runs once over [B, L]: projections, convolutions, residual mixes, loop messages and experts see the whole batch, and only the attention core (relative mask, sliding window, sink, log scaling) runs per row against its own KV cache, as Inkling 1 does. Convolution histories are stacked left-padded to the longest row and each row gets back exactly the history its single-row forward keeps, so trims stay exact. One row keeps the single-sequence graph, so B = 1 output and the Metal kernel gates are unchanged. A batched forward of more than one token keeps as many convolution rows as it appends, so the server's right-padded prefill cohort can trim any amount of padding exactly; supports_batched_prefill and supports_padded_prefill are now true (also through the VL wrapper). Tiny-model tests: B = 3 rows of different lengths (one past the window) with a trim on one row and a row leaving equal their single-row decodes; a 3-row padded cohort equals unpadded prefill in logits, KV and convolution state and in the decode after it. Refs #3377
inureyes
marked this pull request as ready for review
November 24, 2026 05:18
This was referenced Nov 24, 2026
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.
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.
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 (update(models): batch model-owned attention decode #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.forward_with_sequence_id, so the B = 1 graph, the perf(models): port Inkling 2 Mini Metal kernels #3369 kernel gates (short convolutionB <= 4, head preparation and grouped expertsB == 1) and the DSpark verify path are unchanged. B > 4 takes the ops convolution.conv::WideHistoryScope), sotrim_stateremoves any row's padding exactly.supports_batched_prefillandsupports_padded_prefillare 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.--max-batch-prefill 1, so they come from batched decode arithmetic, not the padded prefill.--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 verifyis left to the orchestrator.Closes #3377