mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 23:08:36 +00:00
Layer split of two CUDA cards: the CPU prefill share is armed by default, as on one card (STRATA_SPLIT_CPU_SHARE=0 turns it off)
Until now the default CPU prefill share (idle pool takes some of the experts a prompt chunk would stream over PCIe, chunks up to 3,072 tokens) was armed on one card only. A layer split streamed every expert of every short prompt over PCIe, stage after stage, so a prompt of 32 to 566 tokens took 1.4 to 1.8 times as long on two RTX 5060 Ti 16 GB as on one (UD-Q4_K_XL, DFlash2, PCIe 4.0 x8, 48 cores). The stages already take the pool one at a time (prefill.cpp), and STRATA_PREFILL_CPU_SHARE=auto works on a split; only the default was missing. share_rules.hpp: default_share_layout(later_stages, multi_gpu, env, cuda): one card as before; one later stage (two cards) on a CUDA build by default, the switch both ways; three and four cards, the helper caches and HIP / SYCL builds stay off. generate.cpp (serve): the H11 memory check and arm_cpu_share use it, one start-up line says so. share_rules_test: the layout table. Prompt ms, two cards, default share off against on (3 rounds, tail skip off): 32 tokens 605 -> 268, 64: 825 -> 384, 84: 1,193 -> 489, 169: 1,680 -> 669, 566: 3,188 -> 1,574, 1,024: 2,869 -> 1,754, 2,048: 4,547 -> 2,512; 4,096 and longer are above the limit (+2%). Details and the KL gate: phaseA-tests/bw/RESULTS-BW-F.md.
This commit is contained in:
1 parent
501738c68e
commit
38e6a05061
3 files changed
+38
-2
No files matched your search
@@ -38,6 +38,20 @@ constexpr bool default_share_has_work(int64_t resident_slots, int64_t total_pair
|
||||
return total_pairs <= 0 || resident_slots < total_pairs;
|
||||
}
|
||||
|
||||
// ---- which card layouts arm the default share (BW-F, two 16 GB cards) ----
|
||||
// Until 0.2.16 the default share was armed on one card only: a layer split left every prompt chunk below the staged-chunk limit to stream its experts over PCIe on each stage in turn, although
|
||||
// the stages already take the pool one at a time (prefill.cpp g_cpu_pool_busy). Two RTX 5060 Ti 16 GB (PCIe 4.0 x8, 14.3 GB/s each, EPYC 7K62 with 48 cores, UD-Q4_K_XL, DFlash2, layer split auto K = 24),
|
||||
// prompt ms, STRATA_PREFILL_CPU_SHARE=auto against the split's own default (share off), median of 3 rounds: see phaseA-tests/bw/RESULTS-BW-F.md (BW-MG-small).
|
||||
// `later_stages`: the layer split's stages after the first (0: no split); `multi_gpu`: a layer split across devices; `env`: STRATA_SPLIT_CPU_SHARE as read (-1 unset, 0 off, 1 on).
|
||||
// One card as before; exactly one later stage (two cards) by the switch's default on a CUDA build (not measured on HIP or SYCL); three and four cards, and the helper caches, are not measured and stay off.
|
||||
inline constexpr bool kSplitShareDefault = true;
|
||||
constexpr bool default_share_layout(int later_stages, bool multi_gpu, int env, bool cuda = true) {
|
||||
if (later_stages == 0 && !multi_gpu) return true;
|
||||
if (later_stages == 1 && multi_gpu && cuda) return env < 0 ? kSplitShareDefault : env != 0;
|
||||
return false;
|
||||
}
|
||||
constexpr int split_share_env_of(const char* v) { return v == nullptr || v[0] == '\0' ? -1 : (v[0] == '0' ? 0 : 1); }
|
||||
|
||||
|
||||
// ---- memory (0.1.41 report, RTX 5090, tight RAM: chats failed and the engine restarted until STRATA_PREFILL_CPU_SHARE=0) ----
|
||||
// The default share reads experts with the CPU and keeps two pinned buffers on the host. When the host has little
|
||||
|
||||
@@ -11674,10 +11674,20 @@ int main(int argc, char** argv) {
|
||||
std::fprintf(stderr, "strata serve: every expert is in the GPU cache (%lld of %lld): the CPU prefill share has "
|
||||
"nothing to take, so it is not armed by default (STRATA_PREFILL_CPU_SHARE=auto forces it)\n",
|
||||
(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
|
||||
// BW-F: one card as before, and a layer split of two cards (STRATA_SPLIT_CPU_SHARE=0 takes the split back to streaming every expert over PCIe; share_rules.hpp default_share_layout)
|
||||
#if defined(STRATA_USE_HIP) || defined(STRATA_USE_SYCL) || defined(__HIPCC__)
|
||||
constexpr bool share_cuda_build = false;
|
||||
#else
|
||||
constexpr bool share_cuda_build = true;
|
||||
#endif
|
||||
const bool share_layout = strata::prefill::share_rules::default_share_layout(
|
||||
(int) stages.size(), multi_gpu, strata::prefill::share_rules::split_share_env_of(std::getenv("STRATA_SPLIT_CPU_SHARE")), share_cuda_build);
|
||||
if (share_pool && share_layout && 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::arm_cpu_share(share_pool, share_pool && stages.empty() && !multi_gpu && share_has_work);
|
||||
strata::prefill::Prefill::arm_cpu_share(share_pool, share_pool && share_layout && share_has_work);
|
||||
if (share_pool && share_layout && share_has_work && !stages.empty() && multi_gpu && std::getenv("STRATA_PREFILL_CPU_SHARE") == nullptr)
|
||||
std::fprintf(stderr, "strata serve: layer split of two cards: the CPU prefill share is armed by default, as on one card (STRATA_SPLIT_CPU_SHARE=0 turns it off)\n");
|
||||
void* borrow = nullptr;
|
||||
uint64_t borrow_bytes = 0;
|
||||
int32_t lend_first = -1; // the first slot the prompt path may borrow (its largest chunk)
|
||||
|
||||
@@ -26,6 +26,18 @@ int main() {
|
||||
CHECK(strata::prefill::share_rules::gfx12_share_limit(true) == 2304 && strata::prefill::share_rules::gfx12_share_limit(false) == 3072); // AMD-Q
|
||||
static_assert(strata::prefill::share_rules::kShareLimitOld == 1024, "the old limit (the way back is STRATA_PREFILL_CPU_SHARE_MAX=1024)");
|
||||
|
||||
// BW-F: the card layouts that arm the default share: one card as before, two cards (one later stage) by the switch's default, nothing else
|
||||
{
|
||||
using namespace strata::prefill::share_rules;
|
||||
CHECK(default_share_layout(0, false, -1) && default_share_layout(0, false, 0) && default_share_layout(0, false, 1)); // one card: STRATA_SPLIT_CPU_SHARE is not read
|
||||
CHECK(default_share_layout(1, true, -1) == kSplitShareDefault); // two cards, the switch unset
|
||||
CHECK(!default_share_layout(1, true, 0) && default_share_layout(1, true, 1)); // the switch both ways
|
||||
CHECK(!default_share_layout(2, true, -1) && !default_share_layout(2, true, 1) && !default_share_layout(3, true, 1)); // three and four cards: not measured, never armed by default
|
||||
CHECK(!default_share_layout(1, true, -1, false) && !default_share_layout(1, true, 1, false) && default_share_layout(0, false, -1, false)); // HIP / SYCL: the split stays off, one card as before
|
||||
CHECK(!default_share_layout(1, false, 1) && !default_share_layout(0, true, 1)); // helper caches (no layer split) and an inconsistent split: off
|
||||
CHECK(split_share_env_of(nullptr) == -1 && split_share_env_of("") == -1 && split_share_env_of("0") == 0 && split_share_env_of("1") == 1 && split_share_env_of("on") == 1);
|
||||
static_assert(default_share_layout(0, false, -1), "constexpr");
|
||||
}
|
||||
// H11: memory verdicts
|
||||
using namespace strata::prefill::share_rules;
|
||||
const uint64_t G = 1ull << 30;
|
||||
|
||||
Reference in new issue
Block a user