[PR #800] [CLOSED] qsa_prompt_attn: Volta (sm_70) m8n8k4 kernel - keep the hi and lo halves in separate accumulator chains #2838

Closed
opened 2026-11-04 02:03:28 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/800
Author: @eelgaev
Created: 10/4/2026
Status: ❌ Closed

Base: main ← Head: volta-attn-split-chains


📝 Commits (10+)

  • fa16567 setup: an earlier config that does not parse is skipped, not a crash; configs are written atomically (#459)
  • 749d957 setup (--backend hip): a system ROCm without the HIP development files falls back to the wheels (#446)
  • 5a30024 calibrate: the engine's arguments come from the server's engine_args; a failed tuning says why (#447)
  • 9f60d13 serve, setup: name the small split card that caps the prompt chunk; setup recommends the big card alone (#448)
  • eb8da1d /metrics: each request's speculative draft counts, and their sums in the totals (#457)
  • 6a09387 setup (--gguf-dir): GGUFs Strata cannot run are named as such, with the --family/--model to use (#444)
  • d6a91e2 docs: the Coder is weaker outside code, Chinese/CJK text included; the unpruned sizes for that (#438)
  • d8d4ad3 Merge branch 'f-135-eng' into rel-0.1.35
  • 7b600d5 Merge branch 'f-135-small' into rel-0.1.35
  • d9ab843 Engine 0.1.35: Windows AMD uses its bundled HIP runtime (#468 #461), the low-RAM resident mode on Windows 32 GB PCs (#467), fixes #460 #459 #446 #447 #457 #448 #444; setup requires it

📊 Changes

2 files changed (+13 additions, -10 deletions)

View changed files

📝 docs/NVIDIA_V100.md (+1 -1)
📝 src/kernels/cuda/qsa_prompt_attn.cu (+12 -9)

📄 Description

Small follow-up to #600. Thanks @fks for the kernel, it's a great speedup on V100.

What's going on

The m8n8k4 kernel splits q (for q·k) and p (for p·v) into an FP16 hi half and a lo half, so the products come out close to FP32 precision. Right now both halves go into the same accumulator:

mma884(tg[rb], ah.x, ah.y, b0, b1);   // hi
mma884(tg[rb], al.x, al.y, b0, b1);   // lo, same accumulator

Volta's tensor cores truncate the running sum as they accumulate. They don't round it like a plain FP32 add would. By the time the lo products arrive, the accumulator already holds the hi products, which are orders of magnitude larger, so most of the lo contribution gets cut off. The split ends up buying much less than it should. That's why the kernel sits around 5e-6 against FP64 while the FP32 kernel it replaces is around 2e-6. It's probably also part of why the 99k document in the #600 discussion came out a bit above the controls.

The fix

The lo products get their own accumulator (tgl for the scores, tmpl for p·v), and the two are added in plain FP32 at the end. Nothing else changes: same tiling, same shared memory, same launch. Register counts are identical before and after (166 / 226 / 163 for modes 0 / 1 / 3), with no spills.

Numbers

qsa_prompt_attn_parity, one V100-SXM2-16GB, 2,048 queries, error vs the FP64 reference as the tool reports it:

context FP32 kernel before (one chain) after (two chains) kernel time
8,192 2.14e-6 5.88e-6 3.02e-6 11.94 → 12.20 ms
32,768 2.37e-6 5.08e-6 2.33e-6 12.20 → 12.38 ms
131,072 1.81e-6 5.35e-6 2.75e-6 12.34 → 12.51 ms

The fix brings the kernel to the FP32 kernel's accuracy for about 1.5-2% more kernel time. Attention is a small slice of a prompt, so I'd expect that to vanish end to end. I didn't A/B prompt speed for this change on its own, though.

On a real model it moves in the same direction. Teacher-forced with STRATA_LOGPOS (600 positions after a 32K and a 2K prompt, KL vs an FP32-path reference, UD-Q4_K_XL, int8 KV, 4x V100), KL went 0.0240 → 0.0220 on the 32K text and 0.0168 → 0.0154 on the 2K one. That setup also runs some of our fork's own opt-in kernels, so take it as a direction rather than a clean A/B. The parity table above is the clean comparison.

How it was tested

This was tested on our AC922 fork (eelgaev/Strata-AC922, branch ac922: an IBM AC922 with 2x POWER9 and 4x V100-SXM2 16 GB). main doesn't build on ppc64le yet, so here's what I did:

  • compiled this patch against main (the kernel object builds clean, no new warnings);
  • ran the parity tool from the fork, where this kernel is the same code as main's apart from this change. The before/after rows above come from that tree with the two accumulator lines toggled;
  • the fork's launch configuration has used the fixed kernel since then: full 4-GPU benchmark runs, prompts up to 252K tokens, decode text checks, and the teacher-forced runs above.

To reproduce:

cmake -S . -B build -DSTRATA_EXPERIMENTAL_SM60=ON -DSTRATA_PARITY_PROMPT_ATTN=ON ...
cmake --build build --target qsa_prompt_attn_parity
CUDA_VISIBLE_DEVICES=0 ./build/qsa_prompt_attn_parity 32768 2048 5

V100 only. sm_60 never takes this kernel (no m8n8k4 there). I also updated the error figure in docs/NVIDIA_V100.md.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/800 **Author:** [@eelgaev](https://github.com/eelgaev) **Created:** 10/4/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `volta-attn-split-chains` --- ### 📝 Commits (10+) - [`fa16567`](https://github.com/Niko1221/Strata/commit/fa165679f9860552ac97ebd07118bb8db286be4a) setup: an earlier config that does not parse is skipped, not a crash; configs are written atomically (#459) - [`749d957`](https://github.com/Niko1221/Strata/commit/749d957a1790b1a171dd4a01ab3e31b3882c9892) setup (--backend hip): a system ROCm without the HIP development files falls back to the wheels (#446) - [`5a30024`](https://github.com/Niko1221/Strata/commit/5a3002446dbb9dfcabb7d0bd9f113da90cc2f3c0) calibrate: the engine's arguments come from the server's engine_args; a failed tuning says why (#447) - [`9f60d13`](https://github.com/Niko1221/Strata/commit/9f60d13246e46b02b1dd0841980b4d18b0faaea7) serve, setup: name the small split card that caps the prompt chunk; setup recommends the big card alone (#448) - [`eb8da1d`](https://github.com/Niko1221/Strata/commit/eb8da1d8c26ec41e6ffb084fdf579dba7cad10bd) /metrics: each request's speculative draft counts, and their sums in the totals (#457) - [`6a09387`](https://github.com/Niko1221/Strata/commit/6a093874fe037020f49bd5cf053879ff6a133c21) setup (--gguf-dir): GGUFs Strata cannot run are named as such, with the --family/--model to use (#444) - [`d6a91e2`](https://github.com/Niko1221/Strata/commit/d6a91e2d1770d0f469d6ec15890acc7ee93e764c) docs: the Coder is weaker outside code, Chinese/CJK text included; the unpruned sizes for that (#438) - [`d8d4ad3`](https://github.com/Niko1221/Strata/commit/d8d4ad337d3c98ba21d3bd0af1a16e9177e112b6) Merge branch 'f-135-eng' into rel-0.1.35 - [`7b600d5`](https://github.com/Niko1221/Strata/commit/7b600d55ff801caaaa11542af1523050992e049b) Merge branch 'f-135-small' into rel-0.1.35 - [`d9ab843`](https://github.com/Niko1221/Strata/commit/d9ab8435f654c368c586340d490915f6addf56a3) Engine 0.1.35: Windows AMD uses its bundled HIP runtime (#468 #461), the low-RAM resident mode on Windows 32 GB PCs (#467), fixes #460 #459 #446 #447 #457 #448 #444; setup requires it ### 📊 Changes **2 files changed** (+13 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `docs/NVIDIA_V100.md` (+1 -1) 📝 `src/kernels/cuda/qsa_prompt_attn.cu` (+12 -9) </details> ### 📄 Description Small follow-up to #600. Thanks @fks for the kernel, it's a great speedup on V100. ### What's going on The m8n8k4 kernel splits q (for q·k) and p (for p·v) into an FP16 hi half and a lo half, so the products come out close to FP32 precision. Right now both halves go into the same accumulator: ```cpp mma884(tg[rb], ah.x, ah.y, b0, b1); // hi mma884(tg[rb], al.x, al.y, b0, b1); // lo, same accumulator ``` Volta's tensor cores truncate the running sum as they accumulate. They don't round it like a plain FP32 add would. By the time the lo products arrive, the accumulator already holds the hi products, which are orders of magnitude larger, so most of the lo contribution gets cut off. The split ends up buying much less than it should. That's why the kernel sits around 5e-6 against FP64 while the FP32 kernel it replaces is around 2e-6. It's probably also part of why the 99k document in the #600 discussion came out a bit above the controls. ### The fix The lo products get their own accumulator (`tgl` for the scores, `tmpl` for p·v), and the two are added in plain FP32 at the end. Nothing else changes: same tiling, same shared memory, same launch. Register counts are identical before and after (166 / 226 / 163 for modes 0 / 1 / 3), with no spills. ### Numbers `qsa_prompt_attn_parity`, one V100-SXM2-16GB, 2,048 queries, error vs the FP64 reference as the tool reports it: | context | FP32 kernel | before (one chain) | after (two chains) | kernel time | |---|---:|---:|---:|---:| | 8,192 | 2.14e-6 | 5.88e-6 | **3.02e-6** | 11.94 → 12.20 ms | | 32,768 | 2.37e-6 | 5.08e-6 | **2.33e-6** | 12.20 → 12.38 ms | | 131,072 | 1.81e-6 | 5.35e-6 | **2.75e-6** | 12.34 → 12.51 ms | The fix brings the kernel to the FP32 kernel's accuracy for about 1.5-2% more kernel time. Attention is a small slice of a prompt, so I'd expect that to vanish end to end. I didn't A/B prompt speed for this change on its own, though. On a real model it moves in the same direction. Teacher-forced with `STRATA_LOGPOS` (600 positions after a 32K and a 2K prompt, KL vs an FP32-path reference, UD-Q4_K_XL, int8 KV, 4x V100), KL went 0.0240 → 0.0220 on the 32K text and 0.0168 → 0.0154 on the 2K one. That setup also runs some of our fork's own opt-in kernels, so take it as a direction rather than a clean A/B. The parity table above is the clean comparison. ### How it was tested This was tested on our AC922 fork ([eelgaev/Strata-AC922](https://github.com/eelgaev/Strata-AC922), branch `ac922`: an IBM AC922 with 2x POWER9 and 4x V100-SXM2 16 GB). main doesn't build on ppc64le yet, so here's what I did: - compiled this patch against main (the kernel object builds clean, no new warnings); - ran the parity tool from the fork, where this kernel is the same code as main's apart from this change. The before/after rows above come from that tree with the two accumulator lines toggled; - the fork's launch configuration has used the fixed kernel since then: full 4-GPU benchmark runs, prompts up to 252K tokens, decode text checks, and the teacher-forced runs above. To reproduce: ```sh cmake -S . -B build -DSTRATA_EXPERIMENTAL_SM60=ON -DSTRATA_PARITY_PROMPT_ATTN=ON ... cmake --build build --target qsa_prompt_attn_parity CUDA_VISIBLE_DEVICES=0 ./build/qsa_prompt_attn_parity 32768 2048 5 ``` V100 only. sm_60 never takes this kernel (no m8n8k4 there). I also updated the error figure in `docs/NVIDIA_V100.md`. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-04 02:03:28 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#2838
No description provided.