[GH-ISSUE #13] Windows/consumer GPUs: idle-link PCIe calibration and disk re-reads of in-flight demotions halve decode speed (7.1 -> 14.6 tok/s with two small fixes) #4

Closed
opened 2026-10-29 21:19:00 +07:00 by bsakaguchi · 3 comments
Owner

Originally created by @tanutanu56 on GitHub (Oct 8, 2026).
Original GitHub issue: https://github.com/mw00/project-maya/issues/13

Machine

  • RTX 4070 Ti SUPER 16 GB (CUDA0, PCIe 3.0 x4 slot) + RTX 5070 Ti 16 GB (CUDA1, PCIe 4.0 x16)
  • Ryzen 7 3700X (8C/16T), 128 GB DDR4, Windows 11, CUDA 12.9, Maya-S-v2-IQ2_XXS, 32K context, v1.0.11

Results (--bench)

decode prefill 2k prefill 8k
v1.0.11 as shipped 7.1 138 157
+ fix 1 + fix 2, default split 9.8 140 155
+ fix 1 + fix 2, STRATA_GLM_SPLIT=17, CPU lane 6 / 2 threads 14.6 204 259

On the live server the same build gives 15.8-17.8 tok/s for 600-token answers. Before the fixes it gave 8.4.

fast_cpu_lane_setup times 12 host-to-device copies of one expert. At that moment the GPU is idle (P8), and on these cards the PCIe link sits at Gen1 in P8. Copies alone do not raise the P-state. During decode the links run at Gen3 / Gen4 (checked with nvidia-smi --query-gpu=pcie.link.gen.current,pstate).

measured at idle (shipped) measured with the GPU kept busy
CUDA0 (Gen3 x4) 10.1 ms / expert 2.6 ms
CUDA1 (Gen4 x16) 1.93 ms / expert 0.25 ms

On CUDA1 the CPU took 6 of 8 RAM-tier experts while PCIe was really 2.5x faster than the CPU (0.25 vs 0.62 ms). With the fix the plan becomes 0 0 0 0 0 1 1 1 1.

Fix: launch a small spin kernel (%globaltimer loop, ~1.5 s) on a separate stream, wait 400 ms, then time the copies (24 reps, skipping the first 8). I also added STRATA_GLM_PCIE_MS as a manual override.

2. An expert demoted at the last boundary is re-read from disk while its RAM copy is still landing

This was the main cost. In step (3) of fast_boundary, a VRAM victim's table entry is cleared, and its RAM slot is marked kRDemote with an async D2H copy. The slot only goes live in step (2) of the next boundary. If a route needs that expert during this token, the miss path in fast_service finds ram_of[key] in state kRDemote. That state is neither kRLoad nor kRNew, so the expert is read from disk again.

Once fix 1 sends more misses over PCIe, CUDA1 promotes 35-40 experts per token, so 35-40 experts are "in flight" each token. About 6 per token were re-read from disk, costing 70-80 ms of a ~140 ms token. STRATA_GLM_TIER_DIAG reports these as "never held" (left[] == 0), which hides the cause. The tiers themselves showed 0 experts in no tier.

Fix: in the miss path, wait for that drain's event and use the RAM slot:

if (rs >= 0 && R.st[(size_t) rs] == FastState::kRDemote && R.key[(size_t) rs] == key) {
    for (const auto& d : F->draining)
        if (d.rclass == cls && d.rslot == rs) { cudaEventSynchronize(d.ev); break; }
    dst[m] = R.base + (size_t) rs * R.stride;
    continue;
}

Result: disk reads per token 6.0 -> 0.00, disk wait 80 -> 0.04 ms/token, decode 140 -> 55-76 ms/token. If the route also promotes the expert, the RAM copy goes live as a duplicate, and the existing tier clean-up frees it.

The bytes are identical either way (same expert, from the RAM slot instead of disk). Outputs look correct, but I have not run a formal token-identical A/B.

3. Small knob: per-GPU CPU-lane threads

STRATA_GLM_CPU_LANE<dev> (falls back to STRATA_GLM_CPU_LANE). With one slow and one fast link, the halves want different lanes. Here, 6 threads for the x4 card and 2 for the x16 card beat the default 4 / 4. This also made STRATA_GLM_SPLIT=17 (more layers on the fast-link card) the best split.

Also tried, no gain

  • STRATA_GLM_CPU_LANE=8 for both halves (SMT): 6.8 vs 7.1 tok/s.
  • A larger RAM tier: capped by the Windows commit limit (pinned RAM and WDDM VRAM count against RAM + page file), and it did not help once fix 2 was found.
  • --kv int8 with --kv-resident 20480: hung on the second request ("illegal memory access" in the glm_fast kernels).

The full diff (~45 lines in src/core/glm_fast_path.cu) is available as a PR if useful.

Originally created by @tanutanu56 on GitHub (Oct 8, 2026). Original GitHub issue: https://github.com/mw00/project-maya/issues/13 ## Machine - RTX 4070 Ti SUPER 16 GB (CUDA0, **PCIe 3.0 x4** slot) + RTX 5070 Ti 16 GB (CUDA1, PCIe 4.0 x16) - Ryzen 7 3700X (8C/16T), 128 GB DDR4, Windows 11, CUDA 12.9, Maya-S-v2-IQ2_XXS, 32K context, v1.0.11 ## Results (`--bench`) | | decode | prefill 2k | prefill 8k | |---|---:|---:|---:| | v1.0.11 as shipped | 7.1 | 138 | 157 | | + fix 1 + fix 2, default split | 9.8 | 140 | 155 | | + fix 1 + fix 2, `STRATA_GLM_SPLIT=17`, CPU lane 6 / 2 threads | **14.6** | **204** | **259** | On the live server the same build gives 15.8-17.8 tok/s for 600-token answers. Before the fixes it gave 8.4. ## 1. The CPU-lane calibration times PCIe on an idle link `fast_cpu_lane_setup` times 12 host-to-device copies of one expert. At that moment the GPU is idle (P8), and on these cards the PCIe link sits at **Gen1** in P8. Copies alone do not raise the P-state. During decode the links run at Gen3 / Gen4 (checked with `nvidia-smi --query-gpu=pcie.link.gen.current,pstate`). | | measured at idle (shipped) | measured with the GPU kept busy | |---|---:|---:| | CUDA0 (Gen3 x4) | 10.1 ms / expert | 2.6 ms | | CUDA1 (Gen4 x16) | 1.93 ms / expert | 0.25 ms | On CUDA1 the CPU took 6 of 8 RAM-tier experts while PCIe was really 2.5x faster than the CPU (0.25 vs 0.62 ms). With the fix the plan becomes `0 0 0 0 0 1 1 1 1`. Fix: launch a small spin kernel (`%globaltimer` loop, ~1.5 s) on a separate stream, wait 400 ms, then time the copies (24 reps, skipping the first 8). I also added `STRATA_GLM_PCIE_MS` as a manual override. ## 2. An expert demoted at the last boundary is re-read from disk while its RAM copy is still landing This was the main cost. In step (3) of `fast_boundary`, a VRAM victim's table entry is cleared, and its RAM slot is marked `kRDemote` with an async D2H copy. The slot only goes live in step (2) of the **next** boundary. If a route needs that expert during this token, the `miss` path in `fast_service` finds `ram_of[key]` in state `kRDemote`. That state is neither `kRLoad` nor `kRNew`, so the expert is read from disk again. Once fix 1 sends more misses over PCIe, CUDA1 promotes 35-40 experts per token, so 35-40 experts are "in flight" each token. About 6 per token were re-read from disk, costing 70-80 ms of a ~140 ms token. `STRATA_GLM_TIER_DIAG` reports these as "never held" (`left[] == 0`), which hides the cause. The tiers themselves showed 0 experts in no tier. Fix: in the miss path, wait for that drain's event and use the RAM slot: ```cpp if (rs >= 0 && R.st[(size_t) rs] == FastState::kRDemote && R.key[(size_t) rs] == key) { for (const auto& d : F->draining) if (d.rclass == cls && d.rslot == rs) { cudaEventSynchronize(d.ev); break; } dst[m] = R.base + (size_t) rs * R.stride; continue; } ``` Result: disk reads per token 6.0 -> **0.00**, disk wait 80 -> 0.04 ms/token, decode 140 -> 55-76 ms/token. If the route also promotes the expert, the RAM copy goes live as a duplicate, and the existing tier clean-up frees it. The bytes are identical either way (same expert, from the RAM slot instead of disk). Outputs look correct, but I have not run a formal token-identical A/B. ## 3. Small knob: per-GPU CPU-lane threads `STRATA_GLM_CPU_LANE<dev>` (falls back to `STRATA_GLM_CPU_LANE`). With one slow and one fast link, the halves want different lanes. Here, 6 threads for the x4 card and 2 for the x16 card beat the default 4 / 4. This also made `STRATA_GLM_SPLIT=17` (more layers on the fast-link card) the best split. ## Also tried, no gain - `STRATA_GLM_CPU_LANE=8` for both halves (SMT): 6.8 vs 7.1 tok/s. - A larger RAM tier: capped by the Windows commit limit (pinned RAM and WDDM VRAM count against RAM + page file), and it did not help once fix 2 was found. - `--kv int8` with `--kv-resident 20480`: hung on the second request ("illegal memory access" in the glm_fast kernels). The full diff (~45 lines in `src/core/glm_fast_path.cu`) is available as a PR if useful.
Author
Owner

@mw00 commented on GitHub (Oct 8, 2026):

Thank you, this is a great report: clear numbers, the cause, and the fix for each.

Both findings check out in the code:

  • Demotions in flight: fast_service's miss path only takes a RAM slot in kRLoad or kRNew. A slot still in kRDemote falls through to the disk read, as you describe. Waiting on that drain's event and serving from the slot is the right fix.
  • Idle-link calibration: fast_cpu_lane_setup times the copies while the GPU is idle. Our test machines are Tesla V100s, which don't drop the link at idle, so we never saw it. Consumer cards at P8 do.

Yes please, open the PR. A few notes so it lands smoothly:

  • Please rebase on main (v1.0.13). v1.0.12 merged #12, which changed the CPU lane:
    • each thread's share is now cut into pieces (STRATA_GLM_CPU_SPLIT);
    • ./maya.sh --calibrate measures real decode speed with a few PCIe/CPU splits.
      Your warm-up fixes the start-up guess, which --calibrate starts from.
  • The per-GPU STRATA_GLM_CPU_LANE<dev> knob is welcome in the same PR. Please add a line for it in the README's Tuning table.
  • We'll run it on 1x and 2x Tesla V100 (Linux) before merging: decode / prefill A/B and our parity tests. If you can, a token-identical check on your machine with greedy decoding would help too (--bench output before and after, same prompt).

Separately: the --kv int8 + --kv-resident 20480 hang ("illegal memory access" in the glm_fast kernels on the second request) sounds like a real bug of its own. Could you open a separate issue with the command and the end of the engine log?

<!-- gh-comment-id:6064354679 --> @mw00 commented on GitHub (Oct 8, 2026): Thank you, this is a great report: clear numbers, the cause, and the fix for each. Both findings check out in the code: - **Demotions in flight:** `fast_service`'s miss path only takes a RAM slot in `kRLoad` or `kRNew`. A slot still in `kRDemote` falls through to the disk read, as you describe. Waiting on that drain's event and serving from the slot is the right fix. - **Idle-link calibration:** `fast_cpu_lane_setup` times the copies while the GPU is idle. Our test machines are Tesla V100s, which don't drop the link at idle, so we never saw it. Consumer cards at P8 do. Yes please, open the PR. A few notes so it lands smoothly: - Please rebase on `main` (v1.0.13). v1.0.12 merged #12, which changed the CPU lane: - each thread's share is now cut into pieces (`STRATA_GLM_CPU_SPLIT`); - `./maya.sh --calibrate` measures real decode speed with a few PCIe/CPU splits. Your warm-up fixes the start-up guess, which `--calibrate` starts from. - The per-GPU `STRATA_GLM_CPU_LANE<dev>` knob is welcome in the same PR. Please add a line for it in the README's Tuning table. - We'll run it on 1x and 2x Tesla V100 (Linux) before merging: decode / prefill A/B and our parity tests. If you can, a token-identical check on your machine with greedy decoding would help too (`--bench` output before and after, same prompt). Separately: the `--kv int8` + `--kv-resident 20480` hang ("illegal memory access" in the glm_fast kernels on the second request) sounds like a real bug of its own. Could you open a separate issue with the command and the end of the engine log?
Author
Owner

@tanutanu56 commented on GitHub (Oct 8, 2026):

Thanks for the quick look, and for the notes. The PR is up: #24, rebased on v1.0.14 (main moved after your comment). Its description has the official --bench numbers and an honest note on the greedy-parity check.

On the --kv int8 --kv-resident 20480 hang: I tried to reproduce it for a separate issue and could not. On v1.0.14 (unpatched) with those two flags, I sent 9 requests in a row, a short one, a 3-turn Japanese chat that continues the earlier answer, a 2.5k-token prompt, a short one after it, and a new branch of an old chat. None hung (7.8-10.8 tok/s as usual).

What I saw before was on v1.0.11: the first request (13-token prompt, 128 tokens) finished at 10.5 tok/s, then the second (48 of 49 prompt tokens) stayed at "thinking: 1 token" for 4+ minutes with the GPUs at 0% and the CPU at 300%, until I killed it. My engine log from that period has a long run of "glm_fast ...: an illegal memory access was encountered" lines, but it mixes several starts, so I can't say which run they belong to. Since I can't reproduce it now, I'm not opening a separate issue for it. If it comes back on a current build I will, with the command and a clean log.

<!-- gh-comment-id:6067138291 --> @tanutanu56 commented on GitHub (Oct 8, 2026): Thanks for the quick look, and for the notes. The PR is up: #24, rebased on v1.0.14 (main moved after your comment). Its description has the official --bench numbers and an honest note on the greedy-parity check. On the `--kv int8 --kv-resident 20480` hang: I tried to reproduce it for a separate issue and could not. On v1.0.14 (unpatched) with those two flags, I sent 9 requests in a row, a short one, a 3-turn Japanese chat that continues the earlier answer, a 2.5k-token prompt, a short one after it, and a new branch of an old chat. None hung (7.8-10.8 tok/s as usual). What I saw before was on v1.0.11: the first request (13-token prompt, 128 tokens) finished at 10.5 tok/s, then the second (48 of 49 prompt tokens) stayed at "thinking: 1 token" for 4+ minutes with the GPUs at 0% and the CPU at 300%, until I killed it. My engine log from that period has a long run of "glm_fast ...: an illegal memory access was encountered" lines, but it mixes several starts, so I can't say which run they belong to. Since I can't reproduce it now, I'm not opening a separate issue for it. If it comes back on a current build I will, with the command and a clean log.
Author
Owner

@mw00 commented on GitHub (Oct 8, 2026):

Both fixes from this report ship in v1.0.15, through your #24:

  • the CPU / PCIe split is timed with the GPU awake (on AMD too);
  • in-flight demotions are served from RAM instead of the SSD;
  • STRATA_GLM_CPU_LANE<n> sets per-GPU lane threads.

On 2x Tesla V100: decode 28.4 / 28.9 -> 29.8 / 29.7 tok/s, SSD reads per token 3.0 -> 2.2. Your 4070 Ti SUPER + 5070 Ti numbers are in the release notes. Closing this one. Thank you for the very precise report!

<!-- gh-comment-id:6069346407 --> @mw00 commented on GitHub (Oct 8, 2026): Both fixes from this report ship in [v1.0.15](https://github.com/mw00/project-maya/releases/tag/v1.0.15), through your #24: - the CPU / PCIe split is timed with the GPU awake (on AMD too); - in-flight demotions are served from RAM instead of the SSD; - `STRATA_GLM_CPU_LANE<n>` sets per-GPU lane threads. On 2x Tesla V100: decode 28.4 / 28.9 -> 29.8 / 29.7 tok/s, SSD reads per token 3.0 -> 2.2. Your 4070 Ti SUPER + 5070 Ti numbers are in the release notes. Closing this one. Thank you for the very precise report!
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#4
No description provided.