Repository navigation
qwen27 metal: qk projections, flat glue and Metal 4 verify passes, each bit-identical and switchable - #2342
qwen27 metal: qk projections, flat glue and Metal 4 verify passes, each bit-identical and switchable#2342ashhart wants to merge 10 commits into
Conversation
|
Apple M3 Ultra (Qwen3.8-27B MLX 4-bit, main against this branch, base new new base): GREEN. On this chip only the flat glue is new, since qk and Metal 4 stay off without tensor units. Replies are equal, and decode is level to slightly faster:
Each pair is that arm's two runs, aggregate tok/s, and every run lands on the same side. This run checked decode only; prefill on pre-M5 isn't covered. The M5 Ultra cells, which run qk and Metal 4 too, come next. This lands when they're level. |
fa3b147 to
f9429aa
Compare
|
Apple M5 Ultra (Qwen3.8-27B MLX 4-bit, main against this head
Prompt tokens match across every run (0 of 20 rows differ), and both chat cells (thinking on and off) qualify on both builds. With the M3 Ultra run from 6 Nov, both chips are covered: on the M5 the qk projections and Metal 4 verify passes add a few percent to decode, and nothing is slower.
|
7917a84 to
174645f
Compare
|
Rebased onto main (now 174645f). It conflicted with #2818's whole-prompt row blocks in
|
1744e68 to
179ed9b
Compare
4f06405 to
d7620df
Compare
Main's 9f23d0d keeps Metal 4 out of the 27B's binary after a balanced rerun showed small losses, so #2342 lands without its Metal 4 commits (Metal 4 submission for Qwen27 verify passes, tf-qwen27-stack-ab and the unfair-lock follow-ups). Its CHANGELOG line now names only the qk projections and flat glue.
Main's 9f23d0d keeps Metal 4 out of the 27B's binary after a balanced rerun showed small losses, so #2342 lands without its Metal 4 commits (Metal 4 submission for Qwen27 verify passes, tf-qwen27-stack-ab and the unfair-lock follow-ups). Its CHANGELOG line now names only the qk projections and flat glue.
e2b318c to
843d0e9
Compare
Main's 9f23d0d keeps Metal 4 out of the 27B's binary after a balanced rerun showed small losses, so #2342 lands without its Metal 4 commits (Metal 4 submission for Qwen27 verify passes, tf-qwen27-stack-ab and the unfair-lock follow-ups). Its CHANGELOG line now names only the qk projections and flat glue.
843d0e9 to
0402836
Compare
A tensor-op projection kernel for 4-bit group-64 matrices on chips with tensor units. Load leaves those matrices in projection.weight_layout and skips their reorder for tf_lane_reg, so qk reads the codes and the metadata_layout scales and biases where they sit: no extra memory. Every output word equals tf_lane_reg's on the same K split. - zig/kernels/metal/core/qk.metal: the kernel, any rows a dispatch. - zig/src/core/qk_projection.zig: pipelines by K split and block rows, the encode, and a compile check for runtimes that refuse uint4b_format. - Plain matrices take qk for decode and prompt rows; the Neural Engine share's skipped-tile and cut-group forms take tf_lane_pair. - TF_Q27_QK=0 at load restores the reorder and tf_lane_reg. - tf-qwen27-qk-ab: tf_lane_reg against qk, interleaved in one process. Checked on an M5 Max: public golden 1024 of 1024; qk-ab equal over 1,204 hot rounds a side; 16 served replies equal to stock; streams, marks, lanes and lean_check as on main; zig build test exit 0. A verify is 1.2% to 2.9% faster hot.
…and argmax Four glue kernels for Qwen27 rounds, each bit-identical to the kernel it replaces, with TensorFold's own kept wherever a round does not fit them. - tf_delta_gdn_columns_1/2/4 replace tf_delta_gdn_tree_slots_* for lone trees of up to 4 live states, reading the slot schedule as flow words (tree_slots.flows, a new frame field). - tf_delta_gdn_pre_vectors replaces tf_delta_gdn_pre for four taps over 128-wide heads with bf16 conv, A_log and dt. - q27_mlp_rows replaces custom_kernel_q27_mlp_xs where 256 threads run. - tf_round_pick_chunks/rows replace tf_round_bf16_argmax for Qwen27's two callers through Ops.argmaxChunks; other families keep Ops.argmax. - TF_Q27_FLAT_GLUE=0 at load, or decode_round.setFlatGlue, keeps every round on TensorFold's kernels. - tf-qwen27-glue-ab: the general glue against the flat kernels. Checked on an M5 Max, alone on 1.2.2: glue-ab equal over 1,204 rounds; golden, streams, marks, reuse, lanes and served replies equal; a 16-row verify 3.2% to 4.2% faster. Rebased here with one conflict (main's routed block fields in gpu_frame.zig) and checked stacked on qk: golden 1024 of 1024. On main d2b3722 (#2913: XS sums compile out before tensor units), q27_mlp_rows writes XS only under Q27_XS and its key carries main's .xs, so M1-M4 keep the flat activation without sums; main's norm and MLP test now runs with the flat glue off and on.
Main's 9f23d0d keeps Metal 4 out of the 27B's binary after a balanced rerun showed small losses, so #2342 lands without its Metal 4 commits (Metal 4 submission for Qwen27 verify passes, tf-qwen27-stack-ab and the unfair-lock follow-ups). Its CHANGELOG line now names only the qk projections and flat glue.
0402836 to
5439065
Compare
Qwen3.8-27B on Metal: three changes, each with its own switch and each bit-identical to what it replaces. Four commits; the commit messages carry the details.
zig/kernels/metal/core/qk.metal,core/qk_projection.zig):projection.weight_layoutin place: load skips the reorder fortf_lane_reg, so no extra memory is needed.tf_lane_reg's on the same K split.TF_Q27_QK=0restorestf_lane_reg.TF_Q27_FLAT_GLUE=0turns it off.zig/src/metal/metal4.zig):setBytesand a residency set.TF_Q27_METAL4=0turns it off.For review:
Buffer.deinitnow callsmetal4.released().command.zig's Queue, CommandBuffer and ComputeEncoder gain an optionalm4field.core/fence.zigguards its Metal 4 branch with@hasField, so the recording fakes still compile.A/B tools:
tf-qwen27-qk-ab,tf-qwen27-glue-ab,tf-qwen27-metal4-abandtf-qwen27-stack-ab.Checked on an Apple M5 Max (at main 7040192, before this rebase onto 691fb43):
stack-ab(stock on Metal 3 against all three in one process): every logit and pick equal over 68 rounds cool and 244 hot;zig build testexits 0.Speed:
On this rebase,
zig build native(ReleaseFast) builds on an Apple M3 Ultra, lean matches main (252), and the commits are unchanged apart from the base.Not checked yet, so this stays out of the queue:
device.tensorUnits()inRunner.initReady, withTF_Q27_FLAT_GLUEstill overriding), as Metal 4 already does;Before landing, we'll run main against this branch on an Apple M3 Ultra and an Apple M5 Ultra: replies equal, and prefill and decode level or faster.