[PR #1438] [CLOSED] perf(peer): add opt-in byte-capacity-aware expert placement #3454

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

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/1438
Author: @agorevski
Created: 10/7/2026
Status: ❌ Closed

Base: main ← Head: perf/capacity-aware-peer-placement


📝 Commits (4)

  • 0645ca3 Add opt-in capacity-aware peer expert placement
  • 88a738e Preserve capacity-plan holdbacks and report actual residency
  • 1f7b830 Keep retry sizing independent of retained peer ownership
  • b19c396 Separate writeback reserve initialization from peer override

📊 Changes

7 files changed (+479 additions, -16 deletions)

View changed files

📝 CMakeLists.txt (+4 -0)
📝 docs/SECOND_GPU.md (+46 -1)
📝 include/strata/core/peer_experts.hpp (+8 -0)
➕ include/strata/core/peer_placement.hpp (+117 -0)
📝 src/core/peer_experts.cpp (+37 -5)
📝 src/program/generate.cpp (+118 -10)
➕ tests/core/peer_placement_test.cpp (+149 -0)

📄 Description

Title

Capacity-aware peer expert placement (opt-in)

Issue: Related to #1304 (multi-GPU prompt performance), #2052 (asymmetric-GPU recommendations), #765 (VRAM budgeting), and #831 (profile-limited residency). This PR does not claim to resolve those broader reports.

Summary

Add byte-capacity-aware primary/peer expert placement behind the exact opt-in
STRATA_PEER_CAPACITY_AWARE=1 and explicit --peer-device N. Rebased onto
origin/main at a0116b2782a5b82622358c04a06496485d12b2d6.
Current local HEAD: b19c396f84641fe3ee7d30c4e8aa1f234ee2667d.

A large primary cache can swallow the experts moved behind the legacy
8,700-rank boundary. Unequal GPUs need independent aligned-byte budgets.
Reciprocal square-root profile rank is a heat proxy, not measured routing
frequency. No default placement or CPU-pool mode is changed.

What changed

  • CPU-only planning covers aligned heterogeneous blobs, independent byte
    capacities, peer slot limits, unique ownership, unprofiled tails and bounded
    relocation.
  • Peer scratch is allocated before pricing. Peer fill excludes actual primary
    residents, skips oversize pairs, deduplicates candidates and backfills dropped
    primary pairs where peer room remains.
  • Primary allocation correction now retains the complete holdback originally
    priced: reserve, owned prefill, still-unbound draft buffers and pipeline.
    Previously the post-write check tested only reserve plus pipeline, a real
    budget-consistency defect. owned_prefill_mib remains upstream's existing
    composable calculation; no BF16 persistent-cache symbols or APIs are added.
    Baseline writeback reserve initialization and the peer's complete-holdback
    override are separate, so independent reserve changes can compose without
    adding an already-priced owned cost twice.
  • Aligned retry trimming uses a CPU-testable sized-slot prefix calculation,
    without retaining a second ownership plan through allocation. Final
    primary/peer/missed counts come from actual residency after
    peer backfill, not allocated slot counts or the original plan. Pricing and
    live-free correction diagnostics make the reason for a trim visible.
  • Focused CPU regressions cover the 10,230/13,586/760 plan trimmed to
    9,614/13,586/1,376, exact prefix alignment, repeated/zero trims, heterogeneous
    slots, full holdback arithmetic and zero-free fallback.
  • Retain upstream engine additions and all existing pool modes. Opt-in still
    requires a native pack, a profile, and a shared non-elastic cache with the
    CPU pool; legacy HOT settings are ignored only when enabled.

Extra Notes

Contributor evidence, not new measurements

ruibeikaa's full Windows hardware report
tested pristine 0.1.40.3 plus the original PR, greedy 256-token requests, three
interleaved placement arms over six starts:

  • PH402 with two GP100 dies, experimental sm_60, CUDA 12.9/TCC, 32 GB HBM2 per
    die and NVLink: +6.5% decode (77.0 to 72.4 ms/window), +17.5% prompt
    (233 to 274 tok/s), equal outputs across all arms.
  • Two RTX 3090 Ti 24 GB, sm_86/CUDA 12.9, no P2P: neutral within noise.
    Planned 10,230/13,586/760 became actual 9,614/13,586/1,376.
  • Mixed-size cards were not covered.

Capacity-loss investigation and limitation

The original and rebased paths subtract the primary budget once.
open_sized sums aligned slot bytes; ExpertCache::open does not subtract a
second reserve. The legacy repricing path is excluded by !peer_capacity.
Primary loss can occur only in allocation-failure retries or the post-write
live-free correction before filling. Its zero/near-zero-free fallback gives
back at least 1 GiB on the first two corrections, consistent with the report's
approximately 1 GiB loss, but the contributor comment does not include those
intervening log lines. A WDDM/live-free cause is therefore plausible, not
proved. The complete-holdback bug above would under-reserve, not establish
that the 616 pairs were unnecessarily lost.

Holdback timing was checked against upstream initialization: MTP weights,
private K/V, native head and main logits are already allocated before pricing;
MtpDrafter::bind_bytes counts only its still-null bind-time buffers.
Between capacity-aware pricing and the primary writeback check there are no
draft binds, owned-prefill initializations, or pipeline allocations, only the
expert-cache allocation/retry path. Serve initializes sp and binds the
solo/batch drafters later; plain generate likewise initializes prefill and
binds the drafter later. Thus these costs are genuinely still pending at
writeback. Pipeline windows are disabled when --peer-device is active, so
their composed cost is zero in this mode.

This update does not claim to recover those 616 pairs or prove the root
cause of the contributor's Windows capacity loss.
Runtime allocation/free
logs from that pair are still needed. A real capacity correction must not be
disabled just to match the optimistic initial plan.

The proposed reply requests the same run's pricing, allocation-retry,
post-write correction, actual residency, and final WDDM free-memory lines.
This bounded code investigation and comment response are complete; the
missing Windows evidence is a stated measurement limitation, not a promise
of further code changes or recovered capacity.

Verified directly with gh issue view N --json number,title,state,url,body:

  • #1304, OPEN, Prefill/Reading the prompt with multi-gpu cards is slow:
    two RTX 2080 Ti 22 GB/NVLink, Flash-Next IQ3_S below 400 prompt tok/s.
    Relevant performance context, not proof this placement solves that run.
  • #2052, OPEN, Default multi-GPU recommendation not ideal for asymmetrical
    GPUs
    : RTX 4080 16 GB plus RTX 3060 12 GB performs worse than the 4080
    alone, even after trying expert-cache-only use. Relevant heterogeneous
    context; no setup recommendation change or mixed-size validation here.
  • #765, OPEN, Make VRAM budgeting aware of KV, prefill staging and expert
    residency
    : asks for coherent mandatory-allocation pricing before expert
    cache sizing at large context. The holdback correction is related, not a
    unified-budget or auto-prefill solution.
  • #831, CLOSED, The profile's length caps the expert arena — even an explicit
    --expert-cache N
    : documents partial-profile underfill and slot capacity
    versus true residency. The opt-in cold tail and actual residency log are
    relevant; this is already closed and the general legacy/per-layer policies
    are not changed by this PR.

Validation

Working directory for every command:

/home/algore/.copilot/session-state/a7c2bcbb-4264-4eb2-879d-c71a90285b0b/files/pr-worktrees/peer-capacity
export TMPDIR="$PWD/build-peer-capacity-gcc13"
cmake -S . -B build-peer-capacity-gcc13 -DCMAKE_C_COMPILER=/usr/bin/gcc-13 -DCMAKE_CXX_COMPILER=/usr/bin/g++-13 -DCMAKE_C_FLAGS= -DCMAKE_CXX_FLAGS= -DSTRATA_ENABLE_CUDA=OFF -DSTRATA_ENABLE_HIP=OFF -DSTRATA_BUILD_TESTS=ON
cmake --build build-peer-capacity-gcc13 --target peer_placement_test -j2
ctest --test-dir build-peer-capacity-gcc13 -R '^peer_placement_test$' --output-on-failure

All passed, GCC 13.3.0; CTest passed 1/1 selected test.

/usr/bin/g++-13 -std=c++20 -O3 -DNDEBUG -Wall -Wextra -DSTRATA_NATIVE_EXPERTS=1 -DSTRATA_PREFILL_FUSED=1 -DSTRATA_PREFILL_MMQ=1 '-DSTRATA_VERSION="0.1.43"' -Iinclude -Ithird_party/llama.cpp/ggml/include -isystem /home/algore/miniconda3/include -fsyntax-only src/program/generate.cpp src/core/peer_experts.cpp
/usr/bin/g++-13 -std=c++20 -O3 -DNDEBUG -Wall -Wextra -DSTRATA_NATIVE_EXPERTS=1 -DSTRATA_PREFILL_FUSED=1 -DSTRATA_PREFILL_MMQ=1 '-DSTRATA_VERSION="0.1.43"' -Iinclude -Ithird_party/llama.cpp/ggml/include -isystem /home/algore/miniconda3/include -c src/program/generate.cpp -o build-peer-capacity-host/generate-host.o
/usr/bin/g++-13 -std=c++20 -O3 -DNDEBUG -Wall -Wextra -DSTRATA_NATIVE_EXPERTS=1 '-DSTRATA_VERSION="0.1.43"' -Iinclude -Ithird_party/llama.cpp/ggml/include -isystem /home/algore/miniconda3/include -c src/core/peer_experts.cpp -o build-peer-capacity-host/peer-experts-host.o
git diff --check

All passed. Generate emits the existing unused-variable w warning.
Host checks use CUDA headers but do not link or execute the CUDA runtime.
A full GPU engine build was not run.

No model servers, GPU workloads, or two-GPU runtime tests were run. GPU use
is restricted to physical GPU 3; the pair remains untested. Windows runtime,
mixed-size hardware, actual GPU allocation/backfill, throughput and answer
parity of this rebased update are unverified. Windows/performance/answer
evidence above is contributor-only and applies to the original PR.

Original 1762e1f1 is preserved on
backup/pr1438-1762e1f1-20261012. The original dirty checkout and installed engine were preserved.


🔄 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/1438 **Author:** [@agorevski](https://github.com/agorevski) **Created:** 10/7/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `perf/capacity-aware-peer-placement` --- ### 📝 Commits (4) - [`0645ca3`](https://github.com/Niko1221/Strata/commit/0645ca3e3e0229c4c7c041fcb61d08c04e3f751a) Add opt-in capacity-aware peer expert placement - [`88a738e`](https://github.com/Niko1221/Strata/commit/88a738e5106f26e043410fd632b0dd973da1027e) Preserve capacity-plan holdbacks and report actual residency - [`1f7b830`](https://github.com/Niko1221/Strata/commit/1f7b8304a409b0de656e2da85cd90de72645641a) Keep retry sizing independent of retained peer ownership - [`b19c396`](https://github.com/Niko1221/Strata/commit/b19c396f84641fe3ee7d30c4e8aa1f234ee2667d) Separate writeback reserve initialization from peer override ### 📊 Changes **7 files changed** (+479 additions, -16 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+4 -0) 📝 `docs/SECOND_GPU.md` (+46 -1) 📝 `include/strata/core/peer_experts.hpp` (+8 -0) ➕ `include/strata/core/peer_placement.hpp` (+117 -0) 📝 `src/core/peer_experts.cpp` (+37 -5) 📝 `src/program/generate.cpp` (+118 -10) ➕ `tests/core/peer_placement_test.cpp` (+149 -0) </details> ### 📄 Description ## Title <!-- If Applicable, reference the GitHub issue --> Capacity-aware peer expert placement (opt-in) Issue: Related to #1304 (multi-GPU prompt performance), #2052 (asymmetric-GPU recommendations), #765 (VRAM budgeting), and #831 (profile-limited residency). This PR does not claim to resolve those broader reports. ## Summary <!-- Quick Summary of changes --> Add byte-capacity-aware primary/peer expert placement behind the exact opt-in `STRATA_PEER_CAPACITY_AWARE=1` and explicit `--peer-device N`. Rebased onto `origin/main` at `a0116b2782a5b82622358c04a06496485d12b2d6`. Current local HEAD: `b19c396f84641fe3ee7d30c4e8aa1f234ee2667d`. A large primary cache can swallow the experts moved behind the legacy 8,700-rank boundary. Unequal GPUs need independent aligned-byte budgets. Reciprocal square-root profile rank is a heat proxy, not measured routing frequency. No default placement or CPU-pool mode is changed. ## What changed <!-- Specifics on files changed, and what changes were made there --> - CPU-only planning covers aligned heterogeneous blobs, independent byte capacities, peer slot limits, unique ownership, unprofiled tails and bounded relocation. - Peer scratch is allocated before pricing. Peer fill excludes actual primary residents, skips oversize pairs, deduplicates candidates and backfills dropped primary pairs where peer room remains. - Primary allocation correction now retains the complete holdback originally priced: reserve, owned prefill, still-unbound draft buffers and pipeline. Previously the post-write check tested only reserve plus pipeline, a real budget-consistency defect. `owned_prefill_mib` remains upstream's existing composable calculation; no BF16 persistent-cache symbols or APIs are added. Baseline writeback reserve initialization and the peer's complete-holdback override are separate, so independent reserve changes can compose without adding an already-priced owned cost twice. - Aligned retry trimming uses a CPU-testable sized-slot prefix calculation, without retaining a second ownership plan through allocation. Final primary/peer/missed counts come from actual residency after peer backfill, not allocated slot counts or the original plan. Pricing and live-free correction diagnostics make the reason for a trim visible. - Focused CPU regressions cover the 10,230/13,586/760 plan trimmed to 9,614/13,586/1,376, exact prefix alignment, repeated/zero trims, heterogeneous slots, full holdback arithmetic and zero-free fallback. - Retain upstream engine additions and all existing pool modes. Opt-in still requires a native pack, a profile, and a shared non-elastic cache with the CPU pool; legacy HOT settings are ignored only when enabled. ## Extra Notes <!-- Any extra notes, delete if there are none --> ### Contributor evidence, not new measurements [ruibeikaa's full Windows hardware report](https://github.com/Niko1221/Strata/pull/1438#issuecomment-6055005922) tested pristine 0.1.40.3 plus the original PR, greedy 256-token requests, three interleaved placement arms over six starts: - PH402 with two GP100 dies, experimental sm_60, CUDA 12.9/TCC, 32 GB HBM2 per die and NVLink: +6.5% decode (77.0 to 72.4 ms/window), +17.5% prompt (233 to 274 tok/s), equal outputs across all arms. - Two RTX 3090 Ti 24 GB, sm_86/CUDA 12.9, no P2P: neutral within noise. Planned 10,230/13,586/760 became actual 9,614/13,586/1,376. - Mixed-size cards were not covered. ### Capacity-loss investigation and limitation The original and rebased paths subtract the primary budget once. `open_sized` sums aligned slot bytes; `ExpertCache::open` does not subtract a second reserve. The legacy repricing path is excluded by `!peer_capacity`. Primary loss can occur only in allocation-failure retries or the post-write live-free correction before filling. Its zero/near-zero-free fallback gives back at least 1 GiB on the first two corrections, consistent with the report's approximately 1 GiB loss, but the contributor comment does not include those intervening log lines. A WDDM/live-free cause is therefore plausible, not proved. The complete-holdback bug above would under-reserve, not establish that the 616 pairs were unnecessarily lost. Holdback timing was checked against upstream initialization: MTP weights, private K/V, native head and main logits are already allocated before pricing; `MtpDrafter::bind_bytes` counts only its still-null bind-time buffers. Between capacity-aware pricing and the primary writeback check there are no draft binds, owned-prefill initializations, or pipeline allocations, only the expert-cache allocation/retry path. Serve initializes `sp` and binds the solo/batch drafters later; plain generate likewise initializes `prefill` and binds the drafter later. Thus these costs are genuinely still pending at writeback. Pipeline windows are disabled when `--peer-device` is active, so their composed cost is zero in this mode. **This update does not claim to recover those 616 pairs or prove the root cause of the contributor's Windows capacity loss.** Runtime allocation/free logs from that pair are still needed. A real capacity correction must not be disabled just to match the optimistic initial plan. The proposed reply requests the same run's pricing, allocation-retry, post-write correction, actual residency, and final WDDM free-memory lines. This bounded code investigation and comment response are complete; the missing Windows evidence is a stated measurement limitation, not a promise of further code changes or recovered capacity. ### Related-issue verification Verified directly with `gh issue view N --json number,title,state,url,body`: - #1304, OPEN, **Prefill/Reading the prompt with multi-gpu cards is slow**: two RTX 2080 Ti 22 GB/NVLink, Flash-Next IQ3_S below 400 prompt tok/s. Relevant performance context, not proof this placement solves that run. - #2052, OPEN, **Default multi-GPU recommendation not ideal for asymmetrical GPUs**: RTX 4080 16 GB plus RTX 3060 12 GB performs worse than the 4080 alone, even after trying expert-cache-only use. Relevant heterogeneous context; no setup recommendation change or mixed-size validation here. - #765, OPEN, **Make VRAM budgeting aware of KV, prefill staging and expert residency**: asks for coherent mandatory-allocation pricing before expert cache sizing at large context. The holdback correction is related, not a unified-budget or auto-prefill solution. - #831, CLOSED, **The profile's length caps the expert arena — even an explicit --expert-cache N**: documents partial-profile underfill and slot capacity versus true residency. The opt-in cold tail and actual residency log are relevant; this is already closed and the general legacy/per-layer policies are not changed by this PR. ### Validation Working directory for every command: ```text /home/algore/.copilot/session-state/a7c2bcbb-4264-4eb2-879d-c71a90285b0b/files/pr-worktrees/peer-capacity ``` ```bash export TMPDIR="$PWD/build-peer-capacity-gcc13" cmake -S . -B build-peer-capacity-gcc13 -DCMAKE_C_COMPILER=/usr/bin/gcc-13 -DCMAKE_CXX_COMPILER=/usr/bin/g++-13 -DCMAKE_C_FLAGS= -DCMAKE_CXX_FLAGS= -DSTRATA_ENABLE_CUDA=OFF -DSTRATA_ENABLE_HIP=OFF -DSTRATA_BUILD_TESTS=ON cmake --build build-peer-capacity-gcc13 --target peer_placement_test -j2 ctest --test-dir build-peer-capacity-gcc13 -R '^peer_placement_test$' --output-on-failure ``` All passed, GCC 13.3.0; CTest passed 1/1 selected test. ```bash /usr/bin/g++-13 -std=c++20 -O3 -DNDEBUG -Wall -Wextra -DSTRATA_NATIVE_EXPERTS=1 -DSTRATA_PREFILL_FUSED=1 -DSTRATA_PREFILL_MMQ=1 '-DSTRATA_VERSION="0.1.43"' -Iinclude -Ithird_party/llama.cpp/ggml/include -isystem /home/algore/miniconda3/include -fsyntax-only src/program/generate.cpp src/core/peer_experts.cpp /usr/bin/g++-13 -std=c++20 -O3 -DNDEBUG -Wall -Wextra -DSTRATA_NATIVE_EXPERTS=1 -DSTRATA_PREFILL_FUSED=1 -DSTRATA_PREFILL_MMQ=1 '-DSTRATA_VERSION="0.1.43"' -Iinclude -Ithird_party/llama.cpp/ggml/include -isystem /home/algore/miniconda3/include -c src/program/generate.cpp -o build-peer-capacity-host/generate-host.o /usr/bin/g++-13 -std=c++20 -O3 -DNDEBUG -Wall -Wextra -DSTRATA_NATIVE_EXPERTS=1 '-DSTRATA_VERSION="0.1.43"' -Iinclude -Ithird_party/llama.cpp/ggml/include -isystem /home/algore/miniconda3/include -c src/core/peer_experts.cpp -o build-peer-capacity-host/peer-experts-host.o git diff --check ``` All passed. Generate emits the existing unused-variable `w` warning. Host checks use CUDA headers but do not link or execute the CUDA runtime. A full GPU engine build was not run. No model servers, GPU workloads, or two-GPU runtime tests were run. GPU use is restricted to physical GPU 3; the pair remains untested. Windows runtime, mixed-size hardware, actual GPU allocation/backfill, throughput and answer parity of this rebased update are unverified. Windows/performance/answer evidence above is contributor-only and applies to the original PR. Original `1762e1f1` is preserved on `backup/pr1438-1762e1f1-20261012`. The original dirty checkout and installed engine were preserved. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 14:41:36 +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#3454
No description provided.