[PR #2964] [CLOSED] [Engine] decode: STRATA_ADAPT_FETCH=1|2 (opt-in) - the PCIe share's most-routed misses are admitted into the VRAM tier (-5.6% a round on the NVFP4 pack) #4366

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

📋 Pull Request Information

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

Base: main ← Head: pr/adapt-fetch


📝 Commits (1)

  • f8184f2 decode: STRATA_ADAPT_FETCH=1|2 - the PCIe share's blobs are admitted into the VRAM tier (opt-in)

📊 Changes

9 files changed (+256 additions, -35 deletions)

View changed files

📝 docs/DETAILS.md (+1 -0)
📝 include/strata/core/expert_source.hpp (+23 -1)
📝 include/strata/core/verify.hpp (+3 -1)
📝 include/strata/kernels/verify_kernels.hpp (+7 -0)
📝 metal/src/engine/stubs.cpp (+2 -2)
📝 src/core/expert_source.cpp (+77 -6)
📝 src/core/verify.cpp (+8 -3)
📝 src/kernels/cuda/verify_kernels.cu (+24 -8)
📝 src/program/generate.cpp (+111 -14)

📄 Description

Problem and result

Decode reads expert blobs from host RAM three ways: the CPU pool, the PCIe share (--pcie-frac of a layer's misses, staged into VRAM by fetch_blobs), and the adaptive tier's swaps. The PCIe share's blobs cross into VRAM anyway, and today they are dropped after the window. This opt-in lets the most useful of them stay there.

  • Unset: nothing changes (identity below).
  • STRATA_ADAPT_FETCH=2 on the NVFP4 pack with a ~29% cache and --pcie-frac 0.25: 14.31 -> 13.51 ms a decode round (-5.6%), 169.8 -> 179.5 tok/s; every pair faster.

None beyond this PR. It was #2964 before the 0.2.0-beta tracker reset. It is opt-in and changes no default. Since the reset it has one change besides the rebase: the SYCL and Metal builds are kept linking (see Approach, last bullet).

Approach

Opt-in, STRATA_ADAPT_FETCH=1|2; unset changes nothing.

  • The share takes the layer's most-routed misses, by the tier's decayed counts (today: the last ones in routing order). Tail-skipped and unpinned blobs are not picked.
  • A fetched expert can be admitted: when it is routed at least STRATA_ADAPT_FETCH_MIN (1) and STRATA_ADAPT_FETCH_MARGIN (0.5) more than the layer's least-routed resident expert that the window does not route, fetch_blobs copies it straight into that expert's slot (a new optional dst2 target per blob) instead of staging it, and it becomes resident: a swap with no RAM read of its own.
  • =2 leaves the tier's own swaps out of a layer where an admission ran since the tier's last round; the tier keeps the layers the share did not reach. =1 runs beside them.
  • The admissions write host_res during a window; the device table follows through #1517's pre-launch patch (3f2db5e2), whether the tier waits or not.
  • The router lookahead copies the residency rows it reads when the layer is submitted, because the table now changes while the lookahead runs (on main that is the multi-layer lookahead with 0.2.0's confidence scores, kept as they are).
  • Experts the tier is copying in are left alone.
  • Off, with a log line saying why: --batch, --pipeline-windows, --adapt-async, a layer split, peer or helper GPUs, the resident RAM mode, STRATA_ADAPT_OVERLAP=1, the foresight swap space, --pcie-mode dma|direct, or no PCIe share.
  • STRATA_ADAPT_FETCH_VERIFY=1 (strata generate) reads every admitted slot back and compares it with the experts' bytes.
  • The verify plan block grows by 16 u64 (dst2), zero unless the opt-in writes them.
  • fetch_blobs / rebase_ptrs get overloads with dst2; the old signatures stay, because the SYCL copy takes include/strata/kernels/verify_kernels.hpp from the root and defines and calls those. The Metal stubs (metal/src/engine/stubs.cpp) follow the new overloads, written by hand in gen_stubs.py's form. (The first version of this PR gave dst2 a default argument instead; a g++ stand-in for the SYCL link showed that breaks it: undefined reference to fetch_blobs(..., unsigned long long const*).)
  • docs/DETAILS.md: one bullet next to #1517's.

Validation

Revision: this branch, one commit f8184f25 on main e88ee39d (v0.2.0-beta + 12 commits). RTX 5090, Ryzen 9 9950X3D, 128 GB, Windows 11; MSVC 2022 17.14, CUDA 13.3, release configure (-DSTRATA_PORTABLE=ON, 75-real;86-real;89-real;120-real, ggml at the pinned 3cf03257). Model: the NVFP4 GPTQ pack (Maximilian228/Qwen3.8-Flash-Next-NVFP4-GPTQ-Strata, upstream setup's --family nvfp4 --model NVFP4 files).

Passed:

  • Unset = main. strata --serve with setup's model files plus --expert-cache 3000 --prefill auto --spec 6 --spec-min-p 0.7 --max-context 262144 --kv int8 --gpu 0 --pcie-frac 0 --adapt-every 1000000, env STRATA_PREFILL_CPU_SHARE=0 STRATA_PCIE_BALANCE=0 STRATA_IQ_MT_MIN=1 STRATA_DUMP_FIRST_LOGITS=<file>; a 2,100-token and a 32,037-token prompt, 32 greedy tokens each: first-token logits and tokens byte-identical to a build of main e88ee39d (2K 1e9c612c, 32K f5b2872c).

  • Checks with it on. strata generate with setup's model files plus --expert-cache auto --vram-reserve-mib 1500 --pcie-frac 0.25 --prefill auto --spec 6 --spec-min-p 0.7 --kv int8 --max-context 262144 --stats, 600 tokens after a 45-token prompt, STRATA_ADAPT_FETCH=2 STRATA_ADAPT_FETCH_VERIFY=1 STRATA_ADAPT_CHECKRES=1: 6,511 admissions (23.2 a round); the read-back covered 6,189 of them and 0 differed. The residency check covered 281 windows: 0 with mismatches, 0 layer-windows with CPU experts and no activation published. The tier itself still swapped 1,357 experts in the layers the share did not reach.

  • A/B. The same build in both arms, strata --serve with setup's model files plus --expert-cache auto --vram-reserve-mib 1500 --pcie-frac 0.25 --prefill auto --spec 6 --spec-min-p 0.7 --kv int8 --max-context 262144; the adaptive tier on, as by default. 4 interleaved pairs (off f2 f2 off off f2 f2 off); each start: 4 decodes of up to 600 tokens after a 45-token prompt. "ms a round" = decode time / (tokens - accepted drafts), which does not depend on how many drafts a run accepts.

    unset STRATA_ADAPT_FETCH=2
    ms a round (per start, in pair order) 14.45 / 13.92 / 14.25 / 14.64 13.60 / 13.50 / 13.45 / 13.49 pairs -5.9%, -3.0%, -5.6%, -7.8%
    ms a round (mean ± sd) 14.31 ± 0.31 13.51 ± 0.06 -5.6%
    decode tok/s 169.8 ± 2.3 179.5 ± 0.4 +5.7%

    The cache got 7,205-7,275 slots, about 29% of the 24,576 experts. On 477ac13c (0.1.45) the same A/B gave 16.00 -> 15.16 ms a round (-5.3%); main decodes faster in both arms now.

  • The SYCL and Metal link shapes, without those toolchains: g++ stand-ins that include the new header. A SYCL-like unit (the old signatures defined and called, as in sycl/src/kernels/cuda/verify_kernels.dp.cpp and sycl/src/core/verify.cpp) links and calls them; a Metal-like unit (the two stub lines from stubs.cpp, called the way src/core/verify.cpp calls them) links and reaches the stubs.

Failed: none observed on this revision. (With the PR's first header, the SYCL-like stand-in failed to link, as said above.)

Not run:

  • STRATA_ADAPT_FETCH=1 on this pack, other cache sizes, Linux.
  • HIP, SYCL and Metal builds (no ROCm, oneAPI or Mac here); only the stand-in links above.

Limits

  • One pack and one cache size measured on this revision. Earlier, on 0.1.40.3 with ISTA-DASLab's IQ2_XS model (a 6,297-slot cache, --pcie-frac 0.25): chat -9.1% and 32K explain -6.8% a round. That model is no longer on this PC.
  • It acts only through the PCIe share: with no share (--pcie-frac 0) or with --pcie-mode dma|direct it is off, and the start log says why.

🤖 Generated with Claude Code


🔄 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/2964 **Author:** [@sergqwer](https://github.com/sergqwer) **Created:** 10/17/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/adapt-fetch` --- ### 📝 Commits (1) - [`f8184f2`](https://github.com/Niko1221/Strata/commit/f8184f25c169f6459b2e2a1524731055f54c5d90) decode: STRATA_ADAPT_FETCH=1|2 - the PCIe share's blobs are admitted into the VRAM tier (opt-in) ### 📊 Changes **9 files changed** (+256 additions, -35 deletions) <details> <summary>View changed files</summary> 📝 `docs/DETAILS.md` (+1 -0) 📝 `include/strata/core/expert_source.hpp` (+23 -1) 📝 `include/strata/core/verify.hpp` (+3 -1) 📝 `include/strata/kernels/verify_kernels.hpp` (+7 -0) 📝 `metal/src/engine/stubs.cpp` (+2 -2) 📝 `src/core/expert_source.cpp` (+77 -6) 📝 `src/core/verify.cpp` (+8 -3) 📝 `src/kernels/cuda/verify_kernels.cu` (+24 -8) 📝 `src/program/generate.cpp` (+111 -14) </details> ### 📄 Description ## Problem and result Decode reads expert blobs from host RAM three ways: the CPU pool, the PCIe share (`--pcie-frac` of a layer's misses, staged into VRAM by `fetch_blobs`), and the adaptive tier's swaps. The PCIe share's blobs cross into VRAM anyway, and today they are dropped after the window. This opt-in lets the most useful of them stay there. - Unset: nothing changes (identity below). - `STRATA_ADAPT_FETCH=2` on the NVFP4 pack with a ~29% cache and `--pcie-frac 0.25`: 14.31 -> 13.51 ms a decode round (-5.6%), 169.8 -> 179.5 tok/s; every pair faster. ## Related discussion None beyond this PR. It was #2964 before the 0.2.0-beta tracker reset. It is opt-in and changes no default. Since the reset it has one change besides the rebase: the SYCL and Metal builds are kept linking (see Approach, last bullet). ## Approach Opt-in, `STRATA_ADAPT_FETCH=1|2`; unset changes nothing. - The share takes the layer's most-routed misses, by the tier's decayed counts (today: the last ones in routing order). Tail-skipped and unpinned blobs are not picked. - A fetched expert can be **admitted**: when it is routed at least `STRATA_ADAPT_FETCH_MIN` (1) and `STRATA_ADAPT_FETCH_MARGIN` (0.5) more than the layer's least-routed resident expert that the window does not route, `fetch_blobs` copies it straight into that expert's slot (a new optional `dst2` target per blob) instead of staging it, and it becomes resident: a swap with no RAM read of its own. - `=2` leaves the tier's own swaps out of a layer where an admission ran since the tier's last round; the tier keeps the layers the share did not reach. `=1` runs beside them. - The admissions write `host_res` during a window; the device table follows through #1517's pre-launch patch (3f2db5e2), whether the tier waits or not. - The router lookahead copies the residency rows it reads when the layer is submitted, because the table now changes while the lookahead runs (on `main` that is the multi-layer lookahead with 0.2.0's confidence scores, kept as they are). - Experts the tier is copying in are left alone. - Off, with a log line saying why: `--batch`, `--pipeline-windows`, `--adapt-async`, a layer split, peer or helper GPUs, the resident RAM mode, `STRATA_ADAPT_OVERLAP=1`, the foresight swap space, `--pcie-mode dma|direct`, or no PCIe share. - `STRATA_ADAPT_FETCH_VERIFY=1` (`strata generate`) reads every admitted slot back and compares it with the experts' bytes. - The verify plan block grows by 16 u64 (`dst2`), zero unless the opt-in writes them. - `fetch_blobs` / `rebase_ptrs` get overloads with `dst2`; the old signatures stay, because the SYCL copy takes `include/strata/kernels/verify_kernels.hpp` from the root and defines and calls those. The Metal stubs (`metal/src/engine/stubs.cpp`) follow the new overloads, written by hand in `gen_stubs.py`'s form. (The first version of this PR gave `dst2` a default argument instead; a g++ stand-in for the SYCL link showed that breaks it: `undefined reference to fetch_blobs(..., unsigned long long const*)`.) - `docs/DETAILS.md`: one bullet next to #1517's. ## Validation Revision: this branch, one commit f8184f25 on `main` **e88ee39d** (v0.2.0-beta + 12 commits). RTX 5090, Ryzen 9 9950X3D, 128 GB, Windows 11; MSVC 2022 17.14, CUDA 13.3, release configure (`-DSTRATA_PORTABLE=ON`, `75-real;86-real;89-real;120-real`, ggml at the pinned 3cf03257). Model: the NVFP4 GPTQ pack (`Maximilian228/Qwen3.8-Flash-Next-NVFP4-GPTQ-Strata`, upstream setup's `--family nvfp4 --model NVFP4` files). **Passed:** - **Unset = `main`.** `strata --serve` with setup's model files plus `--expert-cache 3000 --prefill auto --spec 6 --spec-min-p 0.7 --max-context 262144 --kv int8 --gpu 0 --pcie-frac 0 --adapt-every 1000000`, env `STRATA_PREFILL_CPU_SHARE=0 STRATA_PCIE_BALANCE=0 STRATA_IQ_MT_MIN=1 STRATA_DUMP_FIRST_LOGITS=<file>`; a 2,100-token and a 32,037-token prompt, 32 greedy tokens each: first-token logits and tokens byte-identical to a build of `main` e88ee39d (2K `1e9c612c`, 32K `f5b2872c`). - **Checks with it on.** `strata generate` with setup's model files plus `--expert-cache auto --vram-reserve-mib 1500 --pcie-frac 0.25 --prefill auto --spec 6 --spec-min-p 0.7 --kv int8 --max-context 262144 --stats`, 600 tokens after a 45-token prompt, `STRATA_ADAPT_FETCH=2 STRATA_ADAPT_FETCH_VERIFY=1 STRATA_ADAPT_CHECKRES=1`: 6,511 admissions (23.2 a round); the read-back covered 6,189 of them and 0 differed. The residency check covered 281 windows: 0 with mismatches, 0 layer-windows with CPU experts and no activation published. The tier itself still swapped 1,357 experts in the layers the share did not reach. - **A/B.** The same build in both arms, `strata --serve` with setup's model files plus `--expert-cache auto --vram-reserve-mib 1500 --pcie-frac 0.25 --prefill auto --spec 6 --spec-min-p 0.7 --kv int8 --max-context 262144`; the adaptive tier on, as by default. 4 interleaved pairs (off f2 f2 off off f2 f2 off); each start: 4 decodes of up to 600 tokens after a 45-token prompt. "ms a round" = decode time / (tokens - accepted drafts), which does not depend on how many drafts a run accepts. | | unset | `STRATA_ADAPT_FETCH=2` | | |---|---|---|---| | ms a round (per start, in pair order) | 14.45 / 13.92 / 14.25 / 14.64 | 13.60 / 13.50 / 13.45 / 13.49 | pairs -5.9%, -3.0%, -5.6%, -7.8% | | ms a round (mean ± sd) | 14.31 ± 0.31 | **13.51 ± 0.06** | **-5.6%** | | decode tok/s | 169.8 ± 2.3 | 179.5 ± 0.4 | +5.7% | The cache got 7,205-7,275 slots, about 29% of the 24,576 experts. On 477ac13c (0.1.45) the same A/B gave 16.00 -> 15.16 ms a round (-5.3%); `main` decodes faster in both arms now. - The SYCL and Metal link shapes, without those toolchains: g++ stand-ins that include the new header. A SYCL-like unit (the old signatures defined and called, as in `sycl/src/kernels/cuda/verify_kernels.dp.cpp` and `sycl/src/core/verify.cpp`) links and calls them; a Metal-like unit (the two stub lines from `stubs.cpp`, called the way `src/core/verify.cpp` calls them) links and reaches the stubs. **Failed:** none observed on this revision. (With the PR's first header, the SYCL-like stand-in failed to link, as said above.) **Not run:** - `STRATA_ADAPT_FETCH=1` on this pack, other cache sizes, Linux. - HIP, SYCL and Metal builds (no ROCm, oneAPI or Mac here); only the stand-in links above. ## Limits - One pack and one cache size measured on this revision. Earlier, on 0.1.40.3 with ISTA-DASLab's IQ2_XS model (a 6,297-slot cache, `--pcie-frac 0.25`): chat -9.1% and 32K explain -6.8% a round. That model is no longer on this PC. - It acts only through the PCIe share: with no share (`--pcie-frac 0`) or with `--pcie-mode dma|direct` it is off, and the start log says why. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi changed title from [PR #2964] [Engine] decode: STRATA_ADAPT_FETCH=1|2 (opt-in) - the PCIe share's most-routed misses are admitted into the VRAM tier (-5.6% a round on the NVFP4 pack) to [PR #2964] [CLOSED] [Engine] decode: STRATA_ADAPT_FETCH=1|2 (opt-in) - the PCIe share's most-routed misses are admitted into the VRAM tier (-5.6% a round on the NVFP4 pack) 2026-11-07 16:30:28 +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#4366
No description provided.