[PR #335] [MERGED] GLM prompt attention on Volta in one pass (mma.m8n8k4): long prompts +8-9% on a V100 #473

Closed
opened 2026-10-29 21:25:50 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/mw00/project-maya/pull/335
Author: @merbanan
Created: 10/21/2026
Status: ✅ Merged
Merged: 10/23/2026
Merged by: @mw00

Base: main ← Head: pr/mla-attn-v70


📝 Commits (1)

  • 8aaf0ca GLM prompt attention on Volta in one pass (mma.m8n8k4): 27K prompts +9% on a V100

📊 Changes

2 files changed (+191 additions, -2 deletions)

View changed files

📝 docs/SETTINGS.md (+1 -1)
📝 src/kernels/cuda/glm_batch.cu (+190 -1)

📄 Description

What

On Volta, GLM's prompt attention (mla_attn_tc2_kernel) walks each token's selected cells twice. The first pass does the gather and Q·Kᵀ to get the softmax's max and sum; the second does them again to get P. It needs two passes because a wmma accumulator's layout isn't known on Volta, so the context can't be rescaled in registers.

mla_attn_v70_kernel does it in one pass, using mma.sync.m8n8k4, whose layout is known:

  • the same block, tiles and shared memory as tc2: block = (token, 32 heads), 256 threads, tiles of 32 cells;
  • Q·Kᵀ once, on wmma;
  • an online softmax in FP32 that writes P (FP16) and each head's rescale factor;
  • P·V on mma.m8n8k4, with the context in registers (64 floats a lane) and rescaled there each tile;
  • the next tile's latent rows loaded into registers while the current tile computes (Volta has no cp.async).

It uses 202 registers with no spills. It is the default on sm_70 / sm_72. STRATA_GLM_PREFILL_ATTN=tc2 (or MAYA_GLM_PREFILL_ATTN=tc2) runs the two-pass kernel. The other architectures are unchanged. The kernel body is guarded for Pascal the same way tc2's is. Its row in docs/SETTINGS.md is updated.

The one-pass design follows 1CatAI/1Cat-vLLM #1092 / #1125 (FP32 scores and softmax, FP16 operands, F32 sums). The code is new.

Measured

One Tesla V100-PCIE-32GB with a 7950X and 62 GB of RAM, GLM-5.3-Flash Maya-S24, STRATA_GLM_PREFILL_SUB=1024. Same build (main v1.1.19 + this PR), two rounds each, tc2 vs the new default. Each run is a fresh request: a prompt of N tokens, then 128 greedy tokens.

prompt tc2 prompt tok/s one-pass prompt tok/s
2K 568 / 569 585 / 583 +3%
8K 764 / 762 822 / 820 +8%
27K 842 / 839 916 / 915 +9%

Profile of a 27K prompt (STRATA_GLM_PREFILL_PROF=1): dsa_attn goes from 6.87 s to 4.09 s.

The output changes slightly. It's a different summation order, as any rewrite of the attention would be.

  • With STRATA_GLM_PREFILL_ATTN_CHECK=1, rel L2 against the FP32 kernel is 8.6–9.5e-5 (tc2: 4.4–5.2e-5).
  • KL against tc2 (8K tokens teacher-forced, 256 decoded, deterministic: tc2 against itself is 0) is 0.0107 for the one-pass kernel and 0.0113 for the exact FP32 kernel. So the new kernel is as close to tc2 as exact FP32 is.
  • Needles (ab/longctx.py, Maya-S-v2 IQ2_XXS, 128K context, measured on our branch with the same kernel): 6 / 6 at haystacks of 40K and 100K, with tc2 and with the one-pass kernel. Prompt speed there goes from 695 / 698 to 743 / 753 tok/s.

Decode right after a fresh long prompt comes out a little lower. After 27K: 24.8 / 26.0 vs 26.6 / 27.0 tok/s; after 8K: mixed. The kernel itself doesn't slow decode:

  • On a cached prompt, decode is equal: 36.6–38.6 vs 35.6–37.5 tok/s (measured on our branch).
  • The tier counters show the cause. The prompt ends sooner, so the expert tiers have had less time to settle: after 8K, VRAM hits are 74.7 / 76.3% vs 77.6 / 78.3%, with more RAM fetches and promotions.
  • At 27K, the 128 tokens give back about 0.35 s of the 2.6 s the prompt saves.

Builds: native (sm_70) for the run; glm_batch.cu also compiled for sm_75 / 86 / 120. tools/check_hip_compat.py passes.


🔄 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/mw00/project-maya/pull/335 **Author:** [@merbanan](https://github.com/merbanan) **Created:** 10/21/2026 **Status:** ✅ Merged **Merged:** 10/23/2026 **Merged by:** [@mw00](https://github.com/mw00) **Base:** `main` ← **Head:** `pr/mla-attn-v70` --- ### 📝 Commits (1) - [`8aaf0ca`](https://github.com/mw00/project-maya/commit/8aaf0cacce4c6533919045e9e8d1137d8957cfc5) GLM prompt attention on Volta in one pass (mma.m8n8k4): 27K prompts +9% on a V100 ### 📊 Changes **2 files changed** (+191 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `docs/SETTINGS.md` (+1 -1) 📝 `src/kernels/cuda/glm_batch.cu` (+190 -1) </details> ### 📄 Description ## What On Volta, GLM's prompt attention (`mla_attn_tc2_kernel`) walks each token's selected cells twice. The first pass does the gather and Q·Kᵀ to get the softmax's max and sum; the second does them again to get P. It needs two passes because a wmma accumulator's layout isn't known on Volta, so the context can't be rescaled in registers. `mla_attn_v70_kernel` does it in one pass, using `mma.sync.m8n8k4`, whose layout is known: - the same block, tiles and shared memory as tc2: block = (token, 32 heads), 256 threads, tiles of 32 cells; - Q·Kᵀ once, on wmma; - an online softmax in FP32 that writes P (FP16) and each head's rescale factor; - P·V on `mma.m8n8k4`, with the context in registers (64 floats a lane) and rescaled there each tile; - the next tile's latent rows loaded into registers while the current tile computes (Volta has no `cp.async`). It uses 202 registers with no spills. It is the default on sm_70 / sm_72. `STRATA_GLM_PREFILL_ATTN=tc2` (or `MAYA_GLM_PREFILL_ATTN=tc2`) runs the two-pass kernel. The other architectures are unchanged. The kernel body is guarded for Pascal the same way tc2's is. Its row in docs/SETTINGS.md is updated. The one-pass design follows 1CatAI/1Cat-vLLM #1092 / #1125 (FP32 scores and softmax, FP16 operands, F32 sums). The code is new. ## Measured One Tesla V100-PCIE-32GB with a 7950X and 62 GB of RAM, GLM-5.3-Flash Maya-S24, `STRATA_GLM_PREFILL_SUB=1024`. Same build (main v1.1.19 + this PR), two rounds each, `tc2` vs the new default. Each run is a fresh request: a prompt of N tokens, then 128 greedy tokens. | prompt | tc2 prompt tok/s | one-pass prompt tok/s | | |---|---|---|---| | 2K | 568 / 569 | 585 / 583 | +3% | | 8K | 764 / 762 | 822 / 820 | +8% | | 27K | 842 / 839 | 916 / 915 | +9% | Profile of a 27K prompt (`STRATA_GLM_PREFILL_PROF=1`): `dsa_attn` goes from 6.87 s to 4.09 s. **The output changes slightly.** It's a different summation order, as any rewrite of the attention would be. - With `STRATA_GLM_PREFILL_ATTN_CHECK=1`, rel L2 against the FP32 kernel is 8.6–9.5e-5 (tc2: 4.4–5.2e-5). - KL against tc2 (8K tokens teacher-forced, 256 decoded, deterministic: tc2 against itself is 0) is 0.0107 for the one-pass kernel and 0.0113 for the exact FP32 kernel. So the new kernel is as close to tc2 as exact FP32 is. - Needles (`ab/longctx.py`, Maya-S-v2 IQ2_XXS, 128K context, measured on our branch with the same kernel): 6 / 6 at haystacks of 40K and 100K, with tc2 and with the one-pass kernel. Prompt speed there goes from 695 / 698 to 743 / 753 tok/s. **Decode right after a fresh long prompt comes out a little lower.** After 27K: 24.8 / 26.0 vs 26.6 / 27.0 tok/s; after 8K: mixed. The kernel itself doesn't slow decode: - On a cached prompt, decode is equal: 36.6–38.6 vs 35.6–37.5 tok/s (measured on our branch). - The tier counters show the cause. The prompt ends sooner, so the expert tiers have had less time to settle: after 8K, VRAM hits are 74.7 / 76.3% vs 77.6 / 78.3%, with more RAM fetches and promotions. - At 27K, the 128 tokens give back about 0.35 s of the 2.6 s the prompt saves. Builds: native (sm_70) for the run; `glm_batch.cu` also compiled for sm_75 / 86 / 120. `tools/check_hip_compat.py` passes. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-29 21:25:50 +07:00
Sign in to join this conversation.
No labels
pull-request
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
mw00/project-maya#473
No description provided.