mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #2698] [CLOSED] qwen35/q36: --kv - int8 K/V caches (codes + a FP16 scale per 64 values) #4219
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#4219
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/2698
Author: @TorBere
Created: 10/15/2026
Status: ❌ Closed
Base:
main← Head:q36-kv-int8📝 Commits (2)
3c3bc04qwen35/q36: --kv fp32|int8|k8v8|k8v32|k32v8 - int8 K/V caches (codes + a FP16 scale per 64 values)d85b465qwen35/q36: the int8 KV decode reads vectorized (uint2 K loads, a per-block V weight table)📊 Changes
1 file changed (+191 additions, -31 deletions)
View changed files
📝
src/qwen35/q36_engine.cu(+191 -31)📄 Description
Implements the int8 K/V cache for the q36 (qwen35moe) engine's own attention path as
--kv(strata's namefor the stores:
fp32default,int8for both stores,k8v32/k32v8for one of the two). The q36 cacheswere FP32 (2 KiB per cell per store), so a 128K context ran out of VRAM for expert slots: 0/256 experts in
VRAM, 34 tok/s. This is the same effect issue #2464 reports for the V100 (the q36 decode falling from 154 to
56 tok/s as the context fills; llama.cpp quantizes the cache, this engine does not).
What it does
--kv int8: K and V stored as int8 codes with one FP16 scale per 64 values (group absmax / 127), ~3.9xsmaller cache (528 B/cell vs 2048 B at head_dim 256);
k8v8is an alias;k8v32/k32v8quantize onestore only;
fp32(the default) runs bit for bit the old kernels.STRATA_Q36_KV=int8stays as the environment fallback (--kvwins).k_attn_part), prompt chunk (k_kv_f16-> cuBLAS) and the MTP block dequantize on the fly; theverify windows go through the same kernels, the commit/rollback of the cache is unchanged.
k_attn_prep/k_attn_part/k_kv_f16aretemplate <bool KI8, bool VI8>; a smallkv4()dispatcherin
Enginelaunches the right specialization, sokc/vcstay FP32 pointers and the int8 codes + scaleslive in
kc8/vc8/ks8/vs8.kKVG = 64;head_dimmust be a multiple of it (the host says so and staysFP32 otherwise).
Measurements
RTX 3060 12 GB, Qwen3.6-35B-A3B UD-Q4_K_XL (experts 18.75 GiB, streaming),
--mtp 2, same machine, tworuns each, 120 tokens per run:
--kv int8At 128K the freed VRAM (~4 GiB) brings 31 experts back into the VRAM, which is where the +53% comes from.
The FP32 build reproduces the installed engine (50.1 vs 50.3 / 33.9 vs 35.8), so the difference is the patch,
not the toolchain.
Needle-in-the-haystack, 52.8K-token prompt, 128K mode, max_tokens 250, temperature 0: both FP32 and int8
find the hidden number; the int8 run took 91 s vs 159 s end to end (1.75x). A chat answer at the same
context is qualitatively equal between the two.
--kv k8v32/k32v8smoke tested at 64K: each quantizes one store, so they land between FP32 and int8 —32 experts in VRAM (FP32: 18, int8: 46) and 54.8 / 53.8 tok/s (FP32: 50.1, int8: 59.7).
Not in this PR
--kv q4_0andk8v4(PR #21's Hadamard rotation over head_dim 256) are not wired into the q36 kernelsyet;
--kvrefuses them with a note. The FWHT-256/Q4_0 pieces already exist in the repo(
src/kernels/cuda/kv_q4.cu,include/strata/kernels/kv_q4.hpp), so a follow-up can add them the same way(rotate K after RoPE and V, rotate the queries, rotate the output back).
How it was tested
installed engine was not touched.
--kv int8end to end throughserve/server.py(the config's args carry--kv int8).q36reffp32 path is untouched (the FP32 template instantiation is the previous kernel code).🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.