Skip to content

[provider 0.10.12] Batched Bonsai 27B prompt rows by default; per-row FP32 arithmetic only on request (pairs) - #70

Merged
jonathan308 merged 3 commits into
release/provider-0.10.12from
fix/bonsai-batched-prefill-0.10.12
Nov 12, 2026
Merged

jonathan308 merged 3 commits into
release/provider-0.10.12from
fix/bonsai-batched-prefill-0.10.12

Conversation

@jonathan308

@jonathan308 jonathan308 commented Nov 12, 2026 •

Copy link
Copy Markdown

Base: release/provider-0.10.12 = c633d221d6, the provider's current pin (owner, 11-12)

What

HadamardQuantizedLinear gains independentRows (init parameter, default false).

  • Default (single Mac): FP32 input of more than one row to the 2-bit/group128/block1024 profile with FP16 scales
    (Bonsai 2 27B) takes one batched packed matmul again: the path single-Mac prefill used before fe35554
    (provider ≤ 0.10.4). That is the batched matrix kernel: TF32 (NAX) on M5, FP32 steel on M1–M4.
  • independentRows: true (pairs): fe35554's M=1-per-row reduction, unchanged. Each row gets the bytes of a
    separate singleton call on every chip. d-inference's pair stages (QwenPrismHadamardSource.install) ask for it.
  • Unchanged either way: singleton calls (a request decoding alone), every other profile (the 9B's block4096 included),
    QuantizedLinear.independentRowsForward, and the FP16→FP32 constant reuse.

Why

fe35554 ("Preserve singleton FP32 arithmetic for Bonsai packed rows", first shipped in provider 0.10.5 via
c633d221) sends every prompt row of the 27B through an M=1 kernel. Engine-measured prefill fell 2.3–6× on every chip:

Chip ≤ 0.10.4 ≥ 0.10.5
M5 Ultra 1,140 160–197
M5 Max 620 100
M3 Ultra 360 115
M1–M4 220 76–96

Bonsai's first-token deadline is 9 s + 5 ms per prompt token, so image and tool prompts of about 1–2K tokens and
more miss it, and OpenRouter gets 429s: only 35 % of image requests and 47 % of tool requests are served.

Owner's decision (option i): single-Mac serving goes back to the batched kernel for prompt processing. Pairs keep
the exact per-row arithmetic, because their two machines must agree. Prompt rows on a single Mac are no longer
bit-identical to the singleton decode arithmetic, and concurrent decode rows depend on their cohort, both as before 10-30. The owner accepted both.

Commits

Commit What
c7cb850bf3 Red test: testBonsaiFloat32RowsDefaultToOneBatchedPackedMatmul. A default layer's 512-row and 4×128-row FP32 output must equal one quantizedMM over all rows with FP32-widened constants, with and without the grouped GDN layout. On this head every row goes through M=1, so it fails where the two kernels differ. Red: Fork Tests 43138144326 ran on 073a7119ed (shard 3, 4 assertions); that commit has the same tree as c7cb850bf3 but was built on main.
ac8f03e36c The fix: independentRows, the profile check pulled into isBlock1024Profile, comments, and fork.yaml ("Bonsai packed signed-Hadamard layers"). The singleton-row test now builds its layers with independentRows: true. The default test also checks that the opt-in leaves a block512 profile on the batched path.
d7464f7d08 Float16ConstantCastTests: the oracle takes the per-row path only for independentRows layers, so the old assumption no longer fails CI (it failed in 43138178252, shard 2, on the main-based twin). The repeated-call/mutation and compile-state tests run both modes. Tests only.

Only Swift in Source/MLXNN changes: no Metal, C or C++ source, so mlx.metallib is unchanged. swift format is clean on the three changed Swift files.

Consumers

  • d-inference: 0.10.12: Bonsai 2 27B prompts batched again on a single Mac (mlx-swift 1b3520fe94); pairs keep per-row arithmetic d-inference#2022 (draft, on #1970's head 0e6ac37885): the pin bump plus the pair stage's opt-in. It pins this PR's head for CI and this branch's merge commit after review. The pair's
    bonsai-fp32-row-arithmetic-v2 receipt stays byte-identical because the pair's arithmetic is unchanged.
  • mlx-swift-lm: no change needed. Its loader (PrismHadamardCheckpoint.install) builds the single-Mac layers with
    the default.
  • Concurrent decode on a single Mac (review M1; the owner accepted it): the SDK's per-row decode seam (Qwen35BatchDecodeProjection) runs only under Qwen35BatchDecodeScope.enabled, which only cluster sessions set. So a single-Mac decode step with several requests takes one batched matmul too, as in 0.10.4, and a request's exact output can depend on the requests decoding beside it. Pairs (independentRows: true) stay per-row exact.

Review

Reviewed and merged at 03:11:45Z: merge commit 1b3520fe94, which d-inference #2022 pins. Review S1 (a test that builds the block1024 case without the argument) is covered from the consumer side in #2022 (BonsaiRowArithmeticTests.aSingleMacLoaderBuildsBatchedProjections). It goes into #69 for main.

jonathan308 and others added 3 commits November 11, 2026 18:10
… default

A multi-row FP32 call to the 2-bit/group128/block1024 Hadamard profile with
FP16 scales must give the bytes of one quantizedMM over all rows with the
FP32-widened constants (the batched matrix kernel single-Mac prefill used
before the per-row contract), with and without the grouped GDN layout.
Red on this head: every row goes through the M=1 kernel instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
HadamardQuantizedLinear gains `independentRows` (default false). FP32 input
of more than one row to the 2-bit/group128/block1024 profile with FP16
scales now takes one batched packed matmul unless the layer was built with
`independentRows: true`, which keeps fe35554's M=1-per-row reduction (the
bytes of separate singleton calls on every chip) for callers whose machines
must agree byte for byte, such as the stages of a pair.

