mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #241] [CLOSED] Faster grouped and per-hit Q2_0 expert kernels, bitwise identical #2524
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#2524
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/241
Author: @gputier
Created: 9/30/2026
Status: ❌ Closed
Base:
main← Head:pr/grouped-q2-0.1.29📝 Commits (1)
16c2f0akernels: faster grouped and per-hit Q2_0 expert kernels, bitwise identical📊 Changes
4 files changed (+1128 additions, -29 deletions)
View changed files
📝
CMakeLists.txt(+7 -0)📝
include/strata/kernels/s2_expert_grouped.hpp(+13 -0)📝
src/kernels/cuda/s2_expert_grouped.cu(+429 -29)➕
src/kernels/s2_expert_grouped_parity.cpp(+679 -0)📄 Description
Faster grouped and per-hit Q2_0 expert kernels, bitwise identical
Rebased on v0.1.29. One commit, four files:
src/kernels/cuda/s2_expert_grouped.cu, its header, a new parity test, and the test's CMake entry.What it does
The grouped kernels (verify window, MTP layer) staged each entry's activations as
xs_q[k][c * 8 + j], an 8-way bank conflict on every read, and recomputed the chunk sumhxwith eight dp4a per row. The per-hit kernels (token graph) read each chunk with 44 byte loads.New kernels:
hxis summed once per chunk;(dx, hx)pairs, conflict-free on the staging writes and the reads, two rows per warp;uint2code loads, 16-bit scale loads, one warp per (gate, up) pair or pair of down rows.s,hxand the float expressiondw * dx * (float) (s - hx)are unchanged, so every output is the same bits as before. Anything the wide loads cannot take (unaligned activation row, odd stride, odd blob arena) falls back to the previous kernels, andmoe_grouped_last_path()reports which ones ran.Default path is identical to the byte
Measured on an RTX 5090 (sm_120, Windows, MSVC 2022, CUDA 13.4), Release build, v0.1.29 as the base.
s2_expert_grouped_parity(new, in ctest): runs every entry point with the previous kernels, then the new ones, on synthetic Q2_0 blobs and Q8_0 activations. Output and scratch match byte for byte in all 11 cases (fp32 scales, fp16 d,_devwith a partial count,_multi,moe_grouped_s2with and without resident groups, 2-byte aligned activations, slot stride BLOB + 4, arena 4 mod 8). It also checks against a double-precision host reference (worst 1.2e-07 of sum|term|). Result: 0 failures.ple_parity(Q2_0 PLE table),expert_parityandpool_test(pack/full/experts.bin).--spec 4 --expert-cache 8000 --prefill 2048 --max-new 256, three prompts (32, 2 520 and 23 020 tokens), two passes each: all 256 output tokens are identical in every run, and the same withSTRATA_OLD_GROUPED=1on the shortest and longest prompt. This model is not Q2_0, but readingsrc/core/mtp.cppthe MTP layer's resident experts callmoe_grouped_s2, so the drafting path should run through the new kernels (from the code, not confirmed by a counter).Gain
Kernel micro-benchmark (
s2_expert_grouped_parity --bench, RTX 5090, idle GPU, 312 MB of blobs cycled to defeat L2):moe_hit_grouped_s2, 9 hitsmoe_hit_grouped_s2, 1 to 5 hitsmoe_grouped_s2, 4 tokens, no sharingmoe_grouped_s2, 8 tokens, 30% sharedmoe_grouped_s2, 8 tokens, all sharedEnd to end, the gain is not measurable on the IQ3_S model: decode is 142.8 tok/s for v0.1.29 and 142.4 / 142.0 for this branch on the 23K prompt (137.5 / 136.9 against 138.1 / 137.0 on the 2.5K one), within the run to run noise. For that model the new kernels are reached through the MTP layer only. A Q2_0 model is where the verify window and the token graph use them, and none was available for this run.
Switch back
STRATA_OLD_GROUPED=1(ormoe_grouped_select_old(1)) selects the previous kernels.STRATA_GROUPED_PAIR_MIN_HITS=Nkeeps the previous per-hit kernels below N hits of capacity.Not tested
expert_parity,pool_testandple_paritycould not run.Unrelated, spotted while syncing
serve/server.pyrefuses an empty API key (STRATA_API_KEY=""or--api-key "") only afterStrataEngine(...)has loaded, so the user waits the whole load before exit code 2, andengine/visionare not closed. Moving that check right afterparse_args()fixes both.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.