[PR #61] [MERGED] GLM prompts: skip the last layer's unused outputs on a single device #310

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

📋 Pull Request Information

Original PR: https://github.com/mw00/project-maya/pull/61
Author: @boxwrench
Created: 10/9/2026
Status: ✅ Merged
Merged: 10/9/2026
Merged by: @mw00

Base: main ← Head: perf/terminal-layer-skip


📝 Commits (2)

  • 813b923 perf(glm): skip unused single-device prefill tail outputs
  • d1183a9 perf(glm): no prestage for the skipped terminal layer

📊 Changes

2 files changed (+20 additions, -6 deletions)

View changed files

📝 README.md (+1 -0)
📝 src/core/glm_prefill.cu (+19 -6)

📄 Description

On a single device with no NextN block loaded, a prompt chunk's last layer computes outputs nothing reads: decode computes the final prompt token and its logits on its own (generate.cpp prefills all but the last token), the next chunk starts from its own embeddings, and snapshots/slots save only recurrent and cache state. This skips that layer's attention output projection and FFN (both mHC write halves) after all of its KDA/DSA cache updates have run, and doesn't prestage experts for it.

The skip applies only when the whole trunk is on one device, mtp_il_ < 0 (no NextN cache fill to feed), and no GLM_CB_DIR seam dump is set. Splits, a loaded NextN block and decode keep the full path. STRATA_GLM_PREFILL_TAIL_SKIP=0 turns it off (README row added). It adds no kernels and no CUDA/HIP calls, so CUDA single-GPU prompts get it too.

Same output. On Strix Halo (gfx1151, every expert resident, a fresh load per prompt), skip on vs off: three prompts of 220 / 1,122 / 2,682 tokens (1 / 3 / 6 chunks) x 64 greedy tokens, and all 192 token IDs, 29.7M logits, full prefill cache dumps, saved snapshots and restored states are byte-identical. With NextN forced on (STRATA_GLM_MTP=1) the skip stays off, as it should. glm_layer_parity and glm_model_test pass on gfx1151, gfx1201 and gfx1100.

Speed (one request per size, same binary):

4K 8K 16K 28K
Strix Halo, all experts resident +1.2% +1.1% +0.8% -
R9700, 48 GB RAM tier - +1.4% +1.2% +1.0%

Decode is unchanged. On the R9700, greedy text with tiered experts varies between runs of the same arm, by about as much as between arms, so the byte-identical check above (all experts resident) is the one that counts.


🔄 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/61 **Author:** [@boxwrench](https://github.com/boxwrench) **Created:** 10/9/2026 **Status:** ✅ Merged **Merged:** 10/9/2026 **Merged by:** [@mw00](https://github.com/mw00) **Base:** `main` ← **Head:** `perf/terminal-layer-skip` --- ### 📝 Commits (2) - [`813b923`](https://github.com/mw00/project-maya/commit/813b9233b25c643e6754a8754dd23e7d5dc28e30) perf(glm): skip unused single-device prefill tail outputs - [`d1183a9`](https://github.com/mw00/project-maya/commit/d1183a9dbd2856389ec8bc5d096169036ab0fbef) perf(glm): no prestage for the skipped terminal layer ### 📊 Changes **2 files changed** (+20 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `README.md` (+1 -0) 📝 `src/core/glm_prefill.cu` (+19 -6) </details> ### 📄 Description On a single device with no NextN block loaded, a prompt chunk's last layer computes outputs nothing reads: decode computes the final prompt token and its logits on its own (`generate.cpp` prefills all but the last token), the next chunk starts from its own embeddings, and snapshots/slots save only recurrent and cache state. This skips that layer's attention output projection and FFN (both mHC write halves) after all of its KDA/DSA cache updates have run, and doesn't prestage experts for it. The skip applies only when the whole trunk is on one device, `mtp_il_ < 0` (no NextN cache fill to feed), and no `GLM_CB_DIR` seam dump is set. Splits, a loaded NextN block and decode keep the full path. `STRATA_GLM_PREFILL_TAIL_SKIP=0` turns it off (README row added). It adds no kernels and no CUDA/HIP calls, so CUDA single-GPU prompts get it too. **Same output.** On Strix Halo (gfx1151, every expert resident, a fresh load per prompt), skip on vs off: three prompts of 220 / 1,122 / 2,682 tokens (1 / 3 / 6 chunks) x 64 greedy tokens, and all 192 token IDs, 29.7M logits, full prefill cache dumps, saved snapshots and restored states are byte-identical. With NextN forced on (`STRATA_GLM_MTP=1`) the skip stays off, as it should. `glm_layer_parity` and `glm_model_test` pass on gfx1151, gfx1201 and gfx1100. **Speed** (one request per size, same binary): | | 4K | 8K | 16K | 28K | |---|---|---|---|---| | Strix Halo, all experts resident | +1.2% | +1.1% | +0.8% | - | | R9700, 48 GB RAM tier | - | +1.4% | +1.2% | +1.0% | Decode is unchanged. On the R9700, greedy text with tiered experts varies between runs of the same arm, by about as much as between arms, so the byte-identical check above (all experts resident) is the one that counts. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-29 21:24:03 +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#310
No description provided.