Skip to content

feat(models): native batched decode and padded prefill for Inkling 2 - #3392

Merged
inureyes merged 3 commits into
mainfrom
feature/issue-3377-inkling2-batched-decode
Nov 24, 2026
Merged

inureyes merged 3 commits into
mainfrom
feature/issue-3377-inkling2-batched-decode

Conversation

@inureyes

Copy link
Copy Markdown
Member

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 (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.
  • One row routes to forward_with_sequence_id, so the B = 1 graph, the perf(models): port Inkling 2 Mini Metal kernels #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

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
Server throughput at concurrency 1/4/8 (ABAB against 451ec68) on both Mini checkpoints, B = 1/4/8 teacher-forced trace parity, the B = 1 identity check and the free-running solo-versus-concurrent comparison, plus the supported-models and continuous-batching entries.

Refs #3377
@inureyes inureyes changed the title perf(models): native batched decode and padded prefill for Inkling 2 feat(models): native batched decode and padded prefill for Inkling 2 Nov 24, 2026
@inureyes inureyes added status:done Completed type:performance Performance improvements priority:low Low priority area:models Model architectures, weights, loading, metadata area:inference Generation, sampling, decoding (incl. speculative, DRY) labels Nov 24, 2026
@inureyes
inureyes marked this pull request as ready for review November 24, 2026 05:18
@inureyes
inureyes merged commit 7c15e37 into main Nov 24, 2026
33 checks passed
@inureyes
inureyes deleted the feature/issue-3377-inkling2-batched-decode branch November 24, 2026 05:18
@inureyes inureyes added this to the 0.9 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:low Low priority status:done Completed type:performance Performance improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(models): native batched decode and padded prefill for Inkling 2

1 participant