mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #452] [CLOSED] qsa_prompt_attn: Q4_0 KV on tensor cores (mode 4) - long prompts with --kv q4_0 ~19% faster #2645
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#2645
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/452
Author: @architectds
Created: 10/2/2026
Status: ❌ Closed
Base:
main← Head:pr/q4-prompt-attn📝 Commits (1)
e71abf8qsa_prompt_attn: Q4_0 K and V on tensor cores (mode 4) - long prompts with --kv q4_0 no longer take the old kernel📊 Changes
3 files changed (+119 additions, -32 deletions)
View changed files
📝
include/strata/kernels/qsa_prompt_attn.hpp(+3 -2)📝
src/kernels/cuda/qsa_prompt_attn.cu(+77 -23)📝
src/kernels/qsa_prompt_attn_parity.cpp(+39 -7)📄 Description
What
The tensor-core prompt attention (D-1,
qsa_prompt_attn_batch) handles FP16, INT8 and K8V4 KV but refuses Q4_0. With--kv q4_0, every prompt's QSA attention therefore ran on the FP32 per-query kernel (qsa_decode_attn_batch, 32queries at a time). This adds a mode for Q4_0 K and V.
(code - 8) at gather, and its fp16 scale goes into the per-group scales: 8 groups of 32 per row, where int8 has 4
of 64. The scales are applied in FP32 as int8's are: q.k per 32-dim group, and for p.v each group's scale is
folded into p (two groups per warp).
d = max / -8, so about half of a real pool's blocks have a negative scale.The p.v fold is bounded by the chunk's largest
|scale|.and of the output is unchanged.
STRATA_PROMPT_ATTN_Q4=0restores the old kernel.qsa_prompt_attn_paritygets Q4_0 cases (32K and 1.5K contexts) against FP64 and the old kernel. Theirscales are signed and spread over two decades, as a pool's are.
What it speeds up, and what it does not
--kv q4_0: +18.5% at 8K tokens, +18.8% at 16K, +19.9% at 30K. With the old kernel the attentionwas 21-22% of a long prompt's GPU time on this machine.
the same numbers as before.
Measured
Setup:
--kv q4_0 --kv-resident 32768, text-only args (4,560 expert slots),--prefill auto(8,192-token chunks).
Kernel (
qsa_prompt_attn_parity 32768 2048 5):The int8 and fp16 cases still pass.
Prompts:
STRATA_PROMPT_ATTN_Q4=0) and mode 4 in alternating engine runs (old, new, old, new).both arms by their own variables, so the arms are v0.1.34 and v0.1.34 + this commit.
Quality (not bitwise, as D-1 is not):
tools/needle_bench.py's haystack and needle, driven through the engine. 8K, 16K and 32K at depths10/30/50/70/90: 15 of 15 with the old kernel, 15 of 15 with mode 4.
model amplifies any FP32-level change.
bounded. On real K/V that overflowed FP16 and the model returned NaN (needles 0 of 15). The parity test had passed
it, because its synthetic scales were all positive. The test's scales are now signed, and it fails on that bound
(new vs old 0.93 of the output scale).
Not tested here
Developed with an AI coding assistant; all numbers measured on the machine above.
🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.