[PR #4335] [Engine] q36: a 4096-token prompt chunk in the hybrid mode when the card has room #5012

Open
opened 2026-11-07 16:32:01 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4335
Author: @rynwang
Created: 10/27/2026
Status: 🔄 Open

Base: main ← Head: q36-hybrid-chunk-4096


📝 Commits (1)

  • 61caa0d q36: a 4096-token prompt chunk in the hybrid mode when the card has room

📊 Changes

2 files changed (+34 additions, -16 deletions)

View changed files

📝 docs/QWEN36.md (+11 -7)
📝 src/qwen35/q36_engine.cu (+23 -9)

📄 Description

Scope question is in #4332 (this changes a default, and CONTRIBUTING.md asks for agreement first). Happy to turn it
into an opt-in or move the boundary on request, and STRATA_Q36_CHUNK=2048 gives today's chunk either way.

The change itself is one block in the hybrid branch of the chunk rule plus the prompt-chunk section of
docs/QWEN36.md.

Problem and result

With Qwen3.6-35B-A3B-UD-Q4_K_XL on a 16 GB card, the q36 engine's hybrid mode picks the prompt chunk with a fixed
rule (2048 above 7.5 GiB free, 1024 above 5.5, else 512) and never tries 4096. A prompt chunk streams every layer's
experts over PCIe once, so a 4096-token prompt pays that cost per chunk, not per token. Measuring the two arms on the
same binary (RTX 4080 SUPER 16 GB, WSL2, i7-14700KF, engine 0.1.54 at 870aedd, CUDA 12.4, --mtp 2, three
alternating runs per arm, medians):

cells chunk prompt tok/s prompt ms (runs) decode tok/s experts in VRAM
8192 2048 840 4,830 / 4,872 / 4,885 61.9 79 / 256
8192 4096 1,272 3,224 / 3,208 / 3,218 61.8 66 / 256
32768 2048 779 5,256 / 5,370 / 5,032 51.7 63 / 256
32768 4096 1,372 3,120 / 2,847 / 2,852 54.1 50 / 256
16384 (8,192-token prompt) 2048 857 10,366 / 9,485 45.3 63 / 256
16384 (8,192-token prompt) 4096 1,410 5,645 / 5,985 47.7 50 / 256

So: prompt reading 51% faster at 8K context, 76% faster at 32K (4.9 s -> 3.2 s and 5.3 s -> 2.9 s for a 4096-token
prompt), and 64% faster at 16K with an 8,192-token prompt (10.4 s -> 5.6 s); decode unchanged at 8K, and 4-6%
faster at 32K/16K, where the MTP drafts were accepted more often.

Approach

In the hybrid branch, take 4096 when the chunk's buffers fit in a third of the room the expert slots keep at a
512-token chunk; otherwise keep today's rule:

room = fr_raw - 2.97 GiB - ctx * n_attn * n_head_kv * head_dim * 8
chunk = 4096 if (4096 - 512) * 0.5 MiB <= room / 3
  • 0.5 MiB per token is the measured growth of the chunk's buffers (0.47 MiB at these sizes).
  • 2.97 GiB is the engine's buffers at 512, the staging pair and the 0.77 GiB reserve, measured at 8192 and 32768
    cells.
  • The K / V term keeps a long context on 2048: at 65536 cells the rule chooses 2048 (4.89 GiB free after init,
    41 experts per layer), which is the arm 0.1.52 runs today.
  • A 12 GB card keeps 2048: the chunk's buffers would take most of its slots' room, where docs/QWEN36.md measured a
    13% decode loss for 4096 on an RTX 3060.
  • --batch keeps the smaller chunk (the 4096 arm runs only with one slot).

The diff is the rule, its comment, and the prompt-chunk section of docs/QWEN36.md.

Validation

Passed (RTX 4080 SUPER 16 GB, WSL2 Ubuntu 22.04, driver 581.80, CUDA 12.4 build for sm_89 + sm_61):

  • Built main at 5e8a4cc with and without the change; the same binary with --chunk 2048 and with the new rule,
    three alternating runs per arm at 8192 and 32768 cells (table above).
  • New rule chooses 4096 at 8192 and 32768 cells and 2048 at 65536 cells (STRATA_Q36_PLACE_DEBUG=1 shows the
    inputs: free 11.50 GiB, raw 9.72, experts 18.29 GiB).
  • The model loads and runs on the 11 GB GTX 1080 Ti (sm_61) with the change too, and that card keeps its old chunk:
    its free VRAM is below 7.5 GiB, so the rule picks 1024 as before and the new arm does not apply (23 experts per
    layer, 34 tok/s decode; that card is not used in the numbers above).
  • ctest with -DSTRATA_BUILD_TESTS=ON on this build (sm_61 + sm_89, CUDA 12.4): 201 of 205 pass. The 4 failures are
    environment/build-configuration ones, none in code this change touches — ple_parity (the Qwen3.8 PLE shard fixture
    is not on this machine), platform_memory_test (a host-memory heuristic sized for a larger guest than this 24 GB
    WSL one), isa_guard_check (an AVX-512 function is not on this build's allowlist) and cuda_spill_guard (the
    stack-use allowlist does not cover sm_61/sm_89 with this toolkit).

Not run:

  • 12 GB and 8 GB cards; the boundary there is arithmetic from the measured 0.5 MiB/token and the RTX 3060 line in
    the docs, not a measurement.
  • HIP, SYCL, Metal and Windows builds (the change is device-neutral host code in strata::qwen35::run).
  • --batch / parallel requests beyond compiling the batch > 1 guard.

Independent validation (from the comments)

  • RTX 5060 Ti 16 GB, Windows, MSVC 19.42 / CUDA 13.2 / sm_120 (Thymos2027): five alternating pairs per input on
    the PR binary. A 16,385-token input reads 1.30x faster (7,165 -> 5,503 ms, 5/5 pairs); a 1,025-token input is one
    chunk either way, so prefill is identical (809.1 against 808.5 ms) and the generation pays ~3% for the 13 slots
    4096 costs there. Same-chunk logits against main are bitwise equal, and the auto rule equals main with an
    explicit --chunk 4096.

Limits

  • The chunk size changes the GEMM tiles the BLAS picks, so the text differs in its last bits from the 2048 arm. This
    is the difference docs/QWEN36.md already describes for every chunk size except 512; the change does not touch
    kernels, routing, precision or the KV cache.
  • The gain is prompt-side (time to first token). Decode follows the experts' placement and is unchanged at 8K; at 32K
    it moved +4.6% here, but I would not quote that as a decode improvement.

Fixes #4332 once the scope is agreed.


🔄 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/4335 **Author:** [@rynwang](https://github.com/rynwang) **Created:** 10/27/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `q36-hybrid-chunk-4096` --- ### 📝 Commits (1) - [`61caa0d`](https://github.com/Niko1221/Strata/commit/61caa0d40fe31845ee3c135dc4dbcd19b8473456) q36: a 4096-token prompt chunk in the hybrid mode when the card has room ### 📊 Changes **2 files changed** (+34 additions, -16 deletions) <details> <summary>View changed files</summary> 📝 `docs/QWEN36.md` (+11 -7) 📝 `src/qwen35/q36_engine.cu` (+23 -9) </details> ### 📄 Description Scope question is in #4332 (this changes a default, and CONTRIBUTING.md asks for agreement first). Happy to turn it into an opt-in or move the boundary on request, and `STRATA_Q36_CHUNK=2048` gives today's chunk either way. The change itself is one block in the hybrid branch of the chunk rule plus the prompt-chunk section of `docs/QWEN36.md`. ## Problem and result With Qwen3.6-35B-A3B-UD-Q4_K_XL on a 16 GB card, the q36 engine's hybrid mode picks the prompt chunk with a fixed rule (2048 above 7.5 GiB free, 1024 above 5.5, else 512) and never tries 4096. A prompt chunk streams every layer's experts over PCIe once, so a 4096-token prompt pays that cost per chunk, not per token. Measuring the two arms on the same binary (RTX 4080 SUPER 16 GB, WSL2, i7-14700KF, engine 0.1.54 at 870aedd, CUDA 12.4, `--mtp 2`, three alternating runs per arm, medians): | cells | chunk | prompt tok/s | prompt ms (runs) | decode tok/s | experts in VRAM | | --- | --- | --- | --- | --- | --- | | 8192 | 2048 | 840 | 4,830 / 4,872 / 4,885 | 61.9 | 79 / 256 | | 8192 | 4096 | **1,272** | 3,224 / 3,208 / 3,218 | 61.8 | 66 / 256 | | 32768 | 2048 | 779 | 5,256 / 5,370 / 5,032 | 51.7 | 63 / 256 | | 32768 | 4096 | **1,372** | 3,120 / 2,847 / 2,852 | 54.1 | 50 / 256 | | 16384 (8,192-token prompt) | 2048 | 857 | 10,366 / 9,485 | 45.3 | 63 / 256 | | 16384 (8,192-token prompt) | 4096 | **1,410** | 5,645 / 5,985 | 47.7 | 50 / 256 | So: prompt reading 51% faster at 8K context, 76% faster at 32K (4.9 s -> 3.2 s and 5.3 s -> 2.9 s for a 4096-token prompt), and 64% faster at 16K with an 8,192-token prompt (10.4 s -> 5.6 s); decode unchanged at 8K, and 4-6% faster at 32K/16K, where the MTP drafts were accepted more often. ## Approach In the hybrid branch, take 4096 when the chunk's buffers fit in a third of the room the expert slots keep at a 512-token chunk; otherwise keep today's rule: ``` room = fr_raw - 2.97 GiB - ctx * n_attn * n_head_kv * head_dim * 8 chunk = 4096 if (4096 - 512) * 0.5 MiB <= room / 3 ``` - 0.5 MiB per token is the measured growth of the chunk's buffers (0.47 MiB at these sizes). - 2.97 GiB is the engine's buffers at 512, the staging pair and the 0.77 GiB reserve, measured at 8192 and 32768 cells. - The K / V term keeps a long context on 2048: at 65536 cells the rule chooses 2048 (4.89 GiB free after init, 41 experts per layer), which is the arm 0.1.52 runs today. - A 12 GB card keeps 2048: the chunk's buffers would take most of its slots' room, where docs/QWEN36.md measured a 13% decode loss for 4096 on an RTX 3060. - `--batch` keeps the smaller chunk (the 4096 arm runs only with one slot). The diff is the rule, its comment, and the prompt-chunk section of docs/QWEN36.md. ## Validation Passed (RTX 4080 SUPER 16 GB, WSL2 Ubuntu 22.04, driver 581.80, CUDA 12.4 build for sm_89 + sm_61): - Built `main` at 5e8a4cc with and without the change; the same binary with `--chunk 2048` and with the new rule, three alternating runs per arm at 8192 and 32768 cells (table above). - New rule chooses 4096 at 8192 and 32768 cells and 2048 at 65536 cells (`STRATA_Q36_PLACE_DEBUG=1` shows the inputs: free 11.50 GiB, raw 9.72, experts 18.29 GiB). - The model loads and runs on the 11 GB GTX 1080 Ti (sm_61) with the change too, and that card keeps its old chunk: its free VRAM is below 7.5 GiB, so the rule picks 1024 as before and the new arm does not apply (23 experts per layer, 34 tok/s decode; that card is not used in the numbers above). - `ctest` with `-DSTRATA_BUILD_TESTS=ON` on this build (sm_61 + sm_89, CUDA 12.4): 201 of 205 pass. The 4 failures are environment/build-configuration ones, none in code this change touches — `ple_parity` (the Qwen3.8 PLE shard fixture is not on this machine), `platform_memory_test` (a host-memory heuristic sized for a larger guest than this 24 GB WSL one), `isa_guard_check` (an AVX-512 function is not on this build's allowlist) and `cuda_spill_guard` (the stack-use allowlist does not cover sm_61/sm_89 with this toolkit). Not run: - 12 GB and 8 GB cards; the boundary there is arithmetic from the measured 0.5 MiB/token and the RTX 3060 line in the docs, not a measurement. - HIP, SYCL, Metal and Windows builds (the change is device-neutral host code in `strata::qwen35::run`). - `--batch` / parallel requests beyond compiling the `batch > 1` guard. ## Independent validation (from the comments) - **RTX 5060 Ti 16 GB, Windows, MSVC 19.42 / CUDA 13.2 / sm_120** (Thymos2027): five alternating pairs per input on the PR binary. A 16,385-token input reads 1.30x faster (7,165 -> 5,503 ms, 5/5 pairs); a 1,025-token input is one chunk either way, so prefill is identical (809.1 against 808.5 ms) and the generation pays ~3% for the 13 slots 4096 costs there. Same-chunk logits against `main` are bitwise equal, and the auto rule equals `main` with an explicit `--chunk 4096`. ## Limits - The chunk size changes the GEMM tiles the BLAS picks, so the text differs in its last bits from the 2048 arm. This is the difference docs/QWEN36.md already describes for every chunk size except 512; the change does not touch kernels, routing, precision or the KV cache. - The gain is prompt-side (time to first token). Decode follows the experts' placement and is unchanged at 8K; at 32K it moved +4.6% here, but I would not quote that as a decode improvement. Fixes #4332 once the scope is agreed. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#5012
No description provided.