[PR #45] [CLOSED] GLM fast path: the indexer key/gate rows in a ring instead of max_ctx rows (-0.8 / -0.6 GB at 128K, exact) #298

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

📋 Pull Request Information

Original PR: https://github.com/mw00/project-maya/pull/45
Author: @sociolog
Created: 10/9/2026
Status: ❌ Closed

Base: main ← Head: pr1-indexer-ring


📝 Commits (3)

  • 67da11d GLM fast path: the indexer key/gate rows in a ring (8196 positions) instead of max_ctx rows
  • 1d59720 score mode: STRATA_GLM_SCORE_PREFILL=1 reads the unscored context through the prompt path
  • 97e24ba README: the Tuning table's row for this change's setting

📊 Changes

10 files changed (+199 additions, -68 deletions)

View changed files

📝 README.md (+1 -0)
📝 include/strata/core/glm_model.hpp (+9 -0)
📝 include/strata/kernels/glm_batch.hpp (+3 -2)
📝 include/strata/kernels/glm_fast.hpp (+1 -0)
📝 src/core/glm_fast_path.cu (+90 -28)
📝 src/core/glm_model.cu (+23 -4)
📝 src/core/glm_prefill.cu (+38 -22)
📝 src/kernels/cuda/glm_batch.cu (+11 -7)
📝 src/kernels/cuda/glm_fast.cu (+7 -4)
📝 src/program/generate.cpp (+16 -1)

📄 Description

What

The DSA indexer keeps two F32 rows per position - the layer-normed indexer key (dsa_ik_) and the compressor gate
(dsa_ig_). They are read for exactly one thing: building the pooled key of the pool their position completes
(dsa_prep when (p + 1) % kpool == 0, dsa_pool on the prompt path). Every later read goes to the pooled keys. So
the fast path now keeps them in a ring of 8196 positions (a multiple of kpool; it holds the largest prompt
sub-batch plus the kpool - 1 rows before it) instead of max_ctx rows.

  • STRATA_GLM_IK_RING: 0 = a row per position as before, <n> = ring size (at least 2 x kpool). README row added.
  • The unfinished pool's rows are running state now: the conversation snapshot keeps them (snap_tail_) and restores
    them with the KDA states - an answer longer than the ring between two turns does not lose them.
  • Slot files carry the unfinished pool instead of the full rows (magic MAYALST2; an old slot file fails the layout
    check and is read again).
  • The NextN block's prompt cache fill runs in sub-batches the ring holds; a prompt sub-batch larger than the ring is
    refused with a message (cannot happen with the default sizes).
  • STRATA_GLM_SLOW (reference path) keeps the full rows.
  • Second commit: STRATA_GLM_SCORE_PREFILL=1 for the score mode - the unscored context goes through the prompt path,
    so prompt-path changes can be held to a score reference (used for the tests below).

Why

These two caches are 47 % of the DSA state. 131072 context, RTX 3090 (layers 0-28) + RTX 3060 12 GB (29-44 + NextN),
Maya-M, STRATA_GLM_RAM_RESIDENT=1:

before after
state/KV, 3090 1.95 GB 1.13 GB
state/KV, 3060 1.38 GB 0.79 GB
expert slots a layer, 3090 / 3060 76 / 44 80 / 48
decode, --bench (CPU plan pinned, two runs each) 18.8 / 18.5 19.2 / 19.2 tok/s
prefill 2K / 8K 309 / 585 313 / 590 tok/s

The saving grows with --max-context.

Tests (real model)

  • Exact math: STRATA_GLM_SCORE with the expert pool and the CPU plan pinned (STRATA_GLM_POOL_GB=6,
    STRATA_GLM_CPU_PLAN=011233456 - otherwise the start-up calibration moves experts between CPU and GPU and the last
    bits differ run to run): ring of 8 (wraps every 8 positions) vs no ring = KL 0.000000, identical CPU-lane
    expert counts, over 1,135 tokens and over 3,935 tokens (past 2048 tokens of context the indexer's selection
    depends on the pooled keys; below that it selects every pool, so a short test cannot catch a wrong key).
  • Prompt path: 3,499-token prefilled context, 499 scored, STRATA_GLM_PREFILL_SUB=32 and ring 64: KL 0.0155 and
    0.0188 against a prefill-vs-prefill floor of 0.0180 (the prompt path is not bit-reproducible run to run).
  • Conversations: reuse, slot set-aside / take-back and STRATA_GLM_SLOT_ROUNDTRIP exercised with ring 64.

Not built or run on HIP (the changed kernels are shared code: dsa_prep / dsa_pool index rows by p % ring).

Checks run on this branch (run on v1.0.16; the branch is rebased onto v1.0.20 - upstream's engine changes since are one INFO line and one comment; the server tests re-run on v1.0.20: 124 OK): builds (sm_75, sm_86); glm_dsa_parity, glm_ffn_parity, glm_hc_parity, glm_kda_parity, glm_layer_parity --selftest: all PASS; python -m unittest serve.test_server serve.test_tools serve.test_mcp serve.test_detok: 102 tests OK (3 skipped); the --bench request sequence (3 answers, 2K and 8K prompts) on the real model: runs clean.


The code, the measurements and this description were produced with the help of Claude, an AI assistant by Anthropic.


🔄 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/45 **Author:** [@sociolog](https://github.com/sociolog) **Created:** 10/9/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr1-indexer-ring` --- ### 📝 Commits (3) - [`67da11d`](https://github.com/mw00/project-maya/commit/67da11d8d493d20ec4114b3d1277aff1d6ceea7e) GLM fast path: the indexer key/gate rows in a ring (8196 positions) instead of max_ctx rows - [`1d59720`](https://github.com/mw00/project-maya/commit/1d59720520326e2e6e1678deef92ec8ad92769e6) score mode: STRATA_GLM_SCORE_PREFILL=1 reads the unscored context through the prompt path - [`97e24ba`](https://github.com/mw00/project-maya/commit/97e24ba47c302f567fb9a7d7942b5a8bf9cbf7cf) README: the Tuning table's row for this change's setting ### 📊 Changes **10 files changed** (+199 additions, -68 deletions) <details> <summary>View changed files</summary> 📝 `README.md` (+1 -0) 📝 `include/strata/core/glm_model.hpp` (+9 -0) 📝 `include/strata/kernels/glm_batch.hpp` (+3 -2) 📝 `include/strata/kernels/glm_fast.hpp` (+1 -0) 📝 `src/core/glm_fast_path.cu` (+90 -28) 📝 `src/core/glm_model.cu` (+23 -4) 📝 `src/core/glm_prefill.cu` (+38 -22) 📝 `src/kernels/cuda/glm_batch.cu` (+11 -7) 📝 `src/kernels/cuda/glm_fast.cu` (+7 -4) 📝 `src/program/generate.cpp` (+16 -1) </details> ### 📄 Description ## What The DSA indexer keeps two F32 rows per position - the layer-normed indexer key (`dsa_ik_`) and the compressor gate (`dsa_ig_`). They are read for exactly one thing: building the pooled key of the pool their position completes (`dsa_prep` when `(p + 1) % kpool == 0`, `dsa_pool` on the prompt path). Every later read goes to the pooled keys. So the fast path now keeps them in a **ring of 8196 positions** (a multiple of kpool; it holds the largest prompt sub-batch plus the kpool - 1 rows before it) instead of `max_ctx` rows. - `STRATA_GLM_IK_RING`: `0` = a row per position as before, `<n>` = ring size (at least 2 x kpool). README row added. - The unfinished pool's rows are running state now: the conversation snapshot keeps them (`snap_tail_`) and restores them with the KDA states - an answer longer than the ring between two turns does not lose them. - Slot files carry the unfinished pool instead of the full rows (magic `MAYALST2`; an old slot file fails the layout check and is read again). - The NextN block's prompt cache fill runs in sub-batches the ring holds; a prompt sub-batch larger than the ring is refused with a message (cannot happen with the default sizes). - `STRATA_GLM_SLOW` (reference path) keeps the full rows. - Second commit: `STRATA_GLM_SCORE_PREFILL=1` for the score mode - the unscored context goes through the prompt path, so prompt-path changes can be held to a score reference (used for the tests below). ## Why These two caches are 47 % of the DSA state. 131072 context, RTX 3090 (layers 0-28) + RTX 3060 12 GB (29-44 + NextN), Maya-M, `STRATA_GLM_RAM_RESIDENT=1`: | | before | after | |---|---:|---:| | state/KV, 3090 | 1.95 GB | 1.13 GB | | state/KV, 3060 | 1.38 GB | 0.79 GB | | expert slots a layer, 3090 / 3060 | 76 / 44 | 80 / 48 | | decode, `--bench` (CPU plan pinned, two runs each) | 18.8 / 18.5 | 19.2 / 19.2 tok/s | | prefill 2K / 8K | 309 / 585 | 313 / 590 tok/s | The saving grows with `--max-context`. ## Tests (real model) - **Exact math:** `STRATA_GLM_SCORE` with the expert pool and the CPU plan pinned (`STRATA_GLM_POOL_GB=6`, `STRATA_GLM_CPU_PLAN=011233456` - otherwise the start-up calibration moves experts between CPU and GPU and the last bits differ run to run): ring of **8** (wraps every 8 positions) vs no ring = **KL 0.000000**, identical CPU-lane expert counts, over 1,135 tokens and over **3,935 tokens** (past 2048 tokens of context the indexer's selection depends on the pooled keys; below that it selects every pool, so a short test cannot catch a wrong key). - **Prompt path:** 3,499-token prefilled context, 499 scored, `STRATA_GLM_PREFILL_SUB=32` and ring 64: KL 0.0155 and 0.0188 against a prefill-vs-prefill floor of 0.0180 (the prompt path is not bit-reproducible run to run). - **Conversations:** reuse, slot set-aside / take-back and `STRATA_GLM_SLOT_ROUNDTRIP` exercised with ring 64. Not built or run on HIP (the changed kernels are shared code: `dsa_prep` / `dsa_pool` index rows by `p % ring`). **Checks run on this branch (run on v1.0.16; the branch is rebased onto v1.0.20 - upstream's engine changes since are one INFO line and one comment; the server tests re-run on v1.0.20: 124 OK):** builds (sm_75, sm_86); `glm_dsa_parity`, `glm_ffn_parity`, `glm_hc_parity`, `glm_kda_parity`, `glm_layer_parity` `--selftest`: all PASS; `python -m unittest serve.test_server serve.test_tools serve.test_mcp serve.test_detok`: 102 tests OK (3 skipped); the `--bench` request sequence (3 answers, 2K and 8K prompts) on the real model: runs clean. --- *The code, the measurements and this description were produced with the help of Claude, an AI assistant by Anthropic.* --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-29 21:23:57 +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#298
No description provided.