mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #4859] [Engine] a 3-bit Lloyd-Max K/V (--kv oct3) with an exact fp16 window, and the gfx1100 decode ports #5217
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#5217
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/4859
Author: @destroyor
Created: 10/31/2026
Status: 🔄 Open
Base:
main← Head:pr/oct3-gfx1100📝 Commits (3)
ceea172KV: a 3-bit Lloyd-Max K/V (--kv oct3) with an exact fp16 window, and the gfx1100 (RX 7900 XTX) decode ports7e4ac0coct3: keep the prompt attention on the matrix cores. v0.2.10 retemplated SmemW and moved the int8 wmma path behind a k_q4 check, which left the 3-bit pools on the scalar loop: qsa attn 2747 ms over the standard suite, 16K prompt 32-44 % down. Port the oct3 kernel (Lloyd-Max levels, planes, the exact fp16 window) as prompt_attn_oct_kernel with its own shared vsb, taken when pools.oct3 is set; STRATA_PA_FAST picks the wide-register variant. gfx1100: qsa attn back to 486 ms, 16K prompt 3174 tok/s (parity with the deployed 0.1.55), bench sanity 12/12, 64K/250K needle 5/5.e243df3Docs: OCT3.md (the format, the exact window, the knobs) and PERF.md (the 7900 XTX numbers, the parity checksums, the gfx11 WMMA default), and the perf harness that produced them📊 Changes
54 files changed (+4333 additions, -129 deletions)
View changed files
📝
CMakeLists.txt(+21 -5)➕
docs/OCT3.md(+206 -0)➕
docs/PERF.md(+303 -0)📝
include/strata/core/expert_source.hpp(+1 -0)📝
include/strata/core/layer.hpp(+18 -0)📝
include/strata/core/verify.hpp(+4 -0)📝
include/strata/kernels/fused_gr.hpp(+8 -0)➕
include/strata/kernels/kv_exact_window.hpp(+73 -0)➕
include/strata/kernels/kv_octave.hpp(+86 -0)📝
include/strata/kernels/kv_stream.hpp(+1 -1)📝
include/strata/kernels/native_moe.hpp(+7 -0)📝
include/strata/kernels/native_router.hpp(+8 -0)📝
include/strata/kernels/qsa_decode_attn.hpp(+8 -0)📝
include/strata/kernels/verify_kernels.hpp(+4 -1)📝
include/strata/prefill/prefill.hpp(+4 -0)📝
metal/src/engine/stubs.cpp(+1 -1)➕
perf/README.md(+50 -0)➕
perf/harness/ctx_curve.py(+92 -0)➕
perf/harness/launch.sh(+11 -0)➕
perf/harness/win_decode.sh(+27 -0)...and 34 more files
📄 Description
The title must start with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other], for example "[Engine] fix decode stop on long prompts" or "[GUI] keep the model list after the tab switch".
Problem and result
An RX 7900 XTX (gfx1100) is the one RDNA branch
src/core/arch_defaults.cppskips: the matrix-core prompt set is gated on gfx1151 (Strix Halo), gfx1103 (the 780M) and gfx12 (RDNA4), so a discrete RDNA3 card runs the default path for everything. Two things fall out of that, both measured on one box:main(c62d5e3a,md5 e78294f3) and deployed: 3,464.5 / 3,517 tok/s prefill (+84%), 96K at 3,568 (+99%), decode median 109.5 tok/s with 23.23 ms a forward (from 24.91 / 25.55).That reproduces the numbers this branch measured before the rebase (3,467 / 3,517 prefill, 111.0 / 112.6 decode at 23.03 / 23.40): the rebuild on 170 newer commits cost nothing. One thing the re-test did catch is that the numbers depend on the unit's full environment - a launch that exported only part of it (no
GDN_*group,PF_F16,PF_HCDOWN,STAGER_RING) read 3,084 / 3,165 prefill and 99.9 decode tok/s on the same binary.ms per forwardLong-context stability at that setting, same day: 82 of 82 requests over 192K-202K contexts (single conversations of 6, 8 and 20 turns, then 2 x 12-turn and 3 x 8-turn concurrent conversations), on the pre-rebase build. RSS plateaus at 61.5 GiB for one conversation and 65 GiB for three under a 72 GiB cgroup, with no watchdog fire and no growth across 20 turns; an over-long request is refused with a clear 400 rather than truncated and the service stays up. A 200K prompt costs 60 s cold and 1.7-2.0 s a turn once the prefix is cached.
Re-test on the deployed build (2 Nov 2026)
Same card, same binary
md5 e78294f3(engine 0.1.55), measured with the repository's own suite (tools/strata_bench.py --runs 3 --long, the community benchmarkdocs/COMMUNITY_BENCHMARKS.mdpoints people at) rather than the 16-prompt harness:Prefill 32K is within 0.2% of the PR number on the deployed build. The decode rows are listed separately because they differ by suite and by acceptance rate, which swings 59-76% with the prompt text; they are not one comparable column.
Two notes from this pass.
--ple-io directon btrfs withcompress=zstdstalls the batched prompt attention at a chunk boundary: 32 of 59 threads sat in state D on__iomap_dio_rw, no layer was served for 60 s, and the engine ended itself (#29); the log holds three such stalls from production traffic the day before.--ple-io ramran six 128K/250K requests with no stall and the same 32K prefill speed, so the recipe below should readramon a compressed filesystem. Needle recall on oct3 at that setting: 32K 3/3, 128K 3/3, 250K 3/3; five code words at 10/30/50/70/90% came back 5/5 in order, twice at 64K and twice at 250K (242.8K tokens, 74-75 s).Rebuild on v0.2.10 (3 Nov 2026)
The branch is rebuilt on
ffa80d73(v0.2.10): three commits, the same 53 files, the same box; the rebase touched six files (CMakeLists.txt,src/core/verify.cpp,src/kernels/cuda/native_bf16.cu,src/prefill/prefill.cpp,src/program/generate.cpp,src/kernels/cuda/qsa_prompt_attn.cu). The first rebuilt binary lost 32-44 % of the prefill; there were two causes, both fixed:moe_fused.cu/moe_fused_iq.cu) compiles only with-DSTRATA_PREFILL_MMQ=ON; a plain build left the fused gate/up path off. Now built with it (the service setsSTRATA_PREFILL_MMQ=1to turn it on).7e4ac0c5): v0.2.10 retemplated the wmma path intoprompt_attn_wmma_body<SPLIT,GATE,RPF,TR>and gated its int8 entry onpools.k_q4 != nullptr, which the 3-bit pools never satisfy, and resolving the conflict took the upstream file wholesale. oct3 silently returned to the gather path: qsa attn 2,747 ms over the standard suite, 16K prefill 32-44 % down. The fix ports the oct3 matrix-core kernel asprompt_attn_oct_kernelwith its own sharedvsb(upstream'sSmemWTis untouched), selected whenpools.oct3is set - still opt-in (STRATA_PA_OCT=1, and on gfx11 it needsSTRATA_HIP_WMMA=1beside it as before;STRATA_PA_FAST=1picks the wide-register variant). qsa attn is back to 486 ms.Deployed and re-measured with the repository's own suite (
strata bench run --suite standard-v1, corpuse75eff8b, engine 0.1.56 on the v0.2.10 base), oct3 + the exact window + resident 65536, next to the upstream DFlash2 drafter (DFlash2 itself is upstream's, not in this PR; four rounds of MTP / DFlash2 / no-drafter A/B before deployment put DFlash2 +4-10 % on decode):Quality is unchanged at the long end: 64K needle 5/5 and 250K needle 5/5 (242,839 tokens, prefill 3,380 tok/s, decode 97.8). The production service runs this build with
--kv oct3 --kv-resident 65536andSTRATA_PA_OCT=1 STRATA_PA_FAST=1 STRATA_HIP_WMMA=1 STRATA_PREFILL_MMQ=1.Related discussion
None - no prior issue and no scope agreement. We read the rule and deliberately kept every part opt-in (one
--kvname, one env var per port) and leftarch_defaults.cppalone, so the default path and every default are untouched; that is why this went straight to a PR. If a maintainer would rather have an issue first, or wants this split (oct3 is one problem, the gfx1100 decode ports are another), say so and we will split it - see Limits.Approach
oct3 (
--kv oct3, opt-in) stores K and V as 3-bit codes on a Lloyd-Max grid over a 256-value block, behind the same Walsh-Hadamard rotation the repo's own rotated Q4_0 KV already ships, so<Hq,Hk> = <q,k>and the scores are untouched. 14 B per 32 values = 448 B a cell: 55% of k8v4, 78% of q4_0. The cells that carry the attention mass stay in fp16 in a per-layer ring of4 sinks + 1024 tailrows, each row carrying a 4-byte position tag, so a row a newer position has reused is a miss and never a wrong value. The window costs 24.1 MiB over 12 layers - 3.6% of what the same cells cost in an fp16 cache - and is not part of a snapshot, so every restore invalidates the tags.Why it is needed: 35-80% of the attention mass lands on a handful of recent cells, and their quantization error does not average out over a sequence. Quality against fp16 K/V on the same engine (
tools/quant_quality.py):At 256 tail cells oct3 already beats k8v4 at half the bytes. oct3 had no matrix-core prompt attention (the call refused it), so every oct3 prefill ran the chunk path:
STRATA_PA_OCT=1adds the arm, 2,280 / 2,304 -> 3,443 / 3,513 tok/s (32K / 96K), +51%, within 1-2% of--kv int8at 2.4x fewer bytes per cell, decode per forward unchanged. On gfx11 that arm needsSTRATA_HIP_WMMA=1beside it: after the rebase the matrix-core prompt attention defaults off on gfx11 (hip_wmma_mode_env()returns -1 and only gfx12 keeps the old default), and without it oct3 silently stays on the gather path (33,072 tokens at 2,995 against 3,464.5 tok/s).The decode ports (each its own env var, all off by default) close the gfx1100 gaps the default sets leave: a multi-column Q6_K x q8_1 GEMV (
STRATA_RDNA_Q6K, +3.5% decode), a two-launch hyper-connection read (STRATA_GR_RDNA, +4%), three window fusions (STRATA_COMBINE_CPU/STRATA_WAIT_FUSE/STRATA_ROUTE_PUBLISH, +2% once the window had shrunk),--pcie-frac 0(1.4 ms a window: the PCIe share's four expert nodes are empty at that ratio), the draft cumulative-probability floor for the MTP window (STRATA_SPEC_CUM=0.4, acceptance 60% -> 66% at the same cost a forward), and the q8_0 GEMV row policy. The 16-prompt median goes 95.60 -> 103.3 -> 112.6 on the pre-rebase build, and 109.5 tok/s at 23.23 ms a forward on the rebased build - the rebuild moved nothing.Two measurements we are reporting rather than acting on, because changing a default needs your call:
STRATA_SELECT_WMMAworks on gfx1100 (the kernel already accepts gfx11 throughgfx_arch_is_gfx11_wmma()) and is worth +16% prefill at 96K while selecting exactly what the warp scorer does (29,995 positions, top-1 100.00%, KL 0.00000) at no decode cost (23.54 ms a forward with it against 24.09 without, full env, one session per arm), so it stays opt-in and the deployment keeps it on; and the prompt switch group that gfx1151/gfx12 get by default is worth +22% at 32K and +29% at 96K here (1,864 -> 2,280 and 1,787 -> 2,304), with the batched prompt path keeping top-1 on all 20 prompts (mean KL 0.0170).Three config-only changes completed the picture, listed so the numbers above are reproducible:
--prefill auto:32768 -> 34816(a 33,065-token prompt crossed the chunk rule and paid a second full pass over the experts: 3,131 / 3,211 -> 3,467 / 3,517 on the pre-rebase build,wait copy461 -> 18 ms),--expert-cache autowith--vram-reserve-mib 512, and--kv-resident 131072(the deployment currently runs 65536, which is what a 33K-96K prompt needs).The deployment recipe (server config
argsplus the env the unit exports), for reproduce-ability:--kv oct3 --kv-resident 65536 --prefill 34816 --expert-cache auto --spec 4 --pcie-frac 0 --ple-io directand--vram-reserve-mib 512in bothargsanduser_args(argsis overwritten fromuser_argsat start, which cost us a day), withSTRATA_PA_OCT=1,STRATA_PA_FAST=1,STRATA_HIP_WMMA=1,STRATA_SELECT_WMMA=1, the six gfx1100 ports (STRATA_RDNA_Q6K,STRATA_GR_RDNA,STRATA_COMBINE_CPU,STRATA_WAIT_FUSE,STRATA_ROUTE_PUBLISH,STRATA_SPEC_CUM=0.4) and theGDN_CHUNKED/GDN_HEAD/GDN_CONVL2/GDN_NOY/GDN_PP=2,PF_F16=2,PF_HCDOWN,STAGER_RING=64group. Leave the last group out and the same binary reads ~12% lower prefill (3,084 / 3,165); the environment, not the rebuild, is what those numbers depend on.Sources we drew on (nothing here is unattributed): vLLM's Octave KV for the structure and for keeping the projection-preserving scale instead of the least-squares one; Max (1960) for the Lloyd-Max quantizer, whose 8-level fixed point we compute rather than tabulate; this repo's
kv_q4.hppfor the rotation oct3 reuses;nicejunjie/Strata-rdna3(branchrdna3,fc8f823) for the gfx1100 kernels and switches (rdna_mmvq.cu, its84b27e8two-launch read, the three fusions);android-imdad/Strata-7900xtx(02602e1) forSTRATA_SPEC_CUM, which we re-implemented for the MTP window; upstream PR #260 as prior art - measured here and not taken, its dense half loses to the tuned hipBLASLt tables (3,448 / 3,408 against 3,467 / 3,517 at 33K) and its attention half is whatSTRATA_HIP_WMMAalready does;halonc/R9700-Strata-Qwen3.8-Flash-Next-Tuningfor an independent 13.8 GB/s PCIe figure that matches our 13.5 GB/s probe.Validation
Environment for everything below: one Radeon RX 7900 XTX (gfx1100, 24 GB), Ryzen 9 9950X, 91.7 GiB RAM, no swap, EndeavourOS/Arch, ROCm nightly
gfx110x10.2.0a20261016, hipBLASLt 1.0.0.5, model Qwen3.8-Flash-Next GSQ-RCO abliterated IQ3_S (125B MoE / 6B active, 512 experts, 10 a token, MTP draft head). Revision: rebased ontoc62d5e3a(currentmain, 0.2.8), four commitsbe88ad74,843b70bd,43465eee,63c2f1e7; the deployed binary ismd5 e78294f3, built bycmake --build build-hip-oct3 --target strata -j12(CMAKE_HIP_ARCHITECTURES=gfx1100).Passed:
PATH=/opt/rocm/bin:$PATH HIP_PATH=/opt/rocm cmake --build build-hip-oct3 --target strata -j12- HIP/gfx1100 build clean after the rebase; one conflict, insrc/kernels/cuda/qsa_prompt_attn.cu(upstream's newSTRATA_QSA_STATblock against ourif constexpr (OCT)banner), resolved by keeping both.build-hip-oct3/hip_prompt_attn_wmma(ctest #21,src/kernels/qsa_prompt_attn_parity.cpp) - all 12 arms pass,FAILURES: 0, and every arm prints the same checksum as the pre-rebase build: int8aa99bad2..., oct3e7d4e8dc..., oct3+winddae871e.../a4e78832.... The oct3 arm agrees with the FP64 reference to 1.1e-9 of output scale, oct3+win to 3.1e-6 - 4.3e-6, against a 4.38x speedup over the chunk path (38.9 -> 8.9 ms).build-hip-oct3/kv_octave_parity(ok: device bytes are the reference's, MSE/coord 0.050756, rel L2 0.17498, 448 B a cell) andkv_exact_window_parity(ok: sinks kept, ring evicts in order, values exact) - both pass on the rebased build.python ab/tg_sweep.pyon the running service, new document and salt per request - 33,072 tokens at 3,464.5 and 3,440.1 tok/s, 99,412 at 3,568.1 (unit env; the reduced env read 3,083.9 / 3,114.4 / 3,164.6, and withoutSTRATA_HIP_WMMA2,995 / 2,839).perf/harness/win_tps2.py, 8 suffixes x 3, 160,000-character haystack) - 109.5 tok/s, 23.23 ms a forward, 71.0% acceptance, 0 cache misses, 0 stalls (unit env; the reduced env read 99.9 / 24.55).STRATA_SELECT_WMMAon against off, both under the unit's full env, one service restart and one session per arm - 23.54 ms a forward (113.8 tok/s, 71.2%) against 24.09 (107.05, 72.7%), so the switch costs no decode; the earlier 1.0 ms note came from the reduced env.python tools/quant_quality.py(and... compare) - the tables above; 29,995 positions for the oct3 rows, 4,995 for the head-to-head k8v4 row (pre-rebase build; the parity checksums above are how we know the rebase did not move the arithmetic). The stdinrunpath is bit for bit identical with the switch set off.python tools/needle_bench.py- 3/3 at 32K depths 10/50/90, 3/3 at 96K, 128K depth 50 found, 96K 3/3 on the deployed service (pre-rebase build).python ab/long_multiturn.py --tokens 210000 --turns 20(and the 2x and 3x concurrent runs) - 82/82 requests at 192K-202K, RSS plateau 61.5 / 65 GiB, service alive (pre-rebase build).Failed:
STRATA_PA_FAST=1with oct3 costs ~2 points of draft acceptance (66.3 / 66.6 / 68.1% against 68.9%) andSTRATA_PA_FAST=0gives it back at ~5% prefill (3,280 / 3,320); and upstream PR #260's dense WMMA path measured slower than the tuned hipBLASLt tables (3,448 / 3,408 against 3,467 / 3,517), which is why it is credited and not merged here.Not run:
kv_octave.cu/kv_exact_window.cuare compiled for HIP/clang only here; the CUDA path andmetal/src/engine/stubs.cpp(which we touched to keep the Metal build linking) are compile-unverified outside HIP, and we claim no NVIDIA behaviour.Limits
ms per forwardand the engine's own phase table are the comparable numbers, not tok/s across arms.STRATA_SELECT_WMMAis a prefill switch: +16.4% at 96K, and re-tested under the full env it costs nothing on decode (23.54 ms a forward with it against 24.09 without, one session per arm). The deployment keeps it because its work is prompts.be88ad74/843b70bd.docs/FORK-RDNA3-MAPPING.md, ~1,400 lines of what we measured and rejected, including ten negative arms closed with numbers) and the raw arm logs are not included; happy to add the diary if it is useful upstream.docs/PERF.md: an explicit--expert-cache Nis grown by the engine (7,700 became 9,148-9,200 slots) until the MTP draft head no longer fits (needs 213 MiB, 74 MiB is free-> exit 1, and withRestart=nothe service just stays failed); and--vram-reserve-mibis read from the server config'suser_args, so the same flag inargsis silently overwritten at start.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.