Single-Mac prefill returns to the batched matrix kernel it used before the
per-row contract (TF32 on M5, FP32 steel elsewhere), 2.3-6x faster on long
prompts, at the cost of prompt rows no longer matching the singleton decode
bytes. Singleton calls, other profiles (block4096 included) and
`independentRowsForward` are unchanged.

HadamardLayerTests: the singleton-row test builds its layers with
`independentRows: true`; the new default test compares the default with one
batched quantizedMM and checks that the opt-in leaves a block512 profile on
the batched path. fork.yaml describes the opt-in.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…dentRows

Float16ConstantCastTests' oracle still sent every Bonsai FP32 multi-row call
through the singleton kernel, so with the batched default its exact
repeated-call test failed on CI (Fork Tests 43138178252, shard 2). The
oracle now takes the per-row path only for a layer built with
`independentRows`, and one batched quantizedMM otherwise (the oracle this
test had before fe35554). The repeated-call/mutation and compile-state
tests run for both layers, so cache invalidation stays covered on the
batched and the per-row paths; the ineligible profiles are checked with
the opt-in too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jonathan308
jonathan308 merged commit 1b3520f into release/provider-0.10.12 Nov 12, 2026
8 checks passed
jonathan308 added a commit that referenced this pull request Nov 12, 2026
Review S-6: on CI's runner (vector limit 10) batched calls below 10 rows
give the per-row bytes, so the byte tests never exercised the 2-vs-3-row
boundary; a mutant that drops the single-Mac clause (back to #70), or
`<` -> `<=`, survived them. Float16ConstantCastTests (`@testable import
MLXNN`) now asserts `takesPerRowPath` itself: true at 2 rows and false at
3, 12 and 512 rows for a single Mac, for decode-shaped [B, 1, H],
prompt-shaped [1, S, H] and flat [M, H] calls, and true at every row
count with `independentRows`. Nothing is evaluated.

Red first: the same test on 49c145c's code (threshold 12) fails at 3
and 12 rows (Fork Tests on test/bonsai-switch-2-3-red); each mutant above
fails it too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant