Skip to content

perf(qmm): int8-activation prefill on tiled lane weights, default on for dense Qwen3.5/3.8 (+27-34% prefill on 27B) - #1384

Merged
ddalcu merged 5 commits into
mainfrom
perf/int8-lane-prefill
Nov 29, 2026
Merged

ddalcu merged 5 commits into
mainfrom
perf/int8-lane-prefill

Conversation

@ddalcu

@ddalcu ddalcu commented Nov 29, 2026

Copy link
Copy Markdown
Owner

What

On M5 (NAX), a dense Qwen3.5 / 3.6 / 3.8 trunk with a DFlash drafter bound has its projections tiled in place for the lane_qmm row lanes, so MLX's own int8 qmm (MLX_ENABLE_INT8_QMM) can never read them. This ports that path into lane_qmm's prefill on the tiled layout:

  • lane_qmm_int8_quant.metal: MLX's affine_quantize_rows. It quantizes each 64-group of the prompt rows to int8, with per-group f32 scales and sums, and pads to 64-row tiles.
  • lane_qmm_int8{,_head}.metal: MLX's affine_qmm_t_int_nax and QuantizedBlockLoaderInt, addressing the tiled weight. The product runs on int8 tensor ops; each group's scale, bias and row sum fold into one fp32 step.

It is LOSSY and on by default for these trunks. "int8_prefill": false in model-settings.json (or Model Settings ▸ Int8 prefill ▸ Off) opts out. Prism (Bonsai 2) packs keep their own int8 route, opt-in as before. 4/6/8-bit weights take it. 5-bit declines by name, and a view whose width is not a multiple of 64 takes the fp prefill.

Numbers (Qwen3.8-27B, M5 Ultra, int8 off → on)

4-bit 8-bit
Prefill 1934 → 2463 tok/s (+27%) 1788 → 2396 tok/s (+34%)
TTFT, 513 to 16k-token prompts −19 to −22% −25 to −27%
Decode level level
Echo-logprob quality, 6278 positions ppl unchanged, KLD ~0.0013, top-1 97.5–98% ppl unchanged, KLD ~0.0014

Scope

Inkling, Flash Next, MoE Qwen and DeepSeek are unaffected: their weights are never tiled. A dense Qwen trunk without a drafter keeps its current prefill path.

Known

  • The gate is rows > 128 on a tiled weight, not "this is a prompt". A batched verify or decode whose combined rows pass 128 (9+ DFlash slots × block 16) also takes int8 activations. Row-exactness already ended past 128 rows on the fp prefill path, and the crowd thresholds keep such groups rare. If we want it prompt-only, the caller has to say so; the row count can't.

Tests

  • lane_qmm: int8 on a tiled weight vs the int8 activation's fp32 product, at 4/6/8 bits and both column tiles (64, and 32 for a GDN joined projection's shape), for the whole weight and a row view. 5-bit stays bit-equal to int8-off.
  • Kernel contract: the matmul at 4/6/8 bits and the quantizer at both K orders (five gates against float64, planted controls red). One known finding: MLX's quantizer drops a NaN from a group's absmax, as MLX itself does.
  • qwen3_5: the setting's default (on for a tiled trunk, off on Prism) and the override.
  • App: the Int8 prefill picker shows the default per model type, and the badge marks a non-default choice (Int8 lossy, or Int8 off).
  • Full suite on M5 Ultra: 5774 pass, 429 skip, 1 fail. The failure is the DeepSeek-V4.1 DSpark tape, which is already red on main. Lint is 0.
  • units-check -Dunits=true: the new int8_owners set passes (allowlisted: it is set and read in one unit). The check still flags engines.mlx.spec.round_cost.build_id_mu, which this PR does not touch.

… on for dense Qwen3.5/3.8

A dense qwen3_5 trunk tiled for the lanes (NAX, DFlash drafter bound) now reads
prompts through an int8 port of MLX's affine_qmm_t_int_nax on the tiled layout:
the activation is quantized per 64-group row, the product runs on int8 tensor ops
and each group's scale, bias and row sum fold into one fp32 step.

Qwen3.8-27B, M5 Ultra: prefill 4-bit 1934 -> 2463 tok/s, 8-bit 1788 -> 2396,
TTFT -19..-27%, decode level; echo-logprob KLD ~0.0013, perplexity unchanged.

LOSSY: on by default for these trunks, `int8_prefill: false` opts out (Prism
packs stay opt-in). 4/6/8-bit; 5-bit and views off the 64-column tile decline by
name. Kernels registered with the kernel contract; the app shows the default and
badges an opt-out.
…e 4-bit 32-column tile

- NOTICE names the three ported MLX kernels.
- int8_owners is set and read in one unit: listed in unit_globals_ok.txt.
- The int8 test covers a 4-bit weight tiled at 32 columns (a GDN joined
  projection) with a 64-aligned view; the contract adds K 5120 and row/n tiles.
- The quantizer builds on metal_stdlib alone (no NAX headers).
- A width off a multiple of 64 falls back silently; only 5-bit is declined by name.
- qwen3_5: a test of the int8_prefill default and override.
- App: MiniCPM-V 4.7 defaults like the other dense trunks; one model-type lookup.

ddalcu commented Nov 29, 2026

Copy link
Copy Markdown
Owner Author

🤖 MLXServe-PRBot — code review

The port is right:

  • int8Prefill gates on rows > MAX_ROWS after the lane check, so decode and verify widths keep the exact lanes.
  • The quantizer pads to 64-row tiles, and 5-bit and widths off the 64 tile decline to the fp prefill (5-bit by name, once).
  • Tiling is already NAX- and bf16-gated (tileLaneWeights), so no non-NAX Mac reaches the int8 kernel.
  • The contract registers the matmul at 4/6/8 bits and the quantizer at both K orders.
  • int8_owners is set and read inside one unit, which justifies the allowlist entry.
  • release drops the owner.

One bug blocks; one thing needs saying:

  1. The SSD prefix cache does not know the prefill went int8. modelFingerprintWithLayout (engines/mlx/cache/ssd/disk_tier.zig:4224) hashes the model dir, config.json, the config overrides and the arch's layout namespace, and nothing about int8_prefill. Until now that hole sat behind an opt-in on Prism packs. This PR turns it on by default for every dense Qwen3.5/3.8 with a drafter, so it is now the common case. Failure scenarios:

    • A user sees a quality regression and sets "int8_prefill": false to get exact numerics. The next long prompt restores int8-computed K/V and GDN state from ~/.mlx-serve/kv-cache and decodes on top of it, so the "off" run still carries int8 activations for every cached prefix.
    • The reverse holds after upgrading: fp-era chunks are spliced under int8 continuations.

    Key the fingerprint on the resolved int8 state of this load, the way feat(lora): qwen3_5 and Prism serve LoRA adapters through --lora (mlx-lm and PEFT) #1374 had to key its adapter (h.update("\x00mlx-serve-int8-prefill\x00") when the owner is armed). Add a test that toggling the setting changes the root.

  2. Binding a drafter now changes the prompt's numerics. The weights are tiled only when a DFlash drafter binds (rowExactDecode → dflash_bound), so the default-on int8 prefill engages exactly then. Drafter off is fp prefill; drafter on is lossy prefill. Anyone A/B-ing a drafter for speed now also gets a different first token on long prompts, and will blame speculation, which is exact. The Model Settings help says "with a DFlash drafter", which is the right fact. Put the same line in docs/cli.md/performance.md where drafters are documented, and in the [lane] int8 prefill engaged log line ("drafter-bound trunk"). Otherwise the spec-on/spec-off parity people check will look broken.

Non-blocking: ModelSettingsApply.int8PrefillByDefault hand-lists ["qwen3_5", "qwen3_5_text", "minicpmv4_7"] to mirror the plugin. That is the hand-spelled-arch-gate class app/CLAUDE.md warns about (lfm2-vl vs lfm2_vl). The picker also says "Default (On)" for a pack with no drafter, where the default is effectively off. The server knows the real answer; reporting it per model (/v1/models meta or /props) would retire the mirror.

There are no conflicts with main, and CI is still running. It is under 1,000 lines, so it auto-merges once item 1 is fixed, an approved review is posted at that head, and CI is green.


Generated by Claude Code

- CHANGELOG: the v26.11.5 entry for everything since v26.11.4.
- CONTRIBUTING: monitor your PR's bot review, follow AGENTS.md, which new models we
  take, self-review with a subagent, remember the Swift app.
- docs/plugin-engine.md: writing an engine plugin; linked from README, plugins.md and
  plugin-model.md.

ddalcu commented Nov 29, 2026

Copy link
Copy Markdown
Owner Author

🤖 MLXServe-PRBot — code review

The delta since 71d396a3 is a merge of main (#1346) and 09c43a39, which is not on main. That commit carries the v26.11.5 CHANGELOG entry, CONTRIBUTING rules 10-14 and docs/plugin-engine.md. None of the kernel, lane_qmm or plugin code changed, and there are no conflicts with main.

  1. Still blocking: the SSD prefix-cache key. modelFingerprintWithLayout (engines/mlx/cache/ssd/disk_tier.zig:4224) still ignores whether this load's prefill is int8. With it on by default, "int8_prefill": false restores int8-computed K/V and GDN state from disk, and the fp-era chunks from before the upgrade get spliced under int8 continuations. Key the fingerprint on the resolved int8 state, and test that toggling it moves the root.
  2. The release docs ride a perf PR. 09c43a39 is the v26.11.5 changelog for everything since v26.11.4, plus contributor rules and a new engine-plugin guide. Merging perf(qmm): int8-activation prefill on tiled lane weights, default on for dense Qwen3.5/3.8 (+27-34% prefill on 27B) #1384 lands all of it, and reverting perf(qmm): int8-activation prefill on tiled lane weights, default on for dense Qwen3.5/3.8 (+27-34% prefill on 27B) #1384 would take the changelog with it. If that is the intent, fine; otherwise land 09c43a39 on main on its own. Its int8 line also says "no measurable change in its answers". That holds for KLD and top-1, but it is unqualified against item 1: a cached prefix computed with int8 is served whatever the setting.

The drafter-coupling note and the app's hand-copied model-type list from the last review are unchanged and non-blocking.


Generated by Claude Code

The SSD tier's fingerprint did not know a load's prompts went through the
LOSSY int8 prefill, so int8_prefill:false (or the same pack loaded without
a drafter) could restore int8-computed K/V and GDN state, and the reverse.

- lane_qmm's int8 owner set is Shared, so the engine can ask int8Armed()
  for a plugin's model under -Dunits; its allowlist line goes.
- The load adds an int8-prefill-v1 marker to the layout namespace
  (int8PrefillNamespace) when the trunk is armed. Int8 off keeps the root.
- The engage log names the bound drafter and the off switch;
  docs/performance.md documents the route, its numbers and how to A/B a
  drafter with it.

ddalcu commented Nov 29, 2026

Copy link
Copy Markdown
Owner Author

🤖 MLXServe-PRBot approved — reviewed at head 6bba7ce6, no issues found.

The delta since daaaddd8 is 6bba7ce6, and it fixes the blocking item:

  • The cache root follows the arming. int8PrefillNamespace appends int8-prefill-v1 to the layout namespace only when lane_qmm.int8Armed(model) holds. load.zig reads it at the disk-tier attach (:877), after tileLaneWeights has armed the owner at :384, so the root reflects this load's actual prefill. With int8 off the namespace is unchanged, so existing fp caches keep their root. The test covers int8 on/off × marker on/off: four distinct roots, and off equals the old fingerprint.
  • The owner set is Shared (shared_all.zig, allowlist entry removed). Under -Dunits the plugin unit that arms it and the engine unit that reads it see one set. The key is the same pointer both sides use (b.model is the mp handed to tile_lanes).
  • The drafter coupling is stated. The engage log names the bound DFlash drafter and the int8_prefill: false switch, and docs/performance.md carries it.

The release docs riding this PR are noted as intended. Still a follow-up: the app's hand-copied model-type list for the default.

There are no conflicts with main, and CI is running. At +1,032/-36 it is past the auto-merge size limit, so ddalcu merges it.


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant