mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #1367] [CLOSED] prompt attention: STRATA_PROMPT_ATTN_IMMA=1 - the int8-KV kernel on INT8 tensor cores (opt-in, closer to FP32) #3409
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#3409
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/1367
Author: @sergqwer
Created: 10/7/2026
Status: ❌ Closed
Base:
main← Head:pr/prompt-attn-imma📝 Commits (1)
96db6d3prompt attention: STRATA_PROMPT_ATTN_IMMA=1 - the int8-KV kernel on INT8 tensor cores (opt-in, closer to FP32)📊 Changes
3 files changed (+400 additions, -3 deletions)
View changed files
📝
include/strata/kernels/qsa_prompt_attn.hpp(+3 -0)📝
src/kernels/cuda/qsa_prompt_attn.cu(+357 -0)📝
src/kernels/qsa_prompt_attn_parity.cpp(+40 -3)📄 Description
The int8-KV prompt attention (
prompt_attn_i8_kernel, v2) drifts away from the FP32 kernel on short prompts. On IQ2_XS the first-token KL to the FP32 kernel is 0.025 after a 2K prompt, and the 32 greedy tokens change. This PR adds an opt-in kernel (STRATA_PROMPT_ATTN_IMMA=1) that puts both products on INT8 tensor cores with an operand split exact to 24 bits. It is closer to FP64 than v2 at every shape tested and 1.35-1.53x faster per launch. Unset (the default), nothing changes.What it does
prompt_attn_i8v3_kernelkeeps v2's block, its cp.async pipeline and its online softmax.Operands. QK^T and PV run as
mma m16n8k32on the int8 K and V codes as stored, with no int8 -> fp16 conversion. The other operand is split into three exact 8-bit parts:u8 x s8MMA).That is 24 bits, finer than v2's FP16 hi + lo split (~22 bits). Each part's int32 sum is exact, and the three parts are combined in FP32.
Occupancy. One K stage and one V stage per warp (K(c+1) is gathered during softmax(c) and PV(c)), 12-row partial sums, and
__launch_bounds__(128, 3): ~25.5 KB of shared memory and 168 registers, so 3 blocks per SM instead of v2's 2. The kernel waits on latency, not on its MMAs: with one block per SM it ran 1.54x slower than with two.Scope. sm_80+ only: the device code is behind the file's
STRATA_PA_SM80, and Turing / Volta / HIP keep their kernels. The file compiles for 75/80/86/89/120. A test hook,qsa_prompt_attn_set_imma(), is added.qsa_prompt_attn_paritynow checks IMMA against FP64 and v2 and times both.Measured
RTX 5090, Ryzen 9 9950X3D, IQ2_XS (ISTA GSQ-RCO),
--kv int8,--expert-cache 12000.Kernel accuracy against FP64 (
qsa_prompt_attn_parity, max relative error, 0 failures):End to end, first-token KL to the FP32 kernel (
STRATA_PROMPT_ATTN_OLD=1); the last column says whether the 32 greedy tokens match the FP32 kernel's:On the same model in NVFP4 (our fork) the gap at 2K was wider: KL 0.10 for v2 against 0.007 for IMMA.
Speed:
Per launch (
qsa_prompt_attn_parity): 32K / 2048 queries 2.09 -> 1.55 ms (1.35x); 1500 / 1500 0.61 -> 0.40 ms (1.53x); 2100 / 256 0.28 -> 0.26 ms (1.09x).In the engine, 32K prompt in 8K chunks (nsys, 48 launches): 358.1 -> 311.6 ms (1.15x).
Prompt time, 3 interleaved pairs, which the machine's noise dominates:
The kernel saves ~47 ms of a ~5 s 32K prompt, which is below that noise.
Identity. With the switch unset, the first-token logits and the 32 greedy tokens equal v0.1.40.2 on IQ2_XS after 2K and after 32K (identical bytes, repeated).
🤖 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.