[PR #242] [CLOSED] glm prefill: the prompt path's MMQ scratch rides in the loan (a 16 MB size-class slab) - the 16k-chunk out-of-memory that killed every prompt is gone #418

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

📋 Pull Request Information

Original PR: https://github.com/mw00/project-maya/pull/242
Author: @gopinath87607
Created: 10/17/2026
Status: ❌ Closed

Base: main ← Head: pr/mmq-slab


📝 Commits (1)

  • 9825ca0 glm prefill: the prompt path's MMQ scratch rides in the loan (mmq::pool_slab + size classes), and the pool is sized knowing it - the abort that killed every prompt at a 16k chunk ("ggml-cuda (strata mmq): out of memory", CUDA1, mid-prompt) is gone

📊 Changes

8 files changed (+265 additions, -21 deletions)

View changed files

📝 docs/SETTINGS.md (+1 -0)
📝 include/strata/core/glm_model.hpp (+1 -0)
📝 include/strata/prefill/moe_mmq.hpp (+6 -0)
📝 src/core/glm_fast_path.cu (+28 -0)
📝 src/core/glm_fast_state.hpp (+3 -0)
📝 src/core/glm_prefill.cu (+135 -12)
📝 src/prefill/ggml_cuda_host.cu (+87 -9)
📝 src/prefill/moe_mmq.cu (+4 -0)

📄 Description

What this changes

The prompt path's MMQ kernels (llama.cpp's mmq.cuh) allocate their stream-k fixup tiles lazily through ggml_cuda_pool, which this build's ggml_cuda_host.cu backs with a CachingPool that cudaMallocs on demand - on whatever VRAM is free at that moment, which by the time a chunk runs is the card's leftovers. At a 16,384-token chunk that was 3.4 MB free of 7,707.7 MB on CUDA1, and the fixup buffer it wanted (1.2 MB) did not fit: ggml_cuda_error aborted the engine, so every prompt died mid-run and took the server's engine with it.

Three changes, all in that path:

  • The pool allocates in size classes (a power of two, 128 KB floor: 128 KB..2 MB covers the whole J range on a 30-SM card) and hands back the class size, and the reuse scan is restored. mmq.cuh picks a different J per launch; keyed on the exact size, the pool held one buffer per J - 32 buffers, 31.5 MB measured within one 579-token chunk, and the same at 16k, since J does not grow with T. A class is what a caching allocator is for, and it bounds the pool to a few MB whatever J wins.
  • The memory comes from the loan: prefill_lend raises the lending limit by kMmqSlab (16 MB, a bound - the fixup buffer is at most nsm * J * I * 4 = ~2 MB, independent of the chunk size) and hands [need, need + 16 MB) of the freed tail to the pool (mmq::pool_slab, called per chunk since the layout's need moves with T, and cleared when prefill_return gives the region back). Every byte lies in a slot whose start is below the limit, so it is provably lent; it costs a few more experts per part (measured: 42 CUDA0, 44 CUDA1, 46 CUDA2, 47 CUDA3, printed once per part) and no change to the chunk arithmetic. F->lend_end, recorded by lend_tail, marks where the loan ends.
  • fast_setup sizes the expert pool from free VRAM and did not know the prompt path keeps a scratch pool, so STRATA_GLM_MMQ_RESERVE_MB (default 0: the slab covers it) is subtracted by both fast_setup and prefill_setup, so the pool it sizes is the pool it gets. Separate from the slab, cuBLAS loads its kernels lazily and was failing every GEMM of a chunk with CUBLAS_STATUS_EXECUTION_FAILED and no CUDA error behind it when it first ran on a card the pool had filled; one small warm-up GEMM of each kind at prefill_setup now runs while the pool does not exist yet (measured: CUDA0 at 4.53 GB of 7.53 GB, 110 MB free, failed every GEMM before and runs them after).

This branch is rebased onto current main (a4e1ff0), whose pool sizing is the newer PoolBudget/part_budget code: the slab is built on top of it, and the checkout commit's comma-separated STRATA_GLM_RESERVE_MB list is not included because main superseded it with STRATA_GLM_RESERVE_LATER_MB.

What it leaves alone

The chunk arithmetic and the equal-chunk path are untouched. STRATA_GLM_MMQ_RESERVE_MB defaults to 0. The slab is bounded at 16 MB and is used only by the prompt path; a build without the prompt path is unchanged.

Measurements

  • The failure: at 16,384 tokens a chunk, 3.4 MB free of 7,707.7 MB on CUDA1, a 1.2 MB fixup buffer that did not fit; ggml_cuda_error aborted the engine and every prompt died mid-run.
  • The bound: the fixup buffer is nsm * J * I * 4 = ~2 MB at most (J from its 8..128 step-8 search), independent of the chunk size; the pool held 32 buffers / 31.5 MB within one 579-token chunk.
  • The cost: 42 / 44 / 46 / 47 more experts lent per part, printed once per part.
  • cuBLAS: CUDA0 at 4.53 GB of 7.53 GB, 110 MB free - every GEMM failed before the warm-up and runs after it.
  • Verified on the live four-way split (2x RTX 5060 8 GB + 2x RTX 3060 12 GB): three restarts, warm prompts of 579-580 tokens through all four parts, the 100,535-token read repeated to completion, no OOM and no cuBLAS failure in the log.

Checks

  • src/core/glm_prefill.cu, src/core/glm_fast_path.cu, src/prefill/ggml_cuda_host.cu and src/prefill/moe_mmq.cu compile clean with the build's own flags (nvcc 13.2, compute_86 + compute_120).
  • python3 tools/check_hip_compat.py passes.
  • Not run in this branch's preparation; the verification above is the checkout's, on the hardware named.

🤖 Generated with Claude Code


🔄 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/242 **Author:** [@gopinath87607](https://github.com/gopinath87607) **Created:** 10/17/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/mmq-slab` --- ### 📝 Commits (1) - [`9825ca0`](https://github.com/mw00/project-maya/commit/9825ca0c9533916dc85337493274ef51a4f1e259) glm prefill: the prompt path's MMQ scratch rides in the loan (mmq::pool_slab + size classes), and the pool is sized knowing it - the abort that killed every prompt at a 16k chunk ("ggml-cuda (strata mmq): out of memory", CUDA1, mid-prompt) is gone ### 📊 Changes **8 files changed** (+265 additions, -21 deletions) <details> <summary>View changed files</summary> 📝 `docs/SETTINGS.md` (+1 -0) 📝 `include/strata/core/glm_model.hpp` (+1 -0) 📝 `include/strata/prefill/moe_mmq.hpp` (+6 -0) 📝 `src/core/glm_fast_path.cu` (+28 -0) 📝 `src/core/glm_fast_state.hpp` (+3 -0) 📝 `src/core/glm_prefill.cu` (+135 -12) 📝 `src/prefill/ggml_cuda_host.cu` (+87 -9) 📝 `src/prefill/moe_mmq.cu` (+4 -0) </details> ### 📄 Description ## What this changes The prompt path's MMQ kernels (llama.cpp's `mmq.cuh`) allocate their stream-k fixup tiles lazily through `ggml_cuda_pool`, which this build's `ggml_cuda_host.cu` backs with a `CachingPool` that `cudaMalloc`s on demand - on whatever VRAM is free at that moment, which by the time a chunk runs is the card's leftovers. At a 16,384-token chunk that was 3.4 MB free of 7,707.7 MB on CUDA1, and the fixup buffer it wanted (1.2 MB) did not fit: `ggml_cuda_error` aborted the engine, so every prompt died mid-run and took the server's engine with it. Three changes, all in that path: - The pool allocates in size classes (a power of two, 128 KB floor: 128 KB..2 MB covers the whole `J` range on a 30-SM card) and hands back the class size, and the reuse scan is restored. `mmq.cuh` picks a different `J` per launch; keyed on the exact size, the pool held one buffer per `J` - 32 buffers, 31.5 MB measured within one 579-token chunk, and the same at 16k, since `J` does not grow with `T`. A class is what a caching allocator is for, and it bounds the pool to a few MB whatever `J` wins. - The memory comes from the loan: `prefill_lend` raises the lending limit by `kMmqSlab` (16 MB, a bound - the fixup buffer is at most `nsm * J * I * 4` = ~2 MB, independent of the chunk size) and hands `[need, need + 16 MB)` of the freed tail to the pool (`mmq::pool_slab`, called per chunk since the layout's need moves with `T`, and cleared when `prefill_return` gives the region back). Every byte lies in a slot whose start is below the limit, so it is provably lent; it costs a few more experts per part (measured: 42 CUDA0, 44 CUDA1, 46 CUDA2, 47 CUDA3, printed once per part) and no change to the chunk arithmetic. `F->lend_end`, recorded by `lend_tail`, marks where the loan ends. - `fast_setup` sizes the expert pool from free VRAM and did not know the prompt path keeps a scratch pool, so `STRATA_GLM_MMQ_RESERVE_MB` (default 0: the slab covers it) is subtracted by both `fast_setup` and `prefill_setup`, so the pool it sizes is the pool it gets. Separate from the slab, cuBLAS loads its kernels lazily and was failing every GEMM of a chunk with `CUBLAS_STATUS_EXECUTION_FAILED` and no CUDA error behind it when it first ran on a card the pool had filled; one small warm-up GEMM of each kind at `prefill_setup` now runs while the pool does not exist yet (measured: CUDA0 at 4.53 GB of 7.53 GB, 110 MB free, failed every GEMM before and runs them after). This branch is rebased onto current `main` (a4e1ff0), whose pool sizing is the newer `PoolBudget`/`part_budget` code: the slab is built on top of it, and the checkout commit's comma-separated `STRATA_GLM_RESERVE_MB` list is not included because `main` superseded it with `STRATA_GLM_RESERVE_LATER_MB`. ## What it leaves alone The chunk arithmetic and the equal-chunk path are untouched. `STRATA_GLM_MMQ_RESERVE_MB` defaults to 0. The slab is bounded at 16 MB and is used only by the prompt path; a build without the prompt path is unchanged. ## Measurements - The failure: at 16,384 tokens a chunk, 3.4 MB free of 7,707.7 MB on CUDA1, a 1.2 MB fixup buffer that did not fit; `ggml_cuda_error` aborted the engine and every prompt died mid-run. - The bound: the fixup buffer is `nsm * J * I * 4` = ~2 MB at most (`J` from its 8..128 step-8 search), independent of the chunk size; the pool held 32 buffers / 31.5 MB within one 579-token chunk. - The cost: 42 / 44 / 46 / 47 more experts lent per part, printed once per part. - cuBLAS: CUDA0 at 4.53 GB of 7.53 GB, 110 MB free - every GEMM failed before the warm-up and runs after it. - Verified on the live four-way split (2x RTX 5060 8 GB + 2x RTX 3060 12 GB): three restarts, warm prompts of 579-580 tokens through all four parts, the 100,535-token read repeated to completion, no OOM and no cuBLAS failure in the log. ## Checks - `src/core/glm_prefill.cu`, `src/core/glm_fast_path.cu`, `src/prefill/ggml_cuda_host.cu` and `src/prefill/moe_mmq.cu` compile clean with the build's own flags (nvcc 13.2, compute_86 + compute_120). - `python3 tools/check_hip_compat.py` passes. - Not run in this branch's preparation; the verification above is the checkout's, on the hardware named. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <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:12 +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#418
No description provided.