Skip to content

Metal: the 27B's 8-bit lane path reads its code bytes directly and reuses producer sums (fixes #2502) - #2518

Merged
ashhart merged 3 commits into
mainfrom
lead/q8-lane-direct
Nov 8, 2026
Merged

ashhart merged 3 commits into
mainfrom
lead/q8-lane-direct

Conversation

@ashhart

@ashhart ashhart commented Nov 8, 2026

Copy link
Copy Markdown
Owner

Fixes #2502. On M5, an MLX 8-bit group-64 Qwen3.8-27B ran every projection through tf_lane's staged branch. That branch copied each code byte through threadgroup memory, an identity for 8-bit, and recomputed every group's input sum in every 32-column tile, although the producer kernels had already written those sums.

What changes, for TF_BITS == 8 only:

  • A direct uint8 device view of the stored code tiles replaces the staged copy (zig/kernels/metal/core/lane_projection.metal).
  • Prepared 8-bit sums are read from the producer's group-major stride, with inactive rows guarded. The 27B passes the producer sums through encodeSums, and the register path is unchanged.

Exactness, pinned first: the first commit adds lane q8 g64 contract entries for the 27B's head, attention, recurrent and MLP dimensions at SK1/2/4/8, and passes them on the untouched shader. A frozen copy of main's shader then serves as the byte reference. Every output byte of the new path equals it across:

  • four native K splits;
  • fallback sums;
  • groups 32 and 128;
  • prefetch 2;
  • direct FP32 output.

Two planted controls go red at gate 3: a byte view one group off, and sums read at the wrong stride. The 24 launch records pass, and the 4-bit pipelines are byte-identical, with 24 AIR pairs.

Measured on an M5 Ultra, with fresh processes in the order warm, main, new, new, main, one stream and no drafts. Tokens and committed prompt state are byte-equal to main.

MLX affine g64 Cold 2K prompt Cold 8K prompt 512-token decode
8-bit, main 648.5 643.1 27.2
8-bit, this PR 768.5 (+18.5%) 760.0 (+18.2%) 29.3
4-bit, main 1905.4 1856.5 47.7
4-bit, this PR 1904.9 1856.9 47.7

The 8-bit prompt is still 40–41% of 4-bit's, against a stored-weight byte ratio of 54.4%. Dense projections dominate its profile, so the 4-bit register kernel's structure is the next lever there. The 27B recipe now has one 8-bit table: these numbers, plus the disk and wired memory from #2506.

Lean shows nothing new, and every file is at or under 600 lines.

@ashhart
ashhart force-pushed the lead/q8-lane-direct branch 3 times, most recently from 8c86207 to 0994248 Compare November 8, 2026 07:11
Exercise the head and fused attention, recurrent and MLP widths at the
checkpoint’s K splits before replacing the staged byte reader.
Keep the same FP64 bounds, nonfinite rules, guards and sum stress.
Use a device uint8 tensor for stored codes and accept the producer’s
ordered group-64 sums. Keep the original 16-row windows, K splits and
FP32 arithmetic. Four-bit compiled AIR and model state remain identical.

The pinned shader’s byte contract covers BF16 and FP32 outputs, fallback
sums and group variants, with wrong-group and wrong-stride controls.
Cold 2K and 8K prompts improve 18.5% and 18.2% on an M5 Ultra.
Document the remaining dense projection gap against 4-bit.

Refs #2502
@ashhart
ashhart force-pushed the lead/q8-lane-direct branch from 0994248 to b5e6295 Compare November 8, 2026 08:08
@ashhart
ashhart merged commit 5a67a27 into main Nov 8, 2026
3 of 7 checks passed
@ashhart
ashhart deleted the lead/q8-lane-direct branch November 10, 2026 16:34
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.

Qwen3.8-27B MLX 8-bit on M5: an 8-bit lane path without staged codes or recomputed sums

1 participant