mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 23:08:36 +00:00
CPU prompt share on a layer split: the link rule arms it from the stages' summed stream floors (cc 12.0 cards, STRATA_PREFILL_CPU_SHARE_AUTO=0 keeps it off)
The share is off on a layer split by default. With explicit STRATA_PREFILL_CPU_SHARE=auto and the limit above the split's 8,192-token chunk, experts of up to 64 tokens, 2x RTX 5090 on one board (GPU0 PCIe 4.0 x2 3.6 GB/s first stage, GPU1 x8 14.1 GB/s, 32 pool workers, UD-Q4_K_XL, --layer-split auto, 3 rounds) the prompt takes 0.25-0.68 of the split's default time at 84 / 1,024 / 2,048 / 4,096 / 8,192 / 12,288 / 16,384 / 32,768 tokens (843 -> 327, 1,957 -> 829, 5,549 -> 1,395, 5,949 -> 2,345, 6,783 -> 4,599, 11,052 -> 5,999, 11,233 -> 7,578, 20,026 -> 13,125 ms), decode level; the share with the default limit 3,072 costs 3-4% from 4K up. Prefill::arm_cpu_share_split(applies, floor_ms, pool_workers, all_cc120) (called before arm_cpu_share in the serve path when the engine runs a layer split): floor_ms is the sum over the stages of (pairs of the stage's layers - its cache slots) x blob / its link; the share is armed by default only when share_rules::link_rule_floor raises the limit above 3,072 (here 3,556 ms -> 12,032 tokens, 64-token experts), so a split of fast links keeps the share off as before. With the rule (nothing set against STRATA_PREFILL_CPU_SHARE_AUTO=0): x0.38 / 0.41 / 0.25 / 0.38 / 0.63 / 0.52 / 0.64 / 0.62 of the default at the same lengths, decode chat 129.2 -> 132.5, code 189.7 -> 203.9, agent 136.3 -> 138.2 tok/s. Forced-token KL on the split against the FP16 prompt path (48 prompts, 12,288 positions, fixed share 0.5): exact 0.01119, share with 8-token experts 0.980 [0.938, 1.024] of it, share with 64-token experts and limit 16,384 0.979 [0.907, 1.053]. Docs updated (DETAILS.md).
This commit is contained in:
1 parent
a620ffb619
commit
595d409226
5 files changed
+55
-8
No files matched your search
+1
-1
@@ -1099,7 +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_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. Measured prompt time against the default (limit 3,072, 8-token experts): 14.1 GB/s 1K / 2K / 4K / 8K / 12K tokens x0.85 / 0.86 / 0.49 / 0.73 / 0.91 (4,273 -> 2,077 ms at 4K), 28.3 GB/s 4K 2,153 -> 1,425 ms; 53.6 GB/s unchanged. On a layer split of such cards the share is armed by default too when the stages' stream floors, summed, raise the limit above 3,072 (2x RTX 5090, PCIe 4.0 x2 + x8: 1K / 4K / 16K / 32K tokens x0.41 / 0.38 / 0.64 / 0.62 of the split without it, decode level); `STRATA_PREFILL_CPU_SHARE_AUTO=0` keeps the share off on a split. Output changes in the last bits where the CPU takes more than the default's experts: forced-token KL against the FP16 path 0.01096-0.01137 with the wide share against 0.01035-0.01119 without it (ratio 0.98-1.05, every interval contains 1). |
|
||||
| `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). |
|
||||
|
||||
@@ -309,6 +309,9 @@ public:
|
||||
/// `by_default`: this path is one the share was measured on (CUDA, one GPU, no batch slots), so with the variable unset
|
||||
/// the share is on for chunks below 1024 tokens (STRATA_PREFILL_CPU_SHARE=0 turns it off).
|
||||
static void arm_cpu_share(bool applies, bool by_default = false);
|
||||
/// BW-H: a layer split (before arm_cpu_share): arms the default share with the link rule when `floor_ms` (the stages' stream floors summed, share_rules.hpp link_rule_floor) raises the limit above 3,072;
|
||||
/// STRATA_PREFILL_CPU_SHARE_AUTO=0 or an explicit STRATA_PREFILL_CPU_SHARE leave it as it was. `all_cc120`: every stage's card is compute capability 12.0 (the class measured; =1 asks for any).
|
||||
static bool arm_cpu_share_split(bool applies, double floor_ms, int pool_workers, bool all_cc120);
|
||||
/// STRATA_PREFILL_CPU_SHARE_BATCH=1 (batch slots beside the pool): set before each read - true while a slot decodes
|
||||
/// (its windows use the pool), so no chunk of that read takes the share; false lets the read's chunks take it.
|
||||
static void set_share_blocked(bool blocked);
|
||||
|
||||
@@ -69,19 +69,23 @@ constexpr double kLinkPoolRef = 22.0; // the pool the 3.4 was measured
|
||||
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) {
|
||||
/// The rule from the stream floor F (ms) itself: one card's F is (experts not on it) x blob / link; a layer split's is the sum over its stages, because a chunk passes through every stage in turn.
|
||||
inline LinkRule link_rule_floor(double f, int pool_workers) {
|
||||
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;
|
||||
if (!(f > 0.0)) return r;
|
||||
r.floor_ms = f;
|
||||
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;
|
||||
int64_t lim = (int64_t) (t * link_pool_factor(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;
|
||||
}
|
||||
inline LinkRule link_rule(const LinkRuleIn& in) {
|
||||
if (!(in.link_gbps > 0.0) || in.total <= 0 || in.resident < 0 || in.resident >= in.total || !(in.blob_mb > 0.0)) return LinkRule{};
|
||||
return link_rule_floor((double) (in.total - in.resident) * in.blob_mb / in.link_gbps, in.pool_workers);
|
||||
}
|
||||
/// 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;
|
||||
|
||||
@@ -479,13 +479,16 @@ inline strata::prefill::switch_point::Card sp_card() {
|
||||
}
|
||||
// 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 int link_rule_env() {
|
||||
static const int env = [] { const char* v = std::getenv("STRATA_PREFILL_CPU_SHARE_AUTO"); return strata::prefill::share_rules::env_state(v); }();
|
||||
return env;
|
||||
}
|
||||
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);
|
||||
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, link_rule_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()`).
|
||||
@@ -3728,6 +3731,27 @@ void Prefill::arm_cpu_share(bool applies, bool by_default) {
|
||||
#endif
|
||||
}
|
||||
|
||||
// BW-H: a layer split arms the default share only where the link rule raises the limit above 3,072 (the stream floor summed over the stages is large: a slow link in the chain); a split of fast links keeps the
|
||||
// share off, as before. Call before arm_cpu_share (whose tail takes the limit as the stream floor). Returns whether it armed.
|
||||
bool Prefill::arm_cpu_share_split(bool applies, double floor_ms, int pool_workers, bool all_cc120) {
|
||||
#if !defined(STRATA_USE_HIP) && !defined(STRATA_HIP_GFX906)
|
||||
if (!applies || cpu_share_explicit() != -2.0 || g_share_default) return false;
|
||||
if (!strata::prefill::share_rules::link_rule_enabled(true, true, true, all_cc120 ? 12 : 0, 0, link_rule_env())) return false;
|
||||
const auto r = strata::prefill::share_rules::link_rule_floor(floor_ms, pool_workers);
|
||||
if (!r.arm || r.limit <= strata::prefill::share_rules::kShareLimitNew) return false;
|
||||
g_share_default = true;
|
||||
g_share_limit_arch = r.limit;
|
||||
g_share_nt_arch = r.nt;
|
||||
std::fprintf(stderr, "prefill: CPU share rule on a layer split: the stages' links need %.0f ms to stream the experts the cards do not hold, %d pool workers: the CPU share is ON by default for chunks up to %lld tokens, "
|
||||
"experts of up to %d tokens go to the CPU. STRATA_PREFILL_CPU_SHARE_AUTO=0 keeps the share off on a split; STRATA_PREFILL_CPU_SHARE=0 turns it off.\n",
|
||||
floor_ms, pool_workers, (long long) r.limit, std::max<int>(r.nt, (int) strata::kernels::cpu::MAXT));
|
||||
return true;
|
||||
#else
|
||||
(void) applies; (void) floor_ms; (void) pool_workers; (void) all_cc120;
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void Prefill::set_share_blocked(bool blocked) { g_share_blocked.store(blocked, std::memory_order_release); }
|
||||
|
||||
void Prefill::fix_cpu_share(double share) { g_share_fixed = share >= 0.0 ? std::clamp(share, 0.0, 1.0) : -1.0; }
|
||||
|
||||
@@ -11679,6 +11679,22 @@ int main(int argc, char** argv) {
|
||||
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, pool.workers());
|
||||
// BW-H: a layer split takes the default share where the link rule raises its limit (the stages' stream floors summed: a chunk passes through every stage in turn)
|
||||
if (share_pool && (!stages.empty() || multi_gpu) && !stages.empty() && o.batch <= 0 && share_has_work) {
|
||||
double floor_ms = 0.0;
|
||||
bool links_ok = o.pcie_probe_gbps > 0.0, all_cc120 = true;
|
||||
auto stage_floor = [&](const strata::core::ExpertCache& xc, int64_t lb, int64_t le, double link, int dev) {
|
||||
if (!(link > 0.0) || xc.slots() <= 0) { links_ok = false; return; }
|
||||
const int64_t miss = std::max<int64_t>(0, (le - lb) * g.n_expert - (int64_t) xc.slots());
|
||||
floor_ms += (double) miss * ((double) xc.bytes() / (double) xc.slots() / 1e6) / link;
|
||||
cudaDeviceProp dp;
|
||||
if (cudaGetDeviceProperties(&dp, dev) != cudaSuccess || dp.major != 12 || dp.minor != 0) all_cc120 = false;
|
||||
};
|
||||
stage_floor(xcache, 0, stages.front()->lb, o.pcie_probe_gbps, 0);
|
||||
for (auto& st : stages) stage_floor(st->cache, st->lb, st->le, st->link_gbps, st->dev);
|
||||
if (links_ok && share_default_ok())
|
||||
strata::prefill::Prefill::arm_cpu_share_split(true, floor_ms, pool.workers(), all_cc120);
|
||||
}
|
||||
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;
|
||||
|
||||
Reference in new issue
Block a user