mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #3455] [CLOSED] [Engine] GP100 (sm_60): 4-bit slots for resident IQ2_S / IQ3_XXS / IQ3_S gate/up experts, decode +9.7% (opt-in, STRATA_EXPERT_NIBBLE=1) #4642
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#4642
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/3455
Author: @ruibeikaa
Created: 10/20/2026
Status: ❌ Closed
Base:
main← Head:nibble-experts📝 Commits (9)
9fb2dc6expert_nibble: the 4-bit gate/up expert slot contract (STRATA_EXPERT_NIBBLE, default off)fbdd7e6iq_kernels: decode gate/up on 4-bit slots, the load-time transcoder, the GGUF rebuild and the slot hash (STRATA_EXPERT_NIBBLE, default off)8dd0c07prefill: the prompt MMQ gathers a 4-bit expert slot as its rebuilt GGUF blocks (STRATA_EXPERT_NIBBLE, default off)8ead944generate: load converted gate/up experts as 4-bit slots, refuse what would read or write them as GGUF (STRATA_EXPERT_NIBBLE, default off)eab2d47parity: the 4-bit gate/up slots against the production kernels and the GGUF blobs; native_expert_bench --nibble (STRATA_EXPERT_NIBBLE)d4f167ddocs: OLDER_GPUS.md - GP100's 4-bit gate/up expert slots (STRATA_EXPERT_NIBBLE=1, opt-in)cb9cf4ddocs: OLDER_GPUS.md - a PH402 GP100 die has 32 GB of HBM2, not 166fb4f38nibble: a gate/up kernel that stages a group's activations once per two row blocks (STRATA_NIB_GU_PROTO=1, opt-in)282bd66docs: OLDER_GPUS.md - STRATA_NIB_GU_PROTO=1, the staged-once 4-bit gate/up kernel (opt-in)📊 Changes
15 files changed (+3552 additions, -34 deletions)
View changed files
📝
CMakeLists.txt(+11 -0)📝
docs/OLDER_GPUS.md(+43 -0)📝
include/strata/core/expert_cache.hpp(+9 -0)➕
include/strata/core/expert_nibble.hpp(+457 -0)📝
include/strata/kernels/iq_kernels.hpp(+14 -1)📝
include/strata/prefill/prefill.hpp(+5 -0)📝
src/core/expert_cache.cpp(+17 -0)📝
src/core/expert_source.cpp(+7 -0)📝
src/core/verify.cpp(+15 -4)📝
src/kernels/cuda/iq_kernels.cu(+922 -6)➕
src/kernels/cuda/nib_gu_proto.cuh(+137 -0)➕
src/kernels/iq_nibble_parity.cpp(+915 -0)📝
src/kernels/native_expert_bench.cpp(+420 -0)📝
src/prefill/prefill.cpp(+57 -0)📝
src/program/generate.cpp(+523 -23)📄 Description
Problem and result
On a GP100 die (Tesla P100, PH402: compute capability 6.0, no
__dp4a, no tensor cores) the decode gate/up kernels for the i-quant expert formats are nowhere near the memory wall: measured in isolation on one die at T = 1, IQ2_S reads its 1.05 MB expert in 10.2 us (~103 GB/s of the 732 GB/s HBM2), IQ3_XXS 1.25 MB in 10.0 us, IQ3_S 1.41 MB in 12.5 us. The time is the per-block serial chain (unpack the codebook indices from the packed grid, the emulated dp4a, the 16-lane reduction), not the bytes: the same kernel with every dot product removed still takes about two thirds of its time.With
STRATA_EXPERT_NIBBLE=1the engine, after the cache is filled and the residency is final, transcodes the gate/up blocks of every fully resident IQ2_S / IQ3_XXS / IQ3_S layer into a slot layout of 4-bit codes (one codebook index per nibble, the scales as they are; the down projections untouched) and the verify window's gate/up step reads those slots. The arithmetic order is the unchanged kernels' order, so the outputs are the same bits. On four GP100 dies decode goes 47.3 -> 51.9 tok/s (+9.7%, token-weighted over eight prompts, each +9.5..+10.9%), prompt reading is 2.3..3.0% slower, and every reply is bit for bit the unchanged engine's. Unset (the default) nothing changes: the 410 kernels the unchanged engine has iniq_kernels.cuhave the same SASS with and without the change, in the sm_60 and the sm_86 builds, and the switch-off arm's replies and state hashes equal the unchanged engine's.Related discussion
Scope issue: #3454 (opened together with this PR; maintainer agreement pending). The GP100 kernels this builds on: #1424. The fusions in
fuse_decode.hpp(#1097) show the gating used here.Approach
include/strata/core/expert_nibble.hpp: the slot contract (per-format code layout, the per-layer on/off table, the slot byte sizes).src/kernels/cuda/iq_kernels.cu: the load-time transcoder (one kernel per format), the slot hash, the GGUF rebuild kernel, and the 4-bit gate/up kernels (R4S for IQ3_XXS, R4P for IQ2_S, R4SV / R4PX for IQ3_S by group size).native_expert_groupedonly swaps its gate/up step for a converted layer; SwiGLU, Hadamard and the down projection stay on the engine's default path (mode 8 on GP100). No signature changes, so the SYCL and Metal definitions are untouched.src/core/verify.cpp: the converted layers' layout is picked for the window graph (nib_layout(L)); the S26, fused, GU_SWIGLU, LDS and AMD branches are skipped for those layers.src/prefill/: the prompt path is unchanged. Its MMQ gather rebuilds the GGUF blocks from a 4-bit slot on the fly (nib_gguf_kernel), so the prompt kernels read exactly the bytes they read today. At load every converted slot is rebuilt once and compared byte for byte with the staged GGUF blob before the slot is sealed.src/program/generate.cpp: the transcode after the residency is final; the VRAM accounting (the converted slots are sized intosized_slots); a start-up refusal, with a message, of every option that would read or write a converted slot as GGUF bytes:STRATA_MMQ_DIRECT, partial residency, the adaptive and PCIe tiers,--mmap-experts/STRATA_ARENA_MMAP,STRATA_RAM_ADAPT,STRATA_HC_Q8uploads,--peer-device, a prompt chunk below the auto ceiling or a loaned slot.STRATA_EXPERT_NIBBLE_SKIP=<layers>andSTRATA_EXPERT_NIBBLE_FMTS=<types>narrow the conversion;STRATA_EXPERT_NIBBLE_RECHECK=1(debug) hashes every slot again after each request.src/kernels/iq_nibble_parity.cpp,native_expert_bench --nibble: the parity and timing tools.docs/OLDER_GPUS.md: the section under the GP100 kernels.STRATA_EXPERIMENTAL_SM60(CUDA only, not HIP, not Metal); a build without it carries no 4-bit kernel.Validation
Environment note: everything below was measured with every expert resident in VRAM (four dies, 128 GB in all, the Swift 1.5 IQ3_S pack fits whole; no CPU share, no PCIe share, no adaptive tier). A card that holds its experts partly in RAM was not measured, and the switch refuses to convert a layer that is not fully resident, so on such a card the engine keeps the GGUF slots and nothing changes.
Rig: PH402 SKU 200 x2 (four GP100 dies, 48 SMs and 32 GB HBM2 each, application clocks 715 / 1050 MHz), Windows 11, driver 581.80 (TCC), CUDA 12.9, VS 2022; build
-DSTRATA_EXPERIMENTAL_SM60=ON -DCMAKE_CUDA_ARCHITECTURES=60, ggml at the pinned 3cf03257f. Revision: maine88ee39d(engine 0.1.45.3) + this branch. Model: Swift 1.5 IQ3_S (abliterated GSQ-RCO GGUF), 1M context,--layer-split 12,24,36 --trim-stage-weights --pipeline-windows 2 --spec-min-p 0.85, MTP, every expert resident, conversation cache on, the same launcher for every arm; the unchanged engine is the same revision built the same way.Passed:
iq_nibble_parity <shard> --layers-per-fmt 2on one die: PASS, 6 layers + 3 synthetic formats, 0 differences (gate, up, h, hq and the combined output against the unchangednative_expert_groupedin mode 0 and in the card's default mode 8; the rebuilt GGUF blocks byte for byte the blobs).--negative(a deliberately corrupted slot): FAIL with 264,813 differences, exit 1.STRATA_STATE_HASH) equal for the live state (GDN, PLE, tail, pooled, KV, MTP) on every request; N1'sSTRATA_EXPERT_NIBBLE_RECHECKclean after every request. N1 converted 47 of 48 layers (IQ2_S 20, IQ3_XXS 17, IQ3_S 10), +12.70 GiB.STRATA_EXPERIMENTAL_SM60(strata, iq_nibble_parity, native_expert_bench) and sm_86 without it;cuobjdumpshows the unchanged engine's 410 kernels iniq_kernels.cuwith identical SASS in both, and no 4-bit kernel in the sm_86 build.Failed: none observed.
Not run: HIP (gfx906, wave32), SYCL and Metal builds (no such machine here; the new code is under
STRATA_EXPERIMENTAL_SM60and CUDA-only guards, andverify.cpp's new references are guarded for the Metal build of the CUDA tree). A single Tesla P100 (one die, partial residency: the switch refuses and the GGUF slots stay). Other packs (IQ3_XXS, IQ2_XS) on this engine.STRATA_MMQ_TABbuilds (STRATA_MMQ_DIRECTis refused at start).Limits
STRATA_EXPERIMENTAL_SM60; the kernels compile for other archs but were measured on GP100 only, and only in the all-experts-in-VRAM setup described above (a single 16 GB P100 with experts partly in RAM gets nothing from this change today).STRATA_EXPERT_NIBBLE_SKIPnarrows the set).STRATA_DUMP_FIRST_LOGITS) does not write under--pipeline-windows, so the parity evidence is the reply hashes, the state hashes and the slot re-hash, not a logits file.Addendum (2026-10-23): a faster 4-bit gate/up kernel,
STRATA_NIB_GU_PROTO=1(opt-in, default off)Two more commits on this branch.
src/kernels/cuda/nib_gu_proto.cuh(nibx_gu_kernel<TG, 2>) runs a converted layer's decode gate/up with the same row dot as the 4-bit kernel above (nib_row_dot_sis called as it is: same lanes, items, integer chain and float order) and changes only how the activations reach shared memory: a block takes two 16-row blocks of one group and stages the group's q8_1 rows once, as 16-byte loads all issued before the stores. In the existing kernel the staging is a word loop with a serial load -> store chain between two barriers; on a GP100 die that chain, not the weight bytes, was the largest part of a launch. It needsSTRATA_EXPERT_NIBBLE=1; unset, nothing changes. The second commit is a bullet indocs/OLDER_GPUS.md.Environment note: PH402 SKU 200 boards, four GP100 dies of 32 GB HBM2 each (128 GB in all), every expert resident in VRAM, no CPU share, no PCIe share. The single-die numbers below use one of those dies (715 / 1050 MHz).
Bitwise, one GP100 die, this branch:
iq_nibble_parityitem (7) with three new arms (the new kernel in the card's mode, in mode 0, in mode 0 + V1), Swift 1.5 IQ3_S and IQ3_XXS,--layers-per-fmt 2 --ne 512 --plans 8 --synthetic 64: PASS, 12 layers + 3 synthetic formats, 0 differences.native_expert_bench --nibble <IQ3_S shard> 1,0,17 --t 1,2,3,4 --share 0,50 --plans 200 --vs 31: every gate and up row of every plan byte for byte equal to the existing 4-bit kernel's, at all 24 points.Per layer, gate/up only, one GP100 die, this branch (Swift 1.5 IQ3_S layers 1 / 0 / 17; 200 routing plans per point, 7 interleaved trials, median us per launch; existing 4-bit kernel -> new kernel):
Default off:
cuobjdumpofiq_kernels.cu, sm_60 build: the 428 kernels this branch had before the commit have identical SASS after it; the threenibx_gu_kernelinstances are the only additions. The sm_86 build withoutSTRATA_EXPERIMENTAL_SM60has none of them (410 kernels) and builds clean.End to end, four GP100 dies, not this branch's revision: engine 0.1.47 (main
011c9e60) plus 26 opt-in GP100 commits of mine (this PR's 4-bit slots on 47 of 48 layers, #3752 with a 4-bit variant of its gate/up,--pipeline-windows 3and others not posted), expert mode 0 (STRATA_SM60_TABLE=0) in both arms, Swift 1.5 IQ3_S, one fresh engine per arm, eight decode prompts token-weighted: 57.53 -> 59.06 tok/s (+2.65%), each prompt +2.4..+2.8%. Reply hashes and draft acceptance identical on all 9 requests; prompt reads within 0.1%. One run per arm.Not run: HIP, SYCL and Metal builds (no such machine here; the kernel sits inside this PR's
STRATA_EXPERIMENTAL_SM60CUDA-only block). A single P100 with experts partly in RAM (the 4-bit slots are refused there, so this kernel never runs). An end-to-end run on this branch's own revision.CI note: the red
metal-linkcheck is not caused by this PR. The job fails while compiling upstream'smetal/src/mtl_rt.mm(lines 69 and 92:MTLGPUFamilyMetal4,MTLCompileOptions.mathMode,MTLMathModeFast/MTLMathModeSafe), which themacos-14runner's SDK does not provide. The workflow runs on any pull request that touchessrc/orinclude/; this PR changes no file undermetal/.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.