[PR #3841] [CLOSED] [Engine] q36: STRATA_Q36_SINGLE_STAGE=1 keeps one staging buffer, and STRATA_Q36_NO_MMQ takes a number #4799

Closed
opened 2026-11-07 15:39:07 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/3841
Author: @ggeorgovassilis
Created: 10/23/2026
Status: ❌ Closed

Base: main ← Head: q36-single-staging


📝 Commits (2)

  • 2802555 q36: STRATA_Q36_SINGLE_STAGE=1 streams a prompt chunk through one staging buffer, halving that VRAM
  • 907a145 q36 docs: the staging switch's measurement and what the numeric NO_MMQ changes for a script that set it to 0

📊 Changes

2 files changed (+25 additions, -12 deletions)

View changed files

📝 docs/QWEN36.md (+7 -0)
📝 src/qwen35/q36_engine.cu (+18 -12)

📄 Description

Problem and result

In the hybrid mode a prompt chunk streams each layer's experts into a staging buffer, and two are kept so one layer copies while the other computes. On a card whose free VRAM only just holds the experts plus that staging, the second buffer is the difference between starting and cudaMalloc(&E.stage[b], ...) failed: out of memory - and there was no way to ask for one. STRATA_Q36_NO_MMQ was on/off by presence, so 0 turned MMQ off, which reads wrong in a script or a launcher that passes 0 for "off".

After: STRATA_Q36_SINGLE_STAGE=1 keeps one staging buffer (staging 1.10 -> 0.55 GiB measured below) and STRATA_Q36_NO_MMQ takes a number (0 / unset = MMQ on, 1 = off). Both are opt-in: unset, the engine takes the same path as before (two buffers, MMQ on) and the tokens are identical (measured below).

  • Issue: https://github.com/ggeorgovassilis/Strata/issues/3 (scope agreed there).
  • The two earlier PRs this comes from are closed and were not merged as they stood: Niko1221/Strata#2742 (bundled with an int8 K/V cache) and Niko1221/Strata#2698 (the K/V-cache half). This PR is only the staging slice of #2742's 3a9e6c88.

Of the three items the issue asks for, two are still needed and are here. The third, and STRATA_Q36_PLACE_DEBUG, are already upstream and are not in this PR:

  • the attention-scores buffer shrink (256 -> 64 MB) is upstream as shrink_att() with the mtp_only path;
  • STRATA_Q36_PLACE_DEBUG is upstream.

Approach

src/qwen35/q36_engine.cu:

  • int n_stage = 2; on the engine, read once in init() from STRATA_Q36_SINGLE_STAGE (any number above 0 = 1 buffer).
  • The four places that were hardcoded to two buffers now use it: stream_begin() prefetches n_stage layers, stream_kick() / stream_take() / stream_done() index i % n_stage, place_experts() sizes the reservation and the cudaMalloc loop from it.
  • use_mmq reads STRATA_Q36_NO_MMQ with std::atoi instead of testing the presence of the variable.

Compatibility: with the variable unset nothing changes. STRATA_Q36_NO_MMQ set to anything non-numeric or 1 still turns MMQ off; set to 0 it now leaves it on (it used to turn it off). That is the point of the numeric form, and docs/QWEN36.md says it.

Validation

Revision: 907a1452 on q36-single-staging (over upstream 5c8dd322). Machine: RTX 4060 Laptop 8 GB, Linux, CUDA 13.0, model Qwen3.6-35B-A3B-UD-Q4_K_XL (22.9 GB, so the hybrid mode is the one in use), --max-context 4096 --chunk 512, a 1,400-token prompt (three prompt chunks, so the stream runs three times) and 24 greedy tokens, driven through the serve protocol.

Passed:

C++ build, CUDA 13.0, sm_89 - docker build --target engine-build --build-arg CUDA_ARCHITECTURES=89 --build-arg BUILD_VISION=0 . -> [165/165] Linking CXX executable strata, exit 0, warnings only, all pre-existing (the four in q36_engine.cu are at lines 199, 233, 1652 and 1889 - untouched code, the same ones the base build prints).

C++ build, HIP 7.14 (ROCm dev image), gfx1201 - cmake -DSTRATA_ENABLE_HIP=ON -DCMAKE_HIP_ARCHITECTURES=gfx1201 ... then cmake --build build-hip --target strata -> Linking HIP static library libstrata_qwen35.a, Linking HIP executable strata, HIP_BUILD_OK, exit 0 (warnings as above: iq_kernels.cu and the same pre-existing four in q36_engine.cu).

Tokens, staging on (default) against the unmodified upstream build (engine-build-q36-base, same source otherwise): identical, 13 of 13 tokens (tools/qwen35/q36_cmp_gate.py -> p00 identical).

Tokens, STRATA_Q36_SINGLE_STAGE=1 against the default: identical, 13 of 13. Staging size from the engine's own placement line: 1.10 GiB staging with the default, 0.55 GiB staging with the switch - half, as intended.

Tokens, STRATA_Q36_NO_MMQ=0 against unset: identical, 13 of 13, and staging stays at 1.10 GiB (MMQ on). STRATA_Q36_NO_MMQ=1: MMQ off (0.00 GiB staging, the prompt has no streamed path then), prompt 1400 tokens in 13.57 s against 4.46 s, tokens still identical 13 of 13.

Before/after of the compatibility note: the unmodified build with STRATA_Q36_NO_MMQ=0 prints 0.00 GiB staging and reads the prompt in 12.36 s (MMQ off, the old meaning); this branch with the same variable reads it in 4.46 s with 1.10 GiB staging (MMQ on).

Python suites, unrelated to this change but run on this branch: python -m pytest tests/terminal -> 1518 passed, 47 skipped, 17 failed; python -m pytest tools/test_setup_*.py -> 733 passed, 1 skipped, 49 failed. The same 17 and the same 49 fail on a clean upstream/main worktree here (git worktree add /tmp/strata-base upstream/main), with the same names - checked by diffing the two failure lists: identical, so they are this machine's (no CUDA device names in their fixtures, hostname/paths) and not this change.

Failed:
none observed.

Not run:

  • SYCL: this family does not run on it.
  • ROCm run on a real AMD card: the HIP build above is a compile only (the container has no card), so HIP runtime behaviour of the single buffer is unverified.
  • The GPU gates in tools/qwen35/ that need many prompts (q36_batch_gate.py, q36_proto_edge.py, q36_par_bench.py): the 8 GB card in the hybrid mode was used for the token-parity runs above, not those.

Limits

  • One buffer means copy and compute take turns, so a streamed prompt is slower: 4.94 s against 4.46 s for the 1,400-token prompt above (~10%). It buys VRAM, not speed.
  • The switch only matters in the hybrid mode with MMQ on; with every expert in VRAM, or with STRATA_Q36_NO_MMQ=1, there is no staging and it does nothing.
  • STRATA_Q36_NO_MMQ=0 changed meaning as described; a script that relied on =0 turning MMQ off needs =1.

🔄 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/Niko1221/Strata/pull/3841 **Author:** [@ggeorgovassilis](https://github.com/ggeorgovassilis) **Created:** 10/23/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `q36-single-staging` --- ### 📝 Commits (2) - [`2802555`](https://github.com/Niko1221/Strata/commit/28025559955764d56b4cd0357e9b42da9536c690) q36: STRATA_Q36_SINGLE_STAGE=1 streams a prompt chunk through one staging buffer, halving that VRAM - [`907a145`](https://github.com/Niko1221/Strata/commit/907a1452f092c55e67040d29f765bf61b0014b10) q36 docs: the staging switch's measurement and what the numeric NO_MMQ changes for a script that set it to 0 ### 📊 Changes **2 files changed** (+25 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `docs/QWEN36.md` (+7 -0) 📝 `src/qwen35/q36_engine.cu` (+18 -12) </details> ### 📄 Description ## Problem and result In the hybrid mode a prompt chunk streams each layer's experts into a staging buffer, and two are kept so one layer copies while the other computes. On a card whose free VRAM only just holds the experts plus that staging, the second buffer is the difference between starting and `cudaMalloc(&E.stage[b], ...) failed: out of memory` - and there was no way to ask for one. `STRATA_Q36_NO_MMQ` was on/off by presence, so `0` turned MMQ off, which reads wrong in a script or a launcher that passes `0` for "off". After: `STRATA_Q36_SINGLE_STAGE=1` keeps one staging buffer (staging 1.10 -> 0.55 GiB measured below) and `STRATA_Q36_NO_MMQ` takes a number (`0` / unset = MMQ on, `1` = off). Both are opt-in: unset, the engine takes the same path as before (two buffers, MMQ on) and the tokens are identical (measured below). ## Related discussion - Issue: https://github.com/ggeorgovassilis/Strata/issues/3 (scope agreed there). - The two earlier PRs this comes from are closed and were not merged as they stood: Niko1221/Strata#2742 (bundled with an int8 K/V cache) and Niko1221/Strata#2698 (the K/V-cache half). This PR is only the staging slice of #2742's `3a9e6c88`. Of the three items the issue asks for, two are still needed and are here. The third, and `STRATA_Q36_PLACE_DEBUG`, are already upstream and are **not** in this PR: - the attention-scores buffer shrink (256 -> 64 MB) is upstream as `shrink_att()` with the `mtp_only` path; - `STRATA_Q36_PLACE_DEBUG` is upstream. ## Approach `src/qwen35/q36_engine.cu`: - `int n_stage = 2;` on the engine, read once in `init()` from `STRATA_Q36_SINGLE_STAGE` (any number above `0` = 1 buffer). - The four places that were hardcoded to two buffers now use it: `stream_begin()` prefetches `n_stage` layers, `stream_kick()` / `stream_take()` / `stream_done()` index `i % n_stage`, `place_experts()` sizes the reservation and the `cudaMalloc` loop from it. - `use_mmq` reads `STRATA_Q36_NO_MMQ` with `std::atoi` instead of testing the presence of the variable. Compatibility: with the variable unset nothing changes. `STRATA_Q36_NO_MMQ` set to anything non-numeric or `1` still turns MMQ off; set to `0` it now leaves it on (it used to turn it off). That is the point of the numeric form, and `docs/QWEN36.md` says it. ## Validation Revision: `907a1452` on `q36-single-staging` (over upstream `5c8dd322`). Machine: RTX 4060 Laptop 8 GB, Linux, CUDA 13.0, model `Qwen3.6-35B-A3B-UD-Q4_K_XL` (22.9 GB, so the hybrid mode is the one in use), `--max-context 4096 --chunk 512`, a 1,400-token prompt (three prompt chunks, so the stream runs three times) and 24 greedy tokens, driven through the serve protocol. **Passed:** C++ build, CUDA 13.0, sm_89 - `docker build --target engine-build --build-arg CUDA_ARCHITECTURES=89 --build-arg BUILD_VISION=0 .` -> `[165/165] Linking CXX executable strata`, exit 0, warnings only, all pre-existing (the four in `q36_engine.cu` are at lines 199, 233, 1652 and 1889 - untouched code, the same ones the base build prints). C++ build, HIP 7.14 (ROCm dev image), gfx1201 - `cmake -DSTRATA_ENABLE_HIP=ON -DCMAKE_HIP_ARCHITECTURES=gfx1201 ...` then `cmake --build build-hip --target strata` -> `Linking HIP static library libstrata_qwen35.a`, `Linking HIP executable strata`, `HIP_BUILD_OK`, exit 0 (warnings as above: `iq_kernels.cu` and the same pre-existing four in `q36_engine.cu`). Tokens, staging on (default) against the **unmodified** upstream build (`engine-build-q36-base`, same source otherwise): identical, 13 of 13 tokens (`tools/qwen35/q36_cmp_gate.py` -> `p00 identical`). Tokens, `STRATA_Q36_SINGLE_STAGE=1` against the default: identical, 13 of 13. Staging size from the engine's own placement line: `1.10 GiB staging` with the default, `0.55 GiB staging` with the switch - half, as intended. Tokens, `STRATA_Q36_NO_MMQ=0` against unset: identical, 13 of 13, and staging stays at `1.10 GiB` (MMQ on). `STRATA_Q36_NO_MMQ=1`: MMQ off (`0.00 GiB staging`, the prompt has no streamed path then), prompt 1400 tokens in 13.57 s against 4.46 s, tokens still identical 13 of 13. Before/after of the compatibility note: the unmodified build with `STRATA_Q36_NO_MMQ=0` prints `0.00 GiB staging` and reads the prompt in 12.36 s (MMQ off, the old meaning); this branch with the same variable reads it in 4.46 s with `1.10 GiB staging` (MMQ on). Python suites, unrelated to this change but run on this branch: `python -m pytest tests/terminal` -> 1518 passed, 47 skipped, 17 failed; `python -m pytest tools/test_setup_*.py` -> 733 passed, 1 skipped, 49 failed. **The same 17 and the same 49 fail on a clean `upstream/main` worktree here** (`git worktree add /tmp/strata-base upstream/main`), with the same names - checked by diffing the two failure lists: identical, so they are this machine's (no CUDA device names in their fixtures, hostname/paths) and not this change. **Failed:** none observed. **Not run:** - SYCL: this family does not run on it. - ROCm run on a real AMD card: the HIP build above is a compile only (the container has no card), so HIP runtime behaviour of the single buffer is unverified. - The GPU gates in `tools/qwen35/` that need many prompts (`q36_batch_gate.py`, `q36_proto_edge.py`, `q36_par_bench.py`): the 8 GB card in the hybrid mode was used for the token-parity runs above, not those. ## Limits - One buffer means copy and compute take turns, so a streamed prompt is slower: 4.94 s against 4.46 s for the 1,400-token prompt above (~10%). It buys VRAM, not speed. - The switch only matters in the hybrid mode with MMQ on; with every expert in VRAM, or with `STRATA_Q36_NO_MMQ=1`, there is no staging and it does nothing. - `STRATA_Q36_NO_MMQ=0` changed meaning as described; a script that relied on `=0` turning MMQ off needs `=1`. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 15:39:07 +07:00
Sign in to join this conversation.
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
Niko1221/Strata#4799
No description provided.