[PR #459] [MERGED] GLM decode on Volta: the MLA attention on the tensor cores (mma.m8n8k4) - attention 4.3x, decode +3-6% on a V100 #537

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

📋 Pull Request Information

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

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


📝 Commits (1)

  • b2ddf05 GLM decode: the MLA attention on Volta's tensor cores - the prompts' one-pass kernel (mma.m8n8k4) in cell splits (MAYA_GLM_MLA_V70, on by default on sm_70/72; =0: the F32 split kernel)

📊 Changes

4 files changed (+146 additions, -17 deletions)

View changed files

📝 docs/SETTINGS.md (+1 -0)
📝 include/strata/kernels/glm_batch.hpp (+5 -0)
📝 src/kernels/cuda/glm_batch.cu (+131 -17)
📝 src/kernels/cuda/glm_fast.cu (+9 -0)

📄 Description

What

On Volta (sm_70 / sm_72), the GLM decode ran its sparse MLA attention on the CUDA cores. mla_mma_on() is sm_80+ only, because its kernel needs mma.m16n8k16. So every decode token used the F32 split kernel, once per DSA layer: on a V100, 192 µs a call plus a 43 µs combine, about 2.6 ms of every token.

This PR runs the decode attention on Volta's tensor cores. It reuses the prompts' one-pass Volta kernel, mla_attn_v70_kernel from #335: wmma Q·Kᵀ, online softmax, then P·V on mma.m8n8k4 with O in registers.

  • A SPLIT instantiation of that kernel. It takes one token's selected cells in splits of whole 32-cell tiles, about one block per multiprocessor across the head groups. Each split writes its unnormalised context and its heads' max and sum into the decode's existing partial buffer (mla_part), so no new VRAM is needed at decode time.
  • mla_dec_combine_kernel merges the splits: a block per (head, 128 columns).
  • The prompt instantiation (SPLIT = false) does the same arithmetic as before. The decode tail sits behind if constexpr.
  • Off Volta nothing changes. On HIP the launcher returns false (tools/check_hip_compat.py passes).
  • Settings: MAYA_GLM_MLA_V70 is on by default on sm_70/72; =0 gives the F32 split kernel. MAYA_GLM_MLA_V70_SPLITS sets the splits per head group. Both have a row in docs/SETTINGS.md.

Exactness

The kernel is not bit for bit the F32 kernel. Q and the softmax weights enter the tensor cores as FP16, with F32 sums. It is deterministic: repeated runs give identical tokens.

KL against the F32 kernel, with the CPU lane off and a fixed RAM tier, teacher-forced, the last 256 positions decoded:

mean KL p99 top-1 agree
8K, INT8 latents 0.0086 0.070 96.1 %
24K, INT8 latents 0.0131 0.097 95.3 %
8K, FP16 latents 0.0080 0.039 96.5 %
for scale: INT8 vs FP16 latents (F32 kernel), 8K / 24K 0.0118 / 0.0164

The first decoded positions differ by about 3e-5. Most of the KL is the small difference carried forward through the recurrent state.

I also tried a variant that splits Q and P into FP16 high + low parts, two products each, as mla_split_mma_kernel does. It gave the same KL (0.0088 vs 0.0086), so the remaining difference is summation order, not FP16 rounding, and this PR keeps the cheaper form.

Speed

Measured on a Tesla V100-PCIE-32GB at 250 W with a Ryzen 9 7950X and the Maya-S-v2 IQ2_XXS pack.

The attention, per DSA layer (nvprof, 8K prompt + 512 decoded tokens):

kernel combine
F32 split kernel (=0) 192 µs 43 µs
this PR 49 µs 6 µs

Decode, deterministic (CPU lane off, MAYA_GLM_RAM_GB=50, 4 alternating rounds, 512 tokens, ms per token, mean with range):

prompt =0 this PR
2K 97.02 (96.81–97.33) 94.11 (93.97–94.30) −3.0 %
8K 84.33 (84.27–84.39) 81.48 (81.39–81.52) −3.4 %
27K 85.43 (85.35–85.49) 79.56 (79.51–79.64) −6.9 %

Every round with the change was faster than every round without it.

Decode, as served (the default CPU lane, 3 alternating rounds, 256 tokens, tok/s): 2K 20.9 → 21.5, 8K 25.4 → 26.5, 27K 24.1 → 25.4. That is +2.6 / +4.4 / +5.7 %, and every round with the change was faster at 2K and 8K. This setting varies about ±2 % from run to run.

The same A/B with turboderp's EXL3 2.05bpw quant: 22.8 → 23.3 / 24.1 → 25.1 / 24.0 → 25.2 tok/s (+2.2 / +3.9 / +5.1 %). The attention does not depend on the expert format.

Prompt speed is unchanged.

Not run on other Volta parts (Titan V, sm_72) or on other cards; off Volta the code path is not taken.


🔄 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/459 **Author:** [@merbanan](https://github.com/merbanan) **Created:** 10/24/2026 **Status:** ✅ Merged **Merged:** 10/24/2026 **Merged by:** [@mw00](https://github.com/mw00) **Base:** `main` ← **Head:** `pr/mla-decode-v70` --- ### 📝 Commits (1) - [`b2ddf05`](https://github.com/mw00/project-maya/commit/b2ddf050a1fa27bd223d24fa3199aaa872f5f5fb) GLM decode: the MLA attention on Volta's tensor cores - the prompts' one-pass kernel (mma.m8n8k4) in cell splits (MAYA_GLM_MLA_V70, on by default on sm_70/72; =0: the F32 split kernel) ### 📊 Changes **4 files changed** (+146 additions, -17 deletions) <details> <summary>View changed files</summary> 📝 `docs/SETTINGS.md` (+1 -0) 📝 `include/strata/kernels/glm_batch.hpp` (+5 -0) 📝 `src/kernels/cuda/glm_batch.cu` (+131 -17) 📝 `src/kernels/cuda/glm_fast.cu` (+9 -0) </details> ### 📄 Description ## What On Volta (sm_70 / sm_72), the GLM decode ran its sparse MLA attention on the CUDA cores. `mla_mma_on()` is sm_80+ only, because its kernel needs `mma.m16n8k16`. So every decode token used the F32 split kernel, once per DSA layer: on a V100, 192 µs a call plus a 43 µs combine, about 2.6 ms of every token. This PR runs the decode attention on Volta's tensor cores. It reuses the prompts' one-pass Volta kernel, `mla_attn_v70_kernel` from #335: wmma Q·Kᵀ, online softmax, then P·V on `mma.m8n8k4` with O in registers. - **A `SPLIT` instantiation of that kernel.** It takes one token's selected cells in splits of whole 32-cell tiles, about one block per multiprocessor across the head groups. Each split writes its unnormalised context and its heads' max and sum into the decode's existing partial buffer (`mla_part`), so no new VRAM is needed at decode time. - **`mla_dec_combine_kernel`** merges the splits: a block per (head, 128 columns). - **The prompt instantiation (`SPLIT = false`) does the same arithmetic as before.** The decode tail sits behind `if constexpr`. - **Off Volta nothing changes.** On HIP the launcher returns false (`tools/check_hip_compat.py` passes). - **Settings:** `MAYA_GLM_MLA_V70` is on by default on sm_70/72; `=0` gives the F32 split kernel. `MAYA_GLM_MLA_V70_SPLITS` sets the splits per head group. Both have a row in `docs/SETTINGS.md`. ## Exactness The kernel is not bit for bit the F32 kernel. Q and the softmax weights enter the tensor cores as FP16, with F32 sums. It is deterministic: repeated runs give identical tokens. KL against the F32 kernel, with the CPU lane off and a fixed RAM tier, teacher-forced, the last 256 positions decoded: | | mean KL | p99 | top-1 agree | |---|---:|---:|---:| | 8K, INT8 latents | 0.0086 | 0.070 | 96.1 % | | 24K, INT8 latents | 0.0131 | 0.097 | 95.3 % | | 8K, FP16 latents | 0.0080 | 0.039 | 96.5 % | | *for scale: INT8 vs FP16 latents (F32 kernel), 8K / 24K* | *0.0118 / 0.0164* | | | The first decoded positions differ by about 3e-5. Most of the KL is the small difference carried forward through the recurrent state. I also tried a variant that splits Q and P into FP16 high + low parts, two products each, as `mla_split_mma_kernel` does. It gave the same KL (0.0088 vs 0.0086), so the remaining difference is summation order, not FP16 rounding, and this PR keeps the cheaper form. ## Speed Measured on a Tesla V100-PCIE-32GB at 250 W with a Ryzen 9 7950X and the Maya-S-v2 IQ2_XXS pack. **The attention, per DSA layer** (nvprof, 8K prompt + 512 decoded tokens): | | kernel | combine | |---|---:|---:| | F32 split kernel (`=0`) | 192 µs | 43 µs | | this PR | 49 µs | 6 µs | **Decode, deterministic** (CPU lane off, `MAYA_GLM_RAM_GB=50`, 4 alternating rounds, 512 tokens, ms per token, mean with range): | prompt | `=0` | this PR | | |---|---:|---:|---:| | 2K | 97.02 (96.81–97.33) | 94.11 (93.97–94.30) | −3.0 % | | 8K | 84.33 (84.27–84.39) | 81.48 (81.39–81.52) | −3.4 % | | 27K | 85.43 (85.35–85.49) | 79.56 (79.51–79.64) | −6.9 % | Every round with the change was faster than every round without it. **Decode, as served** (the default CPU lane, 3 alternating rounds, 256 tokens, tok/s): 2K 20.9 → 21.5, 8K 25.4 → 26.5, 27K 24.1 → 25.4. That is +2.6 / +4.4 / +5.7 %, and every round with the change was faster at 2K and 8K. This setting varies about ±2 % from run to run. The same A/B with turboderp's EXL3 2.05bpw quant: 22.8 → 23.3 / 24.1 → 25.1 / 24.0 → 25.2 tok/s (+2.2 / +3.9 / +5.1 %). The attention does not depend on the expert format. Prompt speed is unchanged. Not run on other Volta parts (Titan V, sm_72) or on other cards; off Volta the code path is not taken. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-29 21:26:33 +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#537
No description provided.