CPU prompt share: the limit and the expert width follow the card's PCIe link (compute capability 12.0 default, STRATA_PREFILL_CPU_SHARE_AUTO=0 to get 3,072 / 8 back)

The default share took chunks up to 3,072 tokens and experts of at most 8 tokens, a setting measured on one 28 GB/s link.  A chunk from the limit up streams every expert the card does not hold in
one pass whose time F (bytes of the missing experts / the link) does not depend on the chunk length; the staged walk with the share grows with it, so the share pays up to a length T* that
grows with F.  RTX 5090 cards, UD-Q4_K_XL (8,056 of 24,576 experts on the card), 3 interleaved rounds, the share with 32-token experts against the default: T* 4.2K tokens at 53.6 GB/s (15 pool
workers), 8.8K at 28.3 GB/s (22), 14.0K at 14.1 GB/s (32), 19.7K (32-token experts) / 25K (64-token experts) at 3.6 GB/s; 8 pool workers 7.7K, 16 workers 8.5K (22: 8.8K).  At 53.6 GB/s the
default 3,072 beats streaming by 25-34% from 1,536 tokens and above ~4K staged equals streamed, so the rule never goes below 3,072.

share_rules.hpp link_rule(): limit = 3.4 x F (ms) tokens up to F = 3.67 s, +0.76 tokens per ms of F above it, between 3,072 and 20,480, scaled by (workers / 22)^0.15 for smaller pools; experts of
up to 32 tokens (64 from F = 3 s) where the limit is raised.  Prefill::set_card_expert_share takes the pool's workers; arm_cpu_share applies the rule to the default-armed share only (an explicit
STRATA_PREFILL_CPU_SHARE, STRATA_PREFILL_CPU_SHARE_MAX and STRATA_PREFILL_CPU_SHARE_NT keep their meaning) and prints one "CPU share rule:" line.  STRATA_PREFILL_CPU_SHARE_AUTO: unset = cc 12.0
discrete cards with the link probed, 1 = any CUDA card, any other value = off.  Settings register, docs, unit tests (share_rules_test) updated.
This commit is contained in:
Niko1221 committed 2026-11-19 17:28:01 +01:00
1 parent 16c3fa0cd1
commit a620ffb619
8 files changed
+177 -11

No files matched your search

