mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #293] [CLOSED] KV: optional Hadamard rotation for int8 K/V (STRATA_KV_ROT=1), with the drafter and batched verify made rotation-consistent #2561
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#2561
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/293
Author: @sergqwer
Created: 9/30/2026
Status: ❌ Closed
Base:
main← Head:pr/kv-int8-rotation📝 Commits (2)
b9ae69bKV: optional Hadamard rotation for int8 K/V (STRATA_KV_ROT=1); the drafter and the batched verify rotation-consistent5efeaeeMTP drafter: rotation and storage are separate - an INT8 cache with STRATA_KV_ROT=1 called the Q4_0 append (review)📊 Changes
6 files changed (+47 additions, -25 deletions)
View changed files
📝
include/strata/core/layer.hpp(+5 -0)📝
src/core/layer.cpp(+11 -6)📝
src/core/mtp.cpp(+6 -4)📝
src/core/verify.cpp(+4 -3)📝
src/prefill/prefill.cpp(+16 -11)📝
src/program/generate.cpp(+5 -1)📄 Description
Summary
INT8 K and V can now go through the same Walsh-Hadamard rotation that
--kv q4_0already uses (kv_q4.hpp). Therotation spreads outlier channels over the 64-value scale groups before quantization. The queries are rotated too
(
<Hq, Hk> = <q, k>) and the output is rotated back. It is opt-in:STRATA_KV_ROT=1.Along the way, two places that were not rotation-consistent are fixed. They matter for Q4_0 today and for rotated INT8:
verify.cpp: the batched window path (qb) never rotated its queries. That was harmless only because Q4_0 waskept off that path.
Prefill::draft_kv: the MTP drafter's batched prompt pass rotated the prompt's K/V only for Q4_0, while thedrafter's own decode (
mtp.cpp) rotates bykv_rot. With rotated INT8 the drafter would score rotated queriesagainst unrotated prompt keys. On the fork this cost 1.60 vs 2.40 tokens per round after an 8K prompt.
Measured
Measured on current main (0.1.29,
d6708a4) with ISTA-DASLab's IQ2_XS, RTX 5090 32 GB, Ryzen 9 9950X3D, 128 GB DDR5, Windows 11. KL is first-token KL divergence (STRATA_DUMP_FIRST_LOGITS, #276); two runs of main itself differ by 0 on 5 of 6 short prompts and by 0.00013 on the sixth. First-token KL to fp16 K/V:On the fork, on real K/V, the attention output's error against FP32 went from 0.306% to 0.265%. End to end it helps
the NVFP4 pack and hurts IQ2_XS, which is why it is off by default. I don't have an explanation for the IQ2_XS
result; the same code paths run for both packs. It may be worth a look before anyone turns it on by default.
Correctness
Without the switch, the generated tokens are identical to main's (128 tokens, IQ2_XS). With
STRATA_KV_ROT=1drafting works (2.57 tokens per round).
Switch
STRATA_KV_ROT=1rotates INT8 K/V.🤖 Generated with Claude Code
https://claude.ai/code/session_01VZy1yKaDDiA8a7svdwaHio
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.