[PR #1038] [CLOSED] decode: STRATA_PCIE_BALANCE=1 picks each layer's PCIe count from measured costs (opt-in) #2986

Closed
opened 2026-11-04 02:04:41 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/1038
Author: @sergqwer
Created: 10/6/2026
Status: ❌ Closed

Base: main ← Head: pr/pcie-balance


📝 Commits (10+)

  • f4e96d5 tests: gdn_rec_head also compares the PP (variant 4) and two-column (variant 5) recurrence kernels, bitwise
  • 16bc95a prefill: STRATA_HCD_EXACT=1 - the HC down projection by a WMMA kernel with hipBLASLt solution 1176/1177 k order (StaggerU included), bitwise
  • 502fcef #606: the fused SwiGLU q8_1 quantizers keep the block's scale and sum finite too
  • 64d0136 cache: preserve checkpoints when split allocation fails
  • a0d0056 prefill: fused-expert exact wins (table16 via direct selector, float4 moe_combine, LDS alias + occupancy)
  • 5f5452b serve: park_current's try covers the checkpoint split too (#752): a host OOM skips parking
  • 8b19a38 Layer split: --vram-reserve-later-mib, a separate reserve for the later cards
  • ea83d0d Resident RAM mode with a layer split
  • d2d981f setup: the low-RAM mode's resident variant on several GPUs (#642)
  • cd62e5e serve: a split's stage-0 GPU profile line keeps its text (#848); later stages say which stage

📊 Changes

7 files changed (+212 additions, -6 deletions)

View changed files

📝 include/strata/core/expert_source.hpp (+94 -0)
📝 include/strata/core/verify.hpp (+21 -0)
📝 include/strata/kernels/verify_kernels.hpp (+4 -0)
📝 src/core/expert_source.cpp (+3 -2)
📝 src/core/verify.cpp (+46 -3)
📝 src/kernels/cuda/verify_kernels.cu (+25 -0)
📝 src/program/generate.cpp (+19 -1)

📄 Description

The verify window reads pcie_frac of a layer's missed experts over PCIe. The link probe sets that share, so the CPU's speed never enters it. On a slow CPU the GPU spins on the pool's rows while the link sits mostly idle.

This adds an opt-in, STRATA_PCIE_BALANCE=1. Off (the default), nothing changes: no new kernel is captured and the share is the probe's.

What it does

  • Stamps. wait_flag_ge_stamped is the same flag spin kernel, which also writes the GPU clock at three points: as the layer's plan arrives (flag A), as the PCIe part starts (flag B) and as the GPU starts waiting for the CPU's rows. This adds no extra launch, and the stamped kernels are captured only with the switch on.

  • Fits. The host already times its pool per step. After each window, least squares with forgetting (~200 layers) fit two lines:

    • the pool: a + c·n_cpu + d·n_pcie;
    • the GPU: g0 + g·n_pcie.

    d is there because the pool and the link read the same RAM. On a DRAM-bound pool, a PCIe copy slows the pool by about what the expert it took off the CPU saved, so moving misses buys nothing there. A plain per-expert balance got this wrong and was ~4% slower on such a box.

  • Choice. A layer reads over PCIe the m of its misses that minimizes max(GPU, CPU). Every 64th layer that would keep all its misses on one side moves one to the other, so neither fit goes stale. Without that, a cold first sample once sent everything over PCIe for good.

  • Scope. One GPU, no batch slots and no --pcie-frac. A serve request's own pcie_frac pauses the switch for that request. The decode summary prints the fitted costs.

Measured

IQ2_XS (ISTA's GSQ-RCO), RTX 5090 + Ryzen 9 9950X3D, chat prompt decoded to the end of the turn (--stop-eos), automatic cache:

off (probe 0.55) STRATA_PCIE_BALANCE=1
one pool worker on the AVX2 kernels (STRATA_FORCE_AVX2=1 --pool-workers 1 --no-host-worker) 16.77 / 17.17 ms a round, 154 / 149 tok/s 12.98 / 12.82 ms, 198 / 200 tok/s
the 9950X3D's 16 workers, 3 pairs 12.09 / 12.03 / 12.45 12.02 / 11.99 / 12.50
  • One worker. The fit reads the CPU at 42-60 us an expert and the GPU at 28 us a PCIe expert, with d 26-28 us, so 0.8 of the misses move.
  • 16 workers. The pool is DRAM-bound (d 0.5-0.6 of c) and few misses move.

Off, the logits and the 32 greedy tokens equal v0.1.39 on IQ2_XS: 2K prompt, fixed cache, identical bytes.

The slow-CPU case is emulated on this machine by fewer workers and the AVX2 kernels, not run on such a CPU. A 6-core or a Zen 2 box (the README's Ryzen 9 3900X) sits somewhere between those two rows. That is the case the fit is for: it finds the box's own split instead of the probe's. The HIP builds take the clock gpu_stamp already uses (wall_clock64), but I have no AMD card to run them on.

🤖 Generated with Claude Code

https://claude.ai/code/session_01VZy1yKaDDiA8a7svdwaHio


🔄 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/1038 **Author:** [@sergqwer](https://github.com/sergqwer) **Created:** 10/6/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/pcie-balance` --- ### 📝 Commits (10+) - [`f4e96d5`](https://github.com/Niko1221/Strata/commit/f4e96d55b6f13622bae6b3ded2f81ca16cbd78f6) tests: gdn_rec_head also compares the PP (variant 4) and two-column (variant 5) recurrence kernels, bitwise - [`16bc95a`](https://github.com/Niko1221/Strata/commit/16bc95ab3e5293a6dd557ad0ec7e2a5eef23640a) prefill: STRATA_HCD_EXACT=1 - the HC down projection by a WMMA kernel with hipBLASLt solution 1176/1177 k order (StaggerU included), bitwise - [`502fcef`](https://github.com/Niko1221/Strata/commit/502fcef6ff29325427ecfb5409b242ac7bea18e1) #606: the fused SwiGLU q8_1 quantizers keep the block's scale and sum finite too - [`64d0136`](https://github.com/Niko1221/Strata/commit/64d01362bee3aa109fb340d9b4144a62d9192522) cache: preserve checkpoints when split allocation fails - [`a0d0056`](https://github.com/Niko1221/Strata/commit/a0d00560fdb3bd728001cac756e223b12e3a09e9) prefill: fused-expert exact wins (table16 via direct selector, float4 moe_combine, LDS alias + occupancy) - [`5f5452b`](https://github.com/Niko1221/Strata/commit/5f5452bec6fabe7c76b44af2397b29daac95feb4) serve: park_current's try covers the checkpoint split too (#752): a host OOM skips parking - [`8b19a38`](https://github.com/Niko1221/Strata/commit/8b19a38a57a80ee9c2bd03d677d8b55fc961d34b) Layer split: --vram-reserve-later-mib, a separate reserve for the later cards - [`ea83d0d`](https://github.com/Niko1221/Strata/commit/ea83d0dc5ef3fd481c53ee6bd99dd8016e10ce78) Resident RAM mode with a layer split - [`d2d981f`](https://github.com/Niko1221/Strata/commit/d2d981f5b2841cfcefcc88872730785b9d23bd78) setup: the low-RAM mode's resident variant on several GPUs (#642) - [`cd62e5e`](https://github.com/Niko1221/Strata/commit/cd62e5e07f5efa6be42a8ccfbbc82b78f6abfe93) serve: a split's stage-0 GPU profile line keeps its text (#848); later stages say which stage ### 📊 Changes **7 files changed** (+212 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `include/strata/core/expert_source.hpp` (+94 -0) 📝 `include/strata/core/verify.hpp` (+21 -0) 📝 `include/strata/kernels/verify_kernels.hpp` (+4 -0) 📝 `src/core/expert_source.cpp` (+3 -2) 📝 `src/core/verify.cpp` (+46 -3) 📝 `src/kernels/cuda/verify_kernels.cu` (+25 -0) 📝 `src/program/generate.cpp` (+19 -1) </details> ### 📄 Description The verify window reads `pcie_frac` of a layer's missed experts over PCIe. The link probe sets that share, so the CPU's speed never enters it. On a slow CPU the GPU spins on the pool's rows while the link sits mostly idle. This adds an opt-in, `STRATA_PCIE_BALANCE=1`. Off (the default), nothing changes: no new kernel is captured and the share is the probe's. ### What it does - **Stamps.** `wait_flag_ge_stamped` is the same flag spin kernel, which also writes the GPU clock at three points: as the layer's plan arrives (flag A), as the PCIe part starts (flag B) and as the GPU starts waiting for the CPU's rows. This adds no extra launch, and the stamped kernels are captured only with the switch on. - **Fits.** The host already times its pool per step. After each window, least squares with forgetting (~200 layers) fit two lines: - the pool: `a + c·n_cpu + d·n_pcie`; - the GPU: `g0 + g·n_pcie`. `d` is there because the pool and the link read the same RAM. On a DRAM-bound pool, a PCIe copy slows the pool by about what the expert it took off the CPU saved, so moving misses buys nothing there. A plain per-expert balance got this wrong and was ~4% slower on such a box. - **Choice.** A layer reads over PCIe the `m` of its misses that minimizes `max(GPU, CPU)`. Every 64th layer that would keep all its misses on one side moves one to the other, so neither fit goes stale. Without that, a cold first sample once sent everything over PCIe for good. - **Scope.** One GPU, no batch slots and no `--pcie-frac`. A serve request's own `pcie_frac` pauses the switch for that request. The decode summary prints the fitted costs. ### Measured IQ2_XS (ISTA's GSQ-RCO), RTX 5090 + Ryzen 9 9950X3D, chat prompt decoded to the end of the turn (`--stop-eos`), automatic cache: | | off (probe 0.55) | `STRATA_PCIE_BALANCE=1` | |---|---|---| | one pool worker on the AVX2 kernels (`STRATA_FORCE_AVX2=1 --pool-workers 1 --no-host-worker`) | 16.77 / 17.17 ms a round, 154 / 149 tok/s | **12.98 / 12.82 ms, 198 / 200 tok/s** | | the 9950X3D's 16 workers, 3 pairs | 12.09 / 12.03 / 12.45 | 12.02 / 11.99 / 12.50 | - **One worker.** The fit reads the CPU at 42-60 us an expert and the GPU at 28 us a PCIe expert, with `d` 26-28 us, so 0.8 of the misses move. - **16 workers.** The pool is DRAM-bound (`d` 0.5-0.6 of `c`) and few misses move. Off, the logits and the 32 greedy tokens equal v0.1.39 on IQ2_XS: 2K prompt, fixed cache, identical bytes. The slow-CPU case is emulated on this machine by fewer workers and the AVX2 kernels, not run on such a CPU. A 6-core or a Zen 2 box (the README's Ryzen 9 3900X) sits somewhere between those two rows. That is the case the fit is for: it finds the box's own split instead of the probe's. The HIP builds take the clock `gpu_stamp` already uses (`wall_clock64`), but I have no AMD card to run them on. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01VZy1yKaDDiA8a7svdwaHio --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-04 02:04:41 +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#2986
No description provided.