mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #4942] [CLOSED] [Engine] Interleaved MMVQ (native_mmvq_il) for IQ3_S/IQ3_XXS and HIP/gfx12 (1202) tables #5258
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#5258
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/4942
Author: @bsorensen110
Created: 11/1/2026
Status: ❌ Closed
Base:
main← Head:pr/mmvq-il-iq3-tables📝 Commits (5)
0a0b9d2HIP gfx12: build the interleaved mmvq path on HIP; key RDNA4 as 1202 with measured R9700 tables297b9bcHIP gfx12: interleaved mmvq for IQ3_S and IQ3_XXS on RDNA4 (single accumulator, n_in <= 4096)0168cf9test(hip,cuda): quantize_il_parity - fused quantize+interleave vs the pair, byte for bytefdc596aperf(hip): enable fused quantize+interleave (native_quantize_q8_1_il) on gfx12 & document 1202/IQ3 tablesa8b70f7Address review: IL off on gfx906 wave64, plain path on unmeasured HIP, n_in in IL support check, quote HIP header path📊 Changes
9 files changed (+557 additions, -60 deletions)
View changed files
📝
CMakeLists.txt(+70 -9)📝
docs/MMVQ_IL_TABLE.md(+4 -3)📝
include/strata/kernels/native_mmvq.hpp(+3 -2)📝
metal/src/engine/mmvq_host.cpp(+1 -1)📝
src/core/verify.cpp(+25 -9)➕
src/kernels/cuda/iq3_grid.inc.h(+101 -0)📝
src/kernels/cuda/native_mmvq.cu(+215 -29)📝
src/kernels/mmvq_il_parity.cpp(+39 -7)➕
src/kernels/quantize_il_parity.cpp(+99 -0)📄 Description
Problem and result
Before this change:
native_mmvq_il,native_quantize_q8_1_il,native_q8_1_interleave) insrc/kernels/cuda/native_mmvq.cuwas compiled out under#if !defined(__HIPCC__), with HIP stubs throwing or returningfalse, andil_cc()had no architecture key separating AMD RDNA4 (gfx1200/gfx1201, which reports compute capability12.0with 32 wave32 CUs) from NVIDIAsm_120(120).native_mmvq_ilonly supportedIQ4_XS(23),Q4_K(12),Q5_K(13),Q6_K(14), andQ3_K(11). Models whose dense projections useIQ3_S(21) orIQ3_XXS(18) always fell back tonative_mmvqon every backend, andmmvq_il_parity --bench --emit-tablecould not measure or emitIQ3_S/IQ3_XXSrows for any card.With this change:
IQ3_S(21) andIQ3_XXS(18) kernels (IlIQ3S,IlIQ3XXS,src/kernels/cuda/iq3_grid.inc.h,src/kernels/cuda/native_mmvq.cu):Iq3XxsBlock(98 B) andIq3SBlock(110 B) traits (Iq3XxsIlTraits,Iq3SIlTraits) on the sharednative_mmvq_il_kernelfor both CUDA and HIP, reading the 2-byte-aligned weight words viaiq3_int_b2and theiq3xxs_grid[256]/iq3s_grid[512]codebooks (src/kernels/cuda/iq3_grid.inc.h, copied token-for-token fromthird_party/ggml/ggml-common.h:1017-1117).kIlSingleStream<IlIQ3XXS> = true,kIlSingleStream<IlIQ3S> = true) so floating-point contraction matchesnative_mmvq'sSplit<18>/Split<21>baseline bit-for-bit across all tested shapes (n_in <= kIq3IlMaxNIn = 4096). A 4-stream accumulator failed bitwise parity atn_in >= 2560(337 FAIL lines) and measured 6.9–18.0% slower on table-selectedIQ3_Sshapes (n_in = 2560,T = 5, 7, 8).mmvq_il_parity(CASES[]andemit_table()forti < 7) sommvq_il_parity --bench --emit-tablebenchmarks and emitsIQ3_S(21) andIQ3_XXS(18) rows alongsideIQ4_XS/Q4_K/Q5_K/Q6_K/Q3_Kon any CUDA or HIP card.native_mmvq_ilcompilation & RDNA4 (1202) measured tables (src/kernels/cuda/native_mmvq.cu,src/core/verify.cpp,CMakeLists.txt):native_mmvq_il_kernel,native_quantize_q8_1_il,native_q8_1_interleave) on HIP while keeping the PTX-only prefetch variants (native_mmvq_il_pf_kernel,mad.wide.u32/ld.global.nc) gated behindSTRATA_IL_PF(1on CUDA,0on HIP).cc == 120(gfx12) to architecture key1202inil_cc()so RDNA4 never collides withsm_120, and populateskIlRows_1202(T = 2..4),kIlRows58_1202(T = 5..8), andkIl1Rows_1202(T = 1) from two independentmmvq_il_parity --bench --emit-tableruns on a Radeon AI PRO R9700 (gfx1201, 32 wave32 CUs), keeping a cell only where both runs agree and every shape in the class beatsnative_mmvqby >= 3% (else0).qil_on()(native_quantize_q8_1_ilfused quantize + interleave for 2–4 column projection inputs inVerifier::record_window) ongfx12(STRATA_QIL=0|1) and addsquantize_il_parity(CTest) to verify byte-for-byte identity againstnative_quantize_q8_1+native_q8_1_interleave.Related discussion
Follows up on #3453, #3779, and #3999 (per-architecture
native_mmvq_iltables indocs/MMVQ_IL_TABLE.md), extendingnative_mmvq_ilandmmvq_il_parity --bench --emit-tabletoIQ3_S(21) andIQ3_XXS(18) and adding HIP / RDNA4 (1202) support.Approach
native_mmvq:IlIQ3XXSandIlIQ3SreplicateSplit<18>andSplit<21>fromiq_kernels.cuand accumulate in chunk order intoacc[0][i][c](kIlSingleStream<I>), producing bitwise-identicalfloatoutputs tonative_mmvqacrossT = 1..8androws = 1, 2, 4.kIlRows_1202,kIlRows58_1202,kIl1Rows_1202): matchingkIlRows_89,mmvq_il_parity --bench --emit-tablewas run twice ongfx1201(cold cache, 192 MB rotation). Any cell that disagreed between run 1 and run 2 (two K-quant cells and six IQ3 cells) was zeroed so uncertain shapes stay onnative_mmvq.il_cc()keys (61,80,86,89,120,1201) and their tables have no18/21entries yet, soil_rows()returns0forIQ3_S/IQ3_XXSon those cards until measured withmmvq_il_parity --bench --emit-table(or tested immediately viaSTRATA_MMVQ_IL_ROWS="21:...").Validation
Passed:
fdc596a7branched fromorigin/main(c62d5e3a15b40ea51c96aae9e8d36928965f53ab, Strata0.2.9) on Linux7.3.0-2-cachyos-server(AMD Radeon AI PRO R9700gfx120132 GB VRAM, ROCm10.2.0a20260914, 64 GB RAM):cmake -S . -B build-hip -DCMAKE_BUILD_TYPE=Release -DSTRATA_ENABLE_HIP=ON -DSTRATA_BUILD_TESTS=ON -DCMAKE_HIP_ARCHITECTURES=gfx1201 && cmake --build build-hip --target mmvq_il_parity quantize_il_parity strata -j16->Built target mmvq_il_parity,Built target quantize_il_parity,Built target strata(0 errors).ctest --test-dir build-hip --output-on-failure -V -R '^(mmvq_il_parity|quantize_il_parity)$':mmvq_il_parity:mmvq_il_parity: OK (every case, T 1-8, rows 1/2/4 and the table, bitwise)(1.51 sec, 0 FAIL lines across all 50 cases including 18IQ3_SandIQ3_XXSshapes +check_tables()forsm_60/70/80/86/89/120/1202).quantize_il_parity:ALL PASS(0.10 sec, 45/45 cases acrossn_in = {32, 2560, 4096, 8192, 10240},ncols = 2..4, 3 seeds each,0bytes differing in both plainq8_1and interleaved buffers).gfx1201(./build-hip/mmvq_il_parity --bench --emit-table, cold cache with 192 MB rotation, 2 independent runs):IQ3_S(type 21) &IQ3_XXS(type 18) best shape gains vsnative_mmvq(run 1 / run 2):T=2:IQ3_S2560x10240(rows=1) +5.7% / +5.3%T=3:IQ3_S4096x640(rows=1) +9.0% / +7.5%;IQ3_XXS2560x6144(rows=1) +3.6% / +3.1%T=4:IQ3_S4096x640(rows=1) +12.5% / +11.1%;IQ3_XXS2560x6144(rows=1) +8.4% / +9.1%T=5:IQ3_S2560x12288(rows=2) +7.4% / +6.6%;IQ3_XXS2560x12288(rows=2) +12.2% / +10.9%T=7:IQ3_S2560x512(rows=1) +25.0% / +23.8%;IQ3_XXS2560x512(rows=1) +25.6% / +25.6%T=8:IQ3_S2560x12288(rows=2) +23.1% / +23.1%;IQ3_XXS2560x512(rows=1) +22.8% / +22.8%IQ4_XSgains ongfx1201(kIlRows_1202/kIlRows58_1202, run 1 / run 2):Q5_KLM head2560x248320:T=3-48.1% / -48.1%,T=4-48.7% / -48.8% (1713.2 -> 878.6 us),T=5-40.8% / -40.4% (1967.6 -> 1164.2 us),T=8-36.7% / -36.5%IQ4_XS2560x10240:T=4-23.6% / -23.0%,T=8-39.0% / -38.7%Q3_K2560x10240:T=4-28.3% / -28.5%,T=8-41.5% / -41.4%Q6_K2560x12288:T=4-25.6% / -25.6%,T=7-36.5% / -36.1%gfx1201(IQ3_Sdense projections,--mtp --spec 8 --mmap-experts, 2 interleaved rounds of 10 greedy 512-token requests after 3 warmups,STRATA_MMVQ_IL=0vsSTRATA_MMVQ_IL=1):STRATA_MMVQ_IL=0: round medians155.65,163.50 tok/s, pooled median160.95 tok/s(n = 20).STRATA_MMVQ_IL=1: round medians171.40,171.20 tok/s, pooled median171.20 tok/s(n = 20, +10.25 tok/s / +6.4%, 95% bootstrap CI+8.2to+14.7 tok/s).Failed:
Not run:
nvccCUDA build and runtimemmvq_il_parity --bench --emit-tablesweep forIQ3_S/IQ3_XXScells on NVIDIA GPUs (host is a single-GPU AMDgfx1201machine; CUDA preprocessor token diff was verified viaclang++ -Ewith__HIPCC__undefined).gfx1200hardware measurement (shares key1202withgfx1201).Limits
IQ3_S(21) andIQ3_XXS(18) takenative_mmvq_ilonly whenn_in <= kIq3IlMaxNIn(4096), matching the parity-tested range; wider inputs fall back tonative_mmvq.1202(gfx12) populatesIQ3_SandIQ3_XXSrows in the built-in tables so far; other architectures keep0(native_mmvq) for types18and21until measured withmmvq_il_parity --bench --emit-tableor overridden viaSTRATA_MMVQ_IL_ROWS.STRATA_MMVQ_IL=0to disable the interleaved MMVQ path orSTRATA_QIL=0to disable fusednative_quantize_q8_1_il.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.