Repository navigation
Nemotron routed experts past one row: a 16-group's weight words as the outer loop, three members a pass, same bits - #502
BobClawblaw wants to merge 1 commit into
Conversation
…e outer loop, three members a pass, same bits The lane kernel took an expert's member rows two at a time with all 16 activations of a chunk live. tf_experts_w takes the four weight words of a 16-group as its outer loop, so four activations a member are live and three members a pass at four simdgroups fit. Each lane sums in tf_qdot16's order and ends in the same simd_sum, so every width gives the one-row kernel's bits; tf-nemotron-experts checks that at 2 to 64 rows and shows the 23 layers' up and down projections going from 11.93 to 11.24 ms at 32 rows and 22.57 to 20.58 at 64, equal at 2. Served on an M5 Ultra with the cache off, alternated twice against the previous kernel: one stream 503 to 513 tok/s on code and 348 to 351 on prose, 8 streams 947 to 985 and 713 to 731 in all, 32 streams 792 to 802 and 752 to 761, every reply equal to its solo and plain run. Three other shapes that kept the bits and gained nothing go to the guide's "Don't bother" list: member blocks over grid z, activations prepared once a forward, and vector loads. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
Thank you, @BobClawblaw. Turning the weight words into the outer loop while keeping each lane's summation order is It's on main as We re-made the commits without their AI-tool trailer lines, which main's history doesn't carry, so GitHub shows this PR as closed rather than merged. The commit is yours. |
…hhart#518 Lands ashhart#502 on main beside ashhart#518: a shared round can now hold 128 rows, so the routed-expert checker bit-checks and times every pass shape at 128 rows too. Layer 0's routing copy is sized by the widest width.
…hhart#518 Lands ashhart#502 on main beside ashhart#518: a shared round can now hold 128 rows, so the routed-expert checker bit-checks and times every pass shape at 128 rows too. Layer 0's routing copy is sized by the widest width.
ZIG-PREVIEW's "cheaper extra lanes": the routed-expert lane kernel past one row, faster at every width from 4 rows up and bit-identical to the one-row kernel at every width. Independent of #497 and #499 (based on
main).What changed
zig/kernels/metal/nemotron_experts.metal:tf_experts_w, instantiated astf_xup_w3/tf_xdown_w3. The existing lane kernel takes an expert's member rows two at a time with all 16 activations of a 512-chunk live per member. The new one takes the four weight words of a 16-group as the outer loop, so four activations a member are live, and three members a pass at four simdgroups fit. Each(member, output)accumulator still receives its terms intf_qdot16's order, the group'sscale * accum + sum * biasstep is unchanged, and the pass ends in the samesimd_sum, so every width gives the one-row kernel's bits. Single leftover members go through the unchangedtf_rowdot.zig/src/families/nemotron/layers.zig,kernels.zig,backend.zig:members = 3selects it with the{4, 4}geometry;rows2/rows4stay. One-row forwards, the MTP head, the prompt path and CUDA are untouched.zig/tests/nemotron_experts.zig: the word-outer shapes in the bench's variant table (the engine's ownw3s4as compiled, plus 2/4/6 members, two simdgroups and eight outputs for comparison).adding-a-zig-family.mdwith its numbers, three exact-but-not-faster shapes in its "Don't bother" list, a section in the Nemotron recipe, and ZIG-PREVIEW's item 4 restated with what remains.Exactness
tf-nemotron-experts(synthetic 4-bit weights, Zipf routing): every shapebits ==the engine's kernel at 2, 3, 4, 8, 16, 32 and 64 rows, and each row alone through the one-row kernel equals its row inside the 8-row window. Repeated over four runs while the shapes were explored.draft: false); then 467 replies across solo,draft: false, seeded sampling solo and 3x concurrent, dropped connections, 8 threads x 6 reps, 10 threads on 2 lanes, and 89k- and 130k-token prompts, all equal to the reference. The speed runs' own checks: 656 concurrent replies equal to their solo runs and 24 equal to their plain runs, 0 unequal.Speed
Expert up + down, 23 layers, µs a layer in the bench (M5 Ultra):
rows2(before)tf_experts_wServed, cache off, old and new binaries alternated twice (
bench_openai.py,bench_concurrent.py --alone --serial, 256 tokens, greedy):A small step, not the flattened curve: the kernel streams unique expert weights at about 1 TB/s up to 8 rows, 730 GB/s at 32 and 540 GB/s at 64, and most of that gap remains. Three shapes that kept every bit and gained nothing are recorded in the guide so no one repeats them: member blocks spread over grid z, activations prepared once a forward (50 fewer ALU ops a chunk, same time), and 8-byte vector loads. Six or eight members a pass, or four at two simdgroups, lose 5-40%.
Receipts
mainf8fe17d; checkpointTensorFold/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-MLX-4bitrevisiond9d758fb;serve --temperature 0 --no-thinking --parallel 32 --context 32768 --prompt-cache-gib 0for the speed runs.zig build test -Dcpu=apple_m1: 91/91 steps.zig fmt --checkclean.tools/zig/lean_check.py: 512 onmain, 512 after.tf-nemotron-expertswould show its bits and time), CUDA (untouched).🤖 Generated with Claude Code