Repository navigation
qwen3_5_moe: the experts' prompt sort as one threadgroup (stacked on #1125) - #1799
Conversation
3b77807 to
1c67832
Compare
|
Thanks @BobClawblaw: this is byte-identical to the version we reviewed (the one-threadgroup sort, byte-equal to the serial one). It lands right after #1125. |
1c67832 to
9c9a5f8
Compare
|
@ashhart, restacked on #1125's new head (53c9074): head 9c9a5f8. The sort commit's patch is line-for-line what you reviewed. CI checks pass, lean has 0 new problems, and Ornith's live replies (greedy, 1/2/4 streams, with drafts) are identical to #1125's head and to the 2 Nov run. #1125 is being rebased once more over today's main (a CHANGELOG conflict only); this follows it. |
2906c5b to
bd524f1
Compare
|
Thanks @BobClawblaw. We checked the restack: the sort commit is line for line the one we approved, and everything else under it is #1125's. Nothing more is needed here. It lands right after #1125, and if #1125's final rebase moves it again, a plain restack is all it needs. |
bd524f1 to
6d6e033
Compare
6d6e033 to
385595f
Compare
q27_route_sort ran on a single GPU thread, walking every routed slot three times for each prompt chunk. It now runs as one threadgroup with a thread an expert: the threads count the slots together in threadgroup memory, each expert's thread sums the counts before it for its first slot and writes its own slots in ascending order. The outputs (OFFS, ORDER, the sorted weights) and the kernel's interface are unchanged, so the gathers' bits are too. Ornith-1.5-122B (the publisher's 4-bit) on an M5 Ultra, tf-qwen27-run at the served 1,024-row chunks, two runs each: 8,192-token prompt 2,316 / 2,326 -> 2,680 / 2,632 tokens/s, 32,768-token prompt 2,128 / 2,118 -> 2,443 / 2,448. Prompt state and 48 decoded tokens byte-identical to the previous build at 2k, 8k and 32k; --compare-chunk 13 with --seams 1024 byte-equal. The dense model does not route and never runs this kernel.
385595f to
4600e4c
Compare
|
Thank you @BobClawblaw. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes. |
|
Thanks @BobClawblaw! This is in TensorFold 1.2.3, out now: https://github.com/ashhart/TensorFold/releases/tag/v1.2.3 |
Stacked on #1125: this branch is #1125's head (22f1026) plus one commit, 3b77807. Please review that commit only; I will rebase it onto main once #1125 lands.
Closes #1798.
What changes
q27_route_sortsorts each prompt chunk's routed slots by expert for the tensor units' gathers. It ran on one GPU thread, which walked the chunk's slots twice (count, then place). It now runs as one threadgroup with a thread an expert (config.zigadmits at most 256 experts):atomic_int counts[256]);The kernel's name, buffers and outputs (OFFS, ORDER, the sorted weights) are unchanged, so the gathers and everything after them see the same bits. Only the launch changes, from one thread to one threadgroup of the experts rounded up to 32. The dense 27B does not route and never runs this kernel. Four files:
moe.metal,moe_gpu.zig(the launch), the contract record (256 threads, 1,024 bytes of threadgroup memory) and the contract test's launch.Checks (M5 Ultra, the publisher's
ornith-ai/Ornith-1.5-122B-MLX-4bit@ 06a57aba)Exactness,
tf-qwen27-runat the served 1,024-row chunks against #1125's head:prompt_sha256) and 48 greedy tokens byte-identical at 2,048, 8,192 and 32,768 prompt tokens;--compare-chunk 13 --seams 1024:prompt_state_byte_equal,decode_state_byte_equalandseams_byte_equalall true.Prompt speed,
tf-qwen27-run, two runs of each build, alternating:Served, the recipe harness's
prefillplan (one cold prompt a size, thinking off), against the same plan on #1125's rebase 078e224:Each served row is a single prompt, so read the long rows loosely: attention takes a larger share there. The harness's quick plan on the served build matches #1125's results (structured 18/18, sampling 9/9, turns, URLs and the soak, draft and concurrency suites pass; tools 4/5 with the same named-tool-with-thinking case as #1125). The vision suite gives 4/6 and 16/16, as on #1125. Decode is unchanged (one stream 132.7 / 191.6 / 160.6 / 193.8 tok/s for prose, code, structured and lists).
Kernel contract,
tf-kernel-contract --only qwen27:CI set:
zig fmt --check,test-kernel-contract,test-golden,test-server-securityandtest-pull-securitypass. Lean: 424 problems, the same 424 as #1125's head.zig build testhas one failure,contract_images_test("every registered CUDA launch and control selects its own image"), which fails the same way on #1125's head without this commit.