mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #5137] [Engine] sm_75: interleaved MMVQ for 5-8 row windows (kIlRows58_75) and a 5-8 column activation copy in 4-column planes (bitwise) #5321
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#5321
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/5137
Author: @xrip
Created: 11/3/2026
Status: 🔄 Open
Base:
main← Head:pr/il-planes-sm75📝 Commits (2)
81b2b53native_mmvq_il: 5-8 column position-major activation copy as two 4-column planes on sm_75 (IQ4_XS -16..-22 %, bitwise)a56e36fnative_mmvq_il: a 5-8 column rows table for sm_75 (kIlRows58_75)📊 Changes
5 files changed (+58 additions, -13 deletions)
View changed files
📝
docs/MMVQ_IL_TABLE.md(+4 -3)📝
include/strata/kernels/native_mmvq.hpp(+4 -1)📝
src/kernels/cuda/native_mmvq.cu(+22 -2)📝
src/kernels/cuda/q8_1_il.cuh(+24 -7)📝
src/kernels/mmvq_il_parity.cpp(+4 -0)📄 Description
Problem and result
On a Turing card with the interleaved MMVQ path on (
STRATA_SM75_IL=1, orSTRATA_SM75_PERF=1, which turns it on withkIlRows_75), verify windows of 5-8 rows run their dense projections onnative_mmvq's plain multi-column kernels:native_mmvq_il_rows_forhas rows for 5-8 columns only for the cards inkIl58Arch(sm_80, sm_120). On a CMP 50HX (sm_75) those plain kernels take 1.5-2.4x the interleaved ones at those widths (mmvq_il_parity --bench, 5 columns, cold weights, this PR's build):multi)Second, the interleaved kernels themselves waste half of each activation load at 5-8 columns for IQ4_XS. For CP = 8 an entry of the position-major copy (
pm) is 32 bytes, read as two 16-byte loads, and IQ4_XS's lanes read the same int of consecutive blocks, so each load uses half of every 32 bytes it touches. Nsight Compute, CMP 50HX, IQ4_XS 2560x10240, 2 rows a warp:STRATA_IL_PAD)lg_throttlestallThis PR, in two commits:
kIlRows58_75: Turing takes the interleaved kernels for 5-8 columns too (still only withSTRATA_SM75_IL=1/STRATA_SM75_PERF=1).Every output is bitwise the old one. In end-to-end decode on this box (
--spec 4, one stream) the change is within noise, because 5-8 column projections are a small part of a window there (see Limits).Related discussion
--spec 4, slower thanSTRATA_MMVQ_IL=0on 2x RTX 2080 Ti with--spec 3. This PR changes only launches of 5-8 columns, so windows of up to 4 rows (--spec 3) are untouched; it does not explain the 2080 Ti result. It also updates the stale sm_75 row ofdocs/MMVQ_IL_TABLE.mdthat #4962 points out.STRATA_SM75_PERFseries, which turns this path on for Turing.No scope agreement asked: a focused, bitwise change inside the opt-in Turing path. No default changes on any architecture.
Approach
81b2b532):kQ81IlPmPlanesis true only in sm_75 code (__CUDA_ARCH__ == 750). There the position-major copy of 5-8 columns ispm[2][8][nb][4], columns 0-3 then 4-7, in the same bytes (native_q8_1_il_bytesis unchanged). Writers:il_pm_atinnative_q8_1_interleave_kernelandnative_quantize_q8_1_il_kernel. Readers:Q81Il(PLANES,CS,qh();u,qbase,qat,QB,qp), which also serves theSTRATA_MMVQ_IL_PFvariants. Off sm_75qh()is the oldint4 and every kernel compiles to main's instructions (SASS compared below; the opt-in prefetch variants vary between builds of main too).pm: the block-major copy and the scales, which the K-quant kernels read, keep their CP-wide entries. A first version also splitbm; that made Q6_K slower (6144x2560 at 5 columns 52 -> 74 us): lanes that walk the positions of one block already read those 32-byte entries contiguously.a56e36fa):kIlRows58_75, read offMMVQ_IL_TMIN=5 mmvq_il_parity --bench --emit-tablethree times on the planes build. The runs agreed except Q4_K at 5 columns below 2048 rows (2, 0, 2), which is 0 in the table.mmvq_il_parity's table check pins two of its cells.docs/MMVQ_IL_TABLE.mdsays what sm_75 runs.STRATA_SM75_IL=1orSTRATA_SM75_PERF=1; other CUDA architectures compile the old instructions (SASS compared below); HIP never sees this code (q8_1_il.cuhand these kernels are under#if !defined(__HIPCC__)); SYCL and Metal have their own sources.Validation
Revision tested:
c4b8258bagainstffa80d73(main at the time); the branch heada56e36fahas the same tree (one commit message reworded). Some kernel numbers come from the first commit's earlier form4d2c5774, which differs only inqh()'s type off sm_75 (labelled). Box: 2x NVIDIA CMP 50HX (sm_75, 56 SMs, 20,480 MiB; not stock: unlocked to full speed by the owner's driver, 170 W limit, SM clock up to 2,295 MHz), driver 610.43.03, CUDA 13.3 (V13.3.73), GCC 14.2, Ubuntu 24.04.4, kernel 7.2.9-cmp50hx, build-DCMAKE_CUDA_ARCHITECTURES=75 -DSTRATA_ISA_FLOOR=avx. GPU timings with the box's idle clock governor stopped; GPUs 0/1 only.Passed:
Build, CUDA sm_75:
cmake --build build --target strata mmvq_il_parity -j 16atc4b8258b(rc 0);--target mmvq_il_parityatffa80d73(rc 0).Bitwise, GPU 0,
c4b8258b:STRATA_SM75_PERF=1 build/mmvq_il_parityandSTRATA_SM75_PERF=1 build/mmvq_il_parity --pf 0,1,2,3,4,5,6both end withmmvq_il_parity: OK (every case, T 1-8, rows 1/2/4 and the table, bitwise), which includes the newkIlRows58_75check;build/mmvq_il_paritywithout the switch: the same line (4d2c5774).Other architectures: a tree configured with
-DCMAKE_CUDA_ARCHITECTURES="75;80;86;89;120",make src/kernels/cuda/native_mmvq.cu.oatc4b8258b(and at4d2c5774): rc 0, no errors, SASS for all five. SASS against main's object, per function (1,005 functions, label numbers normalised,cuobjdump -sass): sm_120 identical in every function; sm_80 / sm_86 / sm_89 identical except 11 / 9 / 10 instances ofnative_mmvq_il_pf_kernel(the opt-inSTRATA_MMVQ_IL_PFvariants). Those instances are not deterministic from build to build: two builds of unchanged main (ffa80d73, sm_80 only, ccache off) differ in 8 of them as well, and in nothing else. sm_75 differs where this PR changes code (59 functions).HIP view:
native_mmvq.cuwith the__HIPCC__conditionals resolved (other conditionals kept, includes not expanded) is byte-identical atffa80d73andc4b8258b: 2,685 lines, md5b59740ec20c7b21789cb8bbe86d5cef5;q8_1_il.cuhandil_pm_atare not in it.native_mmvq.hppchanges only in a comment.Kernel timing, planes:
STRATA_SM75_PERF=1 MMVQ_IL_TMIN=4 MMVQ_IL_TMAX=6 mmvq_il_parity --bench --rounds 3, theffa80d73and4d2c5774binaries alternated 3 times in one script on GPU 0 (cold weights, the tool's default; the best of rows 1/2/4 per cell, us per call, the three runs):ffa80d73(us)4d2c5774(us)The K-quants and every 4-column cell run identical code in both binaries: K-quants at 5-6 columns -1.3..+2.7 % (median 0.0 %, 34 cells); across all 57 identical-code cells the median change is 0.9 %, with one bimodal cell (Q4_K 2560x10240 at 4 columns: 40.2, 39.0, 46.4 against 37.0, 47.6, 48.1 us), which is this bench's run-to-run spread.
Table:
STRATA_SM75_PERF=1 MMVQ_IL_TMIN=5 MMVQ_IL_TMAX=8 mmvq_il_parity --bench --emit-table, three runs on the planes build: the 5-8 column block the same in every cell but one (above).Engine, layer split on GPUs 0/1, Qwen3.8-Flash-Next Swift 1.5 GSQ-RCO IQ3_XXS,
--spec 4 --spec-min-p 0.5 --mtp ... --kv int8 --kv-resident 32768 --pool-workers 19 --expert-cache auto --prefill auto,STRATA_SM75_PERF=1 STRATA_BF16_TC=1 STRATA_EXP_MODE=8; workload: a ~7.8K-token code prompt, then 6 questions on it, 512 greedy tokens each (the prefix reused), a fresh server per run with the page cache dropped; arms alternated A B C C B A A B C, 6 answers a run:4d2c5774; 5-8 columns on the plain kernels, as main)c4b8258b)ffa80d73+kIlRows58_75)No error in any run; windows of 1 to 6 rows were captured. The differences are within this box's spread (about +-1.5 % between rounds). Nsight Systems with graph nodes on arm B, the same workload: the interleaved kernels at 4 columns took ~3.9 s of GPU time, at 6 columns ~0.6 s (now interleaved: Q6_K 241 ms, Q5_K 165, IQ4_XS 104, Q4_K 103), no 5-column launch; so the 5-8 column projections are ~0.6 ms of a ~29 ms window in this workload.
Failed:
None observed. (A
g++ -E -undef -D__HIPCC__preprocessing ofnative_mmvq.cufailed on both revisions alike, the system headers need the predefined macros; the conditional check above replaced it.)Not run:
--batch 2on a layer split the slots run as pipelined groups of one row, so that is not one here; a single Turing card with batch slots, or longer drafts, would be.mmvq_il_parity's check of every case.Limits
--spec 4and one stream the 5-8 column projections are ~2 % of a window's GPU time, and arms A / B / C agree within noise. The gain is per launch of 5-8 columns (above); setups whose windows are mostly 5-8 rows gain more, unmeasured here.STRATA_MMVQ_IL_WIDE=0turns the 5-8 column path off.pm).🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.