+1
View File
@@ -1099,6 +1099,7 @@ bits of the answer: a switch that changes rounding can change a greedy answer at
| --- | --- | --- | --- |
| `STRATA_PREFILL_CPU_SHARE` (`auto`, cap `STRATA_PREFILL_CPU_SHARE_MAX=1024`) | CUDA, one GPU, no `--batch`, prompt chunks under 1,024 tokens | `STRATA_PREFILL_CPU_SHARE=0` | The CPU pool computes the experts few of the chunk's tokens route to, while the GPU works on the rest. `auto` measures per layer how long each side takes and checks that sharing pays. Skipped with one log line when RAM or commit is short. Output changes in the last bits. Layer split, batch slots and HIP keep it off unless you set it. On a layer split the explicit `STRATA_PREFILL_CPU_SHARE=auto` works (2x RTX 5090 with a PCIe 4.0 x2 + x8 board, UD-Q4_K_XL, one 1,024-token prompt 1,958 -> 986 ms). |
| `STRATA_PREFILL_CPU_SHARE_NT=N` (9-256) | CUDA, with the share on | unset (the share takes only experts of at most 8 tokens) | The CPU share may also take the experts up to N tokens of a chunk (cheapest first); the pool runs such an expert as jobs of 8 tokens that share its weights, each row the same bits whatever the job. Opt-in: the chunk limit `STRATA_PREFILL_CPU_SHARE_MAX` must be raised with it to reach 4K prompts. RTX 5090 on PCIe 4.0 x8 (14 GB/s), 32 pool workers on a Xeon 8352V, UD-Q4_K_XL, `STRATA_PREFILL_CPU_SHARE=auto STRATA_PREFILL_CPU_SHARE_NT=32 STRATA_PREFILL_CPU_SHARE_MAX=8192`: prompt of 1,024 / 2,048 / 4,096 / 8,192 / 12,000 tokens 1,292 -> 956 / 1,832 -> 1,392 / 4,272 -> 1,828 / 4,455 -> 3,244 / 4,694 -> 4,254 ms, 16K and up slower with a limit that high (5.0 -> 5.6 s at 16K); forced-token KL against the FP16 path (fixed share 0.5, N=64, limit 8192) 0.01155 against 0.01096 without the share (ratio 1.054 [0.993, 1.120]). |
| `STRATA_PREFILL_CPU_SHARE_AUTO=0` | CUDA, one GPU, the default-armed CPU share, compute capability 12.0 (RTX 50 series, PRO Blackwell); `=1` asks for it on any CUDA card | `STRATA_PREFILL_CPU_SHARE_AUTO=0` (the share keeps its 3,072-token limit and 8-token experts) | The default share's chunk limit and expert width follow the card's PCIe link (the start-up probe), the experts the card does not hold and the CPU pool: a chunk streams every missing expert in one pass whose time F (bytes of the missing experts / the link) does not depend on the chunk, while the share path grows with it, so the share pays up to a length T* that grows with F. RTX 5090, UD-Q4_K_XL, 8,056 of 24,576 experts on the card, T* measured as where the share with 32-token experts meets the default: 4.2K tokens at 53.6 GB/s (F 0.97 s, 15 pool workers), 8.8K at 28.3 GB/s (1.83 s, 22 workers), 14.0K at 14.1 GB/s (3.67 s, 32 workers), 19.7K (32-token experts) and 25K (64-token experts) at 3.6 GB/s (14.4 s). The limit is 3.4 x F tokens (F in ms; a margin under T*), less above F = 3.67 s, between 3,072 and 20,480, scaled down for pools below 22 workers; experts of up to 32 tokens go to the CPU where the limit is above 3,072 (64 from F = 3 s). The engine prints one `CPU share rule:` line. `STRATA_PREFILL_CPU_SHARE_MAX` and `STRATA_PREFILL_CPU_SHARE_NT` set the two numbers by hand and win; an explicit `STRATA_PREFILL_CPU_SHARE` is taken as it is. Output changes in the last bits where the CPU takes experts of more than 8 tokens (see the KL line in the release notes). |
| `STRATA_NO_KQ512=1` | x86 CPUs with AVX-512 VNNI, Unsloth UD-Q4_K_XL files | unset (on) | The CPU experts' Q4_K gate/up rows and Q5_1 / Q8_0 down rows run in 512-bit VNNI lanes for groups of 8 tokens and more (the CPU prompt share's jobs; a decode window's 2-7 token groups ran 1-6% slower on them), bit for bit what the one-token dot gives; checked against the build's own dot on first use. `STRATA_KQ512_MIN=N` moves the token floor. |
| `STRATA_ROUTE_TAIL_SKIP` (7) | CUDA, and HIP gfx1200/gfx1201; one GPU or a layer split | `STRATA_ROUTE_TAIL_SKIP=0` | A missed expert that every token of a verify window routes at rank 7 or lower is neither copied nor computed. Not applied when every expert is in VRAM, with `--batch` slots, with a peer tier or helper GPU, on other HIP and SYCL, or when 90% or more of the experts are cached (`STRATA_TAIL_SKIP_MAX_CACHED=<percent>` moves that line; it is 60% on an AMD layer split). Answers differ slightly from a run without it. |
| PCIe share from the CPU's speed | CUDA, one GPU or a layer split, no `--pcie-frac` | `--pcie-frac N` always wins; `STRATA_PCIE_FRAC_DEFAULT=old` keeps the probe-only rule; `STRATA_PCIE_AUTO_SPLIT=0` keeps the fixed probe share on a CUDA layer split; `STRATA_PCIE_K_RULE=0` and `STRATA_PCIE_SHARE_MAX=0.60` keep the 0.2.10 rule | The share starts at the probe's value and is refined in the first decode windows from the CPU pool's time per missed expert: `L / (L + k R)`, rounded to 0.05 and kept between 0.10 and 0.95, changed at most three times. k is 1.85 from a pool rate R of 30 GB/s of expert bytes and falls linearly to 0.8 at 12 GB/s (a weak pool is compute-bound), so a strong pool gets exactly the 0.2.10 shares (below 0.60) and a weak one up to 0.95. A CUDA layer split refines each stage by its own probed link. Integrated GPUs (Strix Halo and the other APUs) and `STRATA_DEFAULTS=026` keep k 1.85 and 0.60; on HIP the layer-split refinement stays opt-in (`STRATA_PCIE_AUTO_SPLIT=1`). Each change prints a `PCIe share:` line. On HIP it is the default for gfx1200/gfx1201 and for a discrete gfx103x card (RX 6000, #4007); `STRATA_PCIE_FRAC_DEFAULT=auto` turns it on for other HIP parts. Measured on an RTX PRO 6000 (12 GB free): 2 x 12 GB layer split +12% decode; one card with 4 pool workers 56 -> 79 tok/s, 2 workers 31 -> 63, 32 workers unchanged. Output changes in the last bits (first-window KL 0.03 on the decode-window yardstick, the same as the single-card rule). |
+6 -2
View File
@@ -10,7 +10,7 @@ debugging and are kept in `terminal/data/settings-register.json`.
A number or a word is set like any environment variable, for example `STRATA_KVA=1`. In the Terminal, `strata launch --set NAME=value`
puts it in the model's run configuration.
## Switches you can turn on (268)
## Switches you can turn on (270)
Off unless you set them. The last column says where each one is described.
@@ -206,6 +206,7 @@ Off unless you set them. The last column says where each one is described.
| `STRATA_PREFILL_BORROW` | on / off | NVIDIA, AMD | [STRIX_HALO.md](STRIX_HALO.md), [STRIX_HALO_WINDOWS.md](STRIX_HALO_WINDOWS.md) |
| `STRATA_PREFILL_CPU_SHARE_BATCH` | on / off | NVIDIA and AMD | - |
| `STRATA_PREFILL_CPU_SHARE_MAX` | number | NVIDIA and AMD | [DETAILS.md](DETAILS.md) |
| `STRATA_PREFILL_CPU_SHARE_NT` | number | NVIDIA and AMD | [DETAILS.md](DETAILS.md) |
| `STRATA_PREFILL_EQUAL` | text | NVIDIA and AMD, Intel Arc | [DETAILS.md](DETAILS.md) |
| `STRATA_PREFILL_FIRST` | number | Intel Arc | [INTEL.md](INTEL.md) |
| `STRATA_PREFILL_HELP` | number | NVIDIA and AMD, Intel Arc | [BATCHING.md](BATCHING.md), [GYRO.md](GYRO.md), [MULTI_GPU.md](MULTI_GPU.md) |
@@ -262,6 +263,7 @@ Off unless you set them. The last column says where each one is described.
| `STRATA_SPEC_WATCH` | number | NVIDIA and AMD | [release-notes-0.2.2.md](release-notes-0.2.2.md) |
| `STRATA_SPLIT_HEADROOM` | number | Intel Arc | [INTEL_ARC.md](INTEL_ARC.md) |
| `STRATA_SPLIT_HEADROOM_TOL` | number | Intel Arc | [INTEL_ARC.md](INTEL_ARC.md) |
| `STRATA_SPLIT_LINK_MIN` | text | NVIDIA and AMD | [MULTI_GPU.md](MULTI_GPU.md) |
| `STRATA_SPLIT_MTP_BATCH` | text | NVIDIA and AMD | [BATCHING.md](BATCHING.md), [MULTI_GPU.md](MULTI_GPU.md) |
| `STRATA_SPLIT_OVERLAP` | number | NVIDIA and AMD | [MULTI_GPU.md](MULTI_GPU.md) |
| `STRATA_SPLIT_UNIFORM` | on / off | NVIDIA and AMD | [MULTI_GPU.md](MULTI_GPU.md) |
@@ -285,7 +287,7 @@ Off unless you set them. The last column says where each one is described.
| `STRATA_WATCHDOG_S` | number | NVIDIA and AMD, Intel Arc | [DETAILS.md](DETAILS.md) |
| `STRATA_WDDM_BUDGET` | number | AMD, Intel Arc | [AMD_HIP.md](AMD_HIP.md) |
## Switches that go back to earlier behaviour (85)
## Switches that go back to earlier behaviour (87)
These behaviours are on by default. Setting the switch returns the earlier behaviour; the notes in the register say which
version made it the default.
@@ -326,6 +328,7 @@ version made it the default.
| `STRATA_MTP_BATCH_RING` | on / off | NVIDIA and AMD, Intel Arc | v0.1.40.1 | - |
| `STRATA_NAN_GUARD` | number | NVIDIA and AMD | v0.1.43 | [DETAILS.md](DETAILS.md) |
| `STRATA_NO_IQ512` | on / off | CPU | v0.1.40.1 | - |
| `STRATA_NO_KQ512` | on / off | CPU | - | [DETAILS.md](DETAILS.md) |
| `STRATA_NUMA_CARD` | text | NVIDIA and AMD | - | - |
| `STRATA_NUMA_POOL` | on / off | NVIDIA and AMD, CPU | v0.2.2 | [DETAILS.md](DETAILS.md), [release-notes-0.2.2.md](release-notes-0.2.2.md) |
| `STRATA_NUMA_SPLIT` | text | NVIDIA and AMD, CPU | v0.2.2 | [DETAILS.md](DETAILS.md), [release-notes-0.2.2.md](release-notes-0.2.2.md) |
@@ -343,6 +346,7 @@ version made it the default.
| `STRATA_PF_XMX` | text | Intel Arc | v0.1.42 | [INTEL.md](INTEL.md), [release-notes-0.2.0.md](release-notes-0.2.0.md) |
| `STRATA_PIPELINE_ADAPT_ASYNC` | number | NVIDIA and AMD | v0.1.40.2 | - |
| `STRATA_PLE_AUTO_MMAP` | number | NVIDIA and AMD, Intel Arc | v0.1.43.1 | [DETAILS.md](DETAILS.md) |
| `STRATA_PREFILL_CPU_SHARE_AUTO` | on / off | NVIDIA and AMD | - | [DETAILS.md](DETAILS.md) |
| `STRATA_PREFILL_LOAN_WALK` | on / off | NVIDIA and AMD | - | - |
| `STRATA_PREFILL_STREAM_MIN` | number | NVIDIA and AMD, Intel Arc | v0.1.40.1 | [AMD_HIP.md](AMD_HIP.md), [STRIX_HALO.md](STRIX_HALO.md) |
| `STRATA_PREFILL_TAIL_LOAN` | on / off | NVIDIA and AMD | - | - |
+1 -1
View File
@@ -110,7 +110,7 @@ public:
static int64_t short_read_default(int64_t base);
/// STRATA_SWITCH_POINT (on by default for the class in switch_point_rule.hpp, =0 off): the expert cache's live slots and layers x experts of the single card's own model, before the first lend; the floor above is then
/// chosen from the share of experts the card does not hold, scaled by the cache's mean blob (MB), the start-up link probe (GB/s) and the card's SM count (switch_point_rule.hpp; 0 = unknown: the default floor). With STRATA_SWITCH_POINT=0 this changes nothing.
static void set_card_expert_share(int64_t resident_slots, int64_t total_pairs, double blob_mb = 0.0, double link_gbps = 0.0);
static void set_card_expert_share(int64_t resident_slots, int64_t total_pairs, double blob_mb = 0.0, double link_gbps = 0.0, int pool_workers = 0);
/// --prefill-pipe (opt-in): the chunk a layer split's first stage reads an `n`-token prompt in, for `stages`
/// stages, chunks of at most `cap` (the buffers' size) and a stage-chunk cost of b + a C with b/a = `ratio` tokens
/// (0: unknown - STRATA_PREFILL_EQUAL's rule: the same chunk count as `cap` gives, evened out when its last chunk
@@ -6,6 +6,8 @@
// honoured by Prefill::arm_cpu_share whatever this says.
#pragma once
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <string>
@@ -33,6 +35,64 @@ constexpr int64_t default_share_limit(bool raise = true) { return raise ? kShare
constexpr int64_t kShareLimitGfx12Fused = 2304;
constexpr int64_t gfx12_share_limit(bool fused_iq2s) { return fused_iq2s ? kShareLimitGfx12Fused : kShareLimitNew; }
// ---- the link-aware limit and expert width (BW-H, owner decision 11-19: "full blackwell plan") ----
// A chunk below the limit is STAGED (its routing is read back, only the routed experts the card lacks are brought, and the CPU may take some of them); a chunk from the limit up STREAMS every expert the card
// does not hold in one pass through a ring, at the link's speed. The streamed pass costs about F = (experts not on the card) x blob / link whatever the chunk (RTX 5090, UD-Q4_K_XL, 8,056 of 24,576 experts on the
// card: F = 0.97 s at 53.6 GB/s, 1.83 s at 28.3, 3.67 s at 14.1, 14.4 s at 3.6) plus ~0.07 ms a token; the staged pass with the wide share costs a fixed part plus 0.2-0.3 ms a token, so the staged walk wins up to a
// length T* that grows with F. Measured T* (prompt time of the share with experts of up to 32 tokens against the default, 3 interleaved rounds, bwh lenmap): 4.2K (53.6 GB/s, 15 workers), 8.8K (28.3 GB/s, 22 workers),
// 14.0K (14.1 GB/s, 32 workers), 19.7K with 32-token experts and 25K with 64-token experts (3.6 GB/s, 32 workers). The limit is a margin under T*: 3.4 x F up to F = 3.67 s (T* is 3.8-4.8 x F there), then 0.76 tokens
// per ms of F more (the CPU, not the link, sets T* on a very slow link), never below the default 3,072 (at 53.6 GB/s the default beats streaming from 1,536 tokens by 25-34%, and above ~4K staged = streamed) nor above
// 20,480. A pool smaller than the 22 workers the 3.4 was measured with takes less (8 workers: T* fell 13%, 16 workers: 3%). Experts of up to 32 tokens (64 from F = 3 s: T* equal at 14 GB/s, +27% at 3.6 GB/s) go
// to the CPU where the limit is raised; where it is not (a fast link) the share keeps the pool's own 8.
struct LinkRuleIn {
double link_gbps = 0.0; ///< the start-up host-to-device probe, GB/s (0 = not probed)
int pool_workers = 0; ///< the CPU pool's workers
int64_t resident = -1; ///< expert slots on the card
int64_t total = 0; ///< layers x experts
double blob_mb = 0.0; ///< mean expert blob of the cache, MB
};
struct LinkRule {
bool arm = false;
int64_t limit = 0; ///< the share's chunk limit, tokens
int nt = 0; ///< the experts the share may take: up to nt tokens of a chunk (0 = the pool's own 8)
double floor_ms = 0.0; ///< the stream floor: bytes of the experts the card does not hold / the link
};
constexpr int64_t kShareLimitMax = 20480; // the most the rule gives (T* is 25K at 3.6 GB/s with 64-token experts)
constexpr int64_t kShareLimitGrid = 256; // the prompt path's chunk grid
constexpr double kLinkTokensPerFloorMs = 3.4; // limit = this x the stream floor in ms up to kLinkKneeMs (the measured crossings are 3.8-4.8 x)
constexpr double kLinkKneeMs = 3670.0; // F of the 14.1 GB/s box: 12,480 tokens
constexpr double kLinkTokensPerMsAbove = 0.76; // beyond the knee: 3.6 GB/s (F = 14,388 ms) reaches the 20,480 cap
constexpr double kLinkWideFloorMs = 3000.0; // from this F the share takes experts of up to kLinkNtWide tokens
constexpr int kLinkNt = 32; // the share's expert width when the limit is raised
constexpr int kLinkNtWide = 64;
constexpr double kLinkPoolRef = 22.0; // the pool the 3.4 was measured with (EPYC 9B14: 22 workers)
inline double link_pool_factor(int workers) {
return workers > 0 ? std::min(1.0, std::pow((double) workers / kLinkPoolRef, 0.15)) : 1.0;
}
inline LinkRule link_rule(const LinkRuleIn& in) {
LinkRule r;
if (!(in.link_gbps > 0.0) || in.total <= 0 || in.resident < 0 || in.resident >= in.total || !(in.blob_mb > 0.0)) return r;
r.floor_ms = (double) (in.total - in.resident) * in.blob_mb / in.link_gbps;
const double f = r.floor_ms;
const double t = f <= kLinkKneeMs ? kLinkTokensPerFloorMs * f : kLinkTokensPerFloorMs * kLinkKneeMs + kLinkTokensPerMsAbove * (f - kLinkKneeMs);
int64_t lim = (int64_t) (t * link_pool_factor(in.pool_workers)) / kShareLimitGrid * kShareLimitGrid;
lim = std::min<int64_t>(kShareLimitMax, std::max<int64_t>(kShareLimitNew, lim));
r.limit = lim;
r.nt = lim > kShareLimitNew ? (f >= kLinkWideFloorMs ? kLinkNtWide : kLinkNt) : 0;
r.arm = true;
return r;
}
/// STRATA_PREFILL_CPU_SHARE_AUTO as the engine reads it: -1 unset (or empty), 1 for exactly "1", 0 for any other value.
inline int env_state(const char* v) {
if (v == nullptr || v[0] == '\0') return -1;
return (v[0] == '1' && v[1] == '\0') ? 1 : 0;
}
/// Whether the rule runs: the class it was measured on by default (a CUDA discrete card, one card, the link probed, compute capability 12.0), every CUDA card with =1, none with any other value.
inline bool link_rule_enabled(bool cuda, bool discrete, bool link_probed, int cc_major, int cc_minor, int env) {
if (!cuda || env == 0 || !discrete || !link_probed) return false;
return env == 1 || (cc_major == 12 && cc_minor == 0);
}
/// resident_slots: the expert cache's live slots; total_pairs: layers x routed experts per layer (<= 0: unknown, arm).
constexpr bool default_share_has_work(int64_t resident_slots, int64_t total_pairs) {
return total_pairs <= 0 || resident_slots < total_pairs;
+35 -5
View File
@@ -444,6 +444,7 @@ inline bool share_keeps_own_kernels(int64_t rows_cpu) {
std::atomic<int64_t> g_sp_resident{-1}, g_sp_total{0};
double g_sp_blob_mb = 0.0, g_sp_link_gbps = 0.0; // the cache's mean blob (MB) and the start-up probe (GB/s), from Prefill::set_card_expert_share
int g_sp_sm = 0; // the card's multiprocessor count
int g_sp_pool_workers = 0; // the CPU pool's workers (BW-H: the link-aware share rule reads it)
int g_sp_cc_major = 0, g_sp_cc_minor = 0; // the card's compute capability
bool g_sp_integrated = true; // not known as discrete until the card answered
// STRATA_SWITCH_POINT as set: -1 unset, 1 for "1", 0 for any other value (the way back)
@@ -476,6 +477,17 @@ inline strata::prefill::switch_point::Card sp_card() {
c.blob_mb = g_sp_blob_mb; c.link_gbps = g_sp_link_gbps; c.sm = g_sp_sm;
return c;
}
// STRATA_PREFILL_CPU_SHARE_AUTO (BW-H): the link-aware limit and expert width of the default-armed share (share_rules.hpp link_rule). Unset: on for the class measured (CUDA, discrete, one card,
// start-up link probe ran, compute capability 12.0); 1: on for any CUDA card; any other value (0): off, the share keeps its limit 3,072 and its 8-token experts.
inline bool link_rule_on() {
#if defined(STRATA_USE_HIP) || defined(__HIPCC__) || defined(STRATA_HIP_GFX906)
return false;
#else
static const int env = [] { const char* v = std::getenv("STRATA_PREFILL_CPU_SHARE_AUTO"); return strata::prefill::share_rules::env_state(v); }();
if (!switch_point_known()) return false; // the card's counts have not arrived: a single card, no batch slots only
return strata::prefill::share_rules::link_rule_enabled(true, !g_sp_integrated, g_sp_link_gbps > 0.0, g_sp_cc_major, g_sp_cc_minor, env);
#endif
}
// A build without MMQ (STRATA_PF_OWN_ONLY) loading a pack that is not a native one (the AVX-512 Q2_0 pack) whose layers the plan marks fused (mmq_plan(): `!lay.native && fused::enabled()`).
// The staged fused entry (fz_staged) and the int8 kernels (i8_l) read the native layout only, so below the floor each routed expert of such a layer runs on the dequantize + FP16 path.
// False without a loaded layout (the caller does not cache then) and in a build with MMQ.
@@ -682,13 +694,15 @@ inline bool pf_peer_cpu() {
// the experts a few tokens route to, as since 0.1.41. N > 8: the CPU also takes experts of up to N tokens (cheapest first, as before); the pool runs such an expert as jobs of MAXT
// tokens that share its blob (the rows of each token are the same bits whatever the group: kq512 / kq256 / the per-token dot), and the rows come back to the GPU as before. An expert's
// rows cost 10 KB each over the link, so an expert of ~300 tokens costs more to bring back than to stream (3 MB): N is clamped to 256. The rows of one layer are capped (kShareRowsMax).
int g_share_nt_arch = 0; // BW-H: the link rule's expert width (share_rules::link_rule), set by arm_cpu_share for the default-armed share
inline int cpu_share_nt() {
static const int v = [] {
static const bool explicit_nt = std::getenv("STRATA_PREFILL_CPU_SHARE_NT") != nullptr;
static const int env_n = [] {
const char* e = std::getenv("STRATA_PREFILL_CPU_SHARE_NT");
const int n = e ? std::atoi(e) : 0;
return n <= strata::kernels::cpu::MAXT ? (int) strata::kernels::cpu::MAXT : std::min(n, 256);
return e ? std::atoi(e) : 0;
}();
return v;
const int n = (!explicit_nt && g_share_nt_arch > 0 && g_share_default && cpu_share_explicit() == -2.0) ? g_share_nt_arch : env_n;
return n <= strata::kernels::cpu::MAXT ? (int) strata::kernels::cpu::MAXT : std::min(n, 256);
}
constexpr int64_t kShareRowsMax = 16384; // the CPU share's rows a layer may take (wide groups): 16384 x 2560 floats = 160 MiB of pinned rows
// STRATA_PREFILL_CPU_SHARE_MAX (default 3072, at least 1024): with the share on, chunks below it are staged after their
@@ -3435,7 +3449,7 @@ int64_t Prefill::short_read_default(int64_t base) {
return strata::prefill::short_read_default(base, cls, cls && layers_all_fused_only(), staged_fo_on(), trellis_g1151_all_fused() && layers_any_folded(),
sm120 && layers_all_fused_only());
}
void Prefill::set_card_expert_share(int64_t resident_slots, int64_t total_pairs, double blob_mb, double link_gbps) {
void Prefill::set_card_expert_share(int64_t resident_slots, int64_t total_pairs, double blob_mb, double link_gbps, int pool_workers) {
#if !defined(STRATA_USE_HIP) && !defined(STRATA_HIP_GFX906)
int dev = 0;
cudaDeviceProp prop;
@@ -3447,6 +3461,7 @@ void Prefill::set_card_expert_share(int64_t resident_slots, int64_t total_pairs,
#endif
g_sp_blob_mb = blob_mb;
g_sp_link_gbps = link_gbps;
g_sp_pool_workers = pool_workers;
g_sp_total.store(total_pairs, std::memory_order_release);
g_sp_resident.store(resident_slots, std::memory_order_release);
}
@@ -3665,6 +3680,21 @@ void Prefill::arm_cpu_share(bool applies, bool by_default) {
g_sp_resident.load(std::memory_order_acquire), g_sp_total.load(std::memory_order_acquire), sp_card()));
if (lim > 0) g_share_limit_arch = lim;
}
// BW-H: the link-aware limit and expert width (cc 12.0 by default; STRATA_PREFILL_CPU_SHARE_AUTO=0 keeps 3,072 / 8, =1 asks for it on any CUDA card)
if (g_share_limit_arch == 0 && link_rule_on()) {
strata::prefill::share_rules::LinkRuleIn in;
in.link_gbps = g_sp_link_gbps; in.pool_workers = g_sp_pool_workers;
in.resident = g_sp_resident.load(std::memory_order_acquire); in.total = g_sp_total.load(std::memory_order_acquire); in.blob_mb = g_sp_blob_mb;
const auto r = strata::prefill::share_rules::link_rule(in);
if (r.arm) {
g_share_limit_arch = r.limit;
g_share_nt_arch = r.nt;
std::fprintf(stderr, "prefill: CPU share rule: the card's link reads %.1f GB/s and %lld of %lld experts are not on it (%.1f GB, a stream floor of %.0f ms), %d pool workers: chunks up to %lld tokens take the share, "
"experts of up to %d tokens go to the CPU. STRATA_PREFILL_CPU_SHARE_AUTO=0 keeps 3,072 and 8; STRATA_PREFILL_CPU_SHARE_MAX / _NT set them by hand.\n",
in.link_gbps, (long long) (in.total - in.resident), (long long) in.total, (double) (in.total - in.resident) * in.blob_mb / 1000.0, r.floor_ms,
in.pool_workers, (long long) r.limit, std::max<int>(r.nt, (int) strata::kernels::cpu::MAXT));
}
}
std::fprintf(stderr, "prefill: the CPU share is ON by default for prompt chunks up to %lld tokens (the idle CPU "
"takes some of the experts the GPU would stream; answers can differ slightly from 0.1.40.3, "
"mean KL ~0.004 below 1024 tokens, ~0.011 at 1-3K). STRATA_PREFILL_CPU_SHARE=0 turns it off, "
+2 -2
View File
@@ -11678,7 +11678,7 @@ int main(int argc, char** argv) {
(long long) xcache.slots(), (long long) (g.n_layers * g.n_expert));
if (share_pool && stages.empty() && !multi_gpu && share_has_work && !share_default_ok()) share_has_work = false; // H11
if (stages.empty() && !multi_gpu && o.batch <= 0) // STRATA_SWITCH_POINT: one card, no batch slots; before any bytes_needed, like the share
strata::prefill::Prefill::set_card_expert_share((int64_t) xcache.slots(), (int64_t) (g.n_layers * g.n_expert), xcache.slots() > 0 ? (double) xcache.bytes() / (double) xcache.slots() / 1e6 : 0.0, o.pcie_probe_gbps);
strata::prefill::Prefill::set_card_expert_share((int64_t) xcache.slots(), (int64_t) (g.n_layers * g.n_expert), xcache.slots() > 0 ? (double) xcache.bytes() / (double) xcache.slots() / 1e6 : 0.0, o.pcie_probe_gbps, pool.workers());
strata::prefill::Prefill::arm_cpu_share(share_pool, share_pool && stages.empty() && !multi_gpu && share_has_work);
void* borrow = nullptr;
uint64_t borrow_bytes = 0;
@@ -22751,7 +22751,7 @@ int main(int argc, char** argv) {
int64_t spec_pos = strata::spec::kSpecNotStarted; // plan v0.3 P6: where the speculative loop starts (0 is a real position: a 1-token prompt on a native pack)
strata::prefill::Prefill prefill;
if (!multi_gpu && o.batch <= 0) // STRATA_SWITCH_POINT: before any bytes_needed, like the share
strata::prefill::Prefill::set_card_expert_share((int64_t) xcache.slots(), (int64_t) (g.n_layers * g.n_expert), xcache.slots() > 0 ? (double) xcache.bytes() / (double) xcache.slots() / 1e6 : 0.0, o.pcie_probe_gbps);
strata::prefill::Prefill::set_card_expert_share((int64_t) xcache.slots(), (int64_t) (g.n_layers * g.n_expert), xcache.slots() > 0 ? (double) xcache.bytes() / (double) xcache.slots() / 1e6 : 0.0, o.pcie_probe_gbps, pool.workers());
// #1595: not by default when the cache holds every expert (nothing to take)
strata::prefill::Prefill::arm_cpu_share(!multi_gpu && !o.no_pool,
!multi_gpu && !o.no_pool && o.batch <= 0 &&
+36
View File
@@ -58,6 +58,42 @@ int main() {
CHECK(default_share_memory_verdict(m).arm);
m.avail_ram = kUnknown; m.inplace_bytes = 500 * G;
CHECK(default_share_memory_verdict(m).arm); // RAM unknown: never blocks
// BW-H: the link-aware limit and expert width (RTX 5090, UD-Q4_K_XL: 24,576 experts of ~3.13 MB, 8,056 on the card)
{
LinkRuleIn in;
in.pool_workers = 22; in.resident = 8056; in.total = 24576; in.blob_mb = 3.133;
CHECK(!link_rule(in).arm); // no probe: today's behaviour
in.link_gbps = 28.3; // PCIe 5.0 x8 (EPYC 9B14, 22 workers): the measured crossing is 8.8K tokens
LinkRule r = link_rule(in);
CHECK(r.arm && r.limit == 6144 && r.nt == kLinkNt);
CHECK(r.floor_ms > 1800.0 && r.floor_ms < 1860.0);
in.pool_workers = 8; // a small pool takes less (8 workers: the crossing fell from 8.8K to 7.7K)
CHECK(link_rule(in).limit == 5120 && link_rule(in).nt == kLinkNt);
CHECK(link_pool_factor(0) == 1.0 && link_pool_factor(64) == 1.0 && link_pool_factor(22) == 1.0 && link_pool_factor(8) < link_pool_factor(16));
in.link_gbps = 14.1; in.pool_workers = 32; // PCIe 4.0 x8 (Xeon 8352V, 32 workers): crossing 14.0K
r = link_rule(in);
CHECK(r.arm && r.limit == 12288 && r.nt == kLinkNtWide);
in.link_gbps = 53.6; in.pool_workers = 15; // PCIe 5.0 x16 (Ryzen 9 9950X, 15 workers): crossing 4.2K, the default 3,072 stays
r = link_rule(in);
CHECK(r.arm && r.limit == kShareLimitNew && r.nt == 0);
in.link_gbps = 3.6; in.pool_workers = 32; // PCIe 4.0 x2: the cap, 64-token experts
r = link_rule(in);
CHECK(r.arm && r.limit == kShareLimitMax && r.nt == kLinkNtWide);
in.link_gbps = 1000.0; // a link so fast the floor is tiny: never below the default
CHECK(link_rule(in).limit == kShareLimitNew);
in.link_gbps = 28.3; in.resident = 24576; // every expert resident: nothing to take
CHECK(!link_rule(in).arm);
in.resident = -1;
CHECK(!link_rule(in).arm); // the card's counts not known
CHECK(env_state(nullptr) == -1 && env_state("") == -1 && env_state("1") == 1 && env_state("0") == 0 && env_state("auto") == 0);
CHECK(link_rule_enabled(true, true, true, 12, 0, -1)); // the class: a discrete cc 12.0 card, link probed
CHECK(!link_rule_enabled(true, true, true, 8, 6, -1)); // other cards: not measured
CHECK(link_rule_enabled(true, true, true, 8, 6, 1)); // =1 asks for it
CHECK(!link_rule_enabled(true, true, true, 12, 0, 0)); // =0 is the way back
CHECK(!link_rule_enabled(true, false, true, 12, 0, -1)); // an integrated card
CHECK(!link_rule_enabled(true, true, false, 12, 0, 1)); // no probe: nothing to read the link from
CHECK(!link_rule_enabled(false, true, true, 12, 0, 1)); // HIP
}
if (failed == 0) std::printf("share_rules_test: ok\n");
return failed ? 1 : 0;
}
+36 -1
View File
@@ -29784,6 +29784,41 @@
"retire_after": "",
"retired_in": ""
},
{
"name": "STRATA_PREFILL_CPU_SHARE_AUTO",
"backends": [
"cuda-hip"
],
"reads": [
{
"file": "src/prefill/prefill.cpp",
"line": 486,
"backend": "cuda-hip",
"fn": "getenv"
}
],
"parse": "flag",
"default_state": null,
"code_default": null,
"engine_sets": [],
"engine_defaults": [],
"launch_files": [],
"launch_sets": [],
"launch_reads": [],
"doc_mentions": [
"docs/DETAILS.md:1102"
],
"first_commit": null,
"first_date": null,
"since": null,
"last_commit": null,
"last_date": null,
"status": "rollback",
"owner": "core",
"note": "=0 keeps the default CPU prompt share's limit 3,072 tokens and 8-token experts; unset: the limit and expert width follow the card's PCIe link, the experts it does not hold and the pool (compute capability 12.0); =1: the same on any CUDA card (RESULTS-BW-H.md)",
"retire_after": "",
"retired_in": ""
},
{
"name": "STRATA_PREFILL_CPU_SHARE_BATCH",
"backends": [
@@ -29895,7 +29930,7 @@
"last_date": null,
"status": "opt-in",
"owner": "core",
"note": "experts of up to N tokens may go to the CPU prompt share (default: 8); 2,244-4,272 ms -> 1,828 ms at 4K on an x8 PCIe 4.0 link, KL ratio 1.054 [0.993, 1.120] (RESULTS-BW-E.md)",
"note": "experts of up to N tokens may go to the CPU prompt share (default: 8; on a compute capability 12.0 card the link rule STRATA_PREFILL_CPU_SHARE_AUTO sets 32 or 64 where it raises the limit); 2,244-4,272 ms -> 1,828 ms at 4K on an x8 PCIe 4.0 link, KL ratio 1.054 [0.993, 1.120] (RESULTS-BW-E.md, RESULTS-BW-H.md)",
"retire_after": "",
"retired_in": ""
},