feat(kar): isolate target native routed storage in explicit mode
KAR CUDA compile (GPU hidden) / kar-cuda-compile (pull_request) Failing after 52s
KAR CUDA compile (GPU hidden) / kar-cuda-compile (pull_request) Failing after 52s
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
#include "strata/core/conversation_memory.hpp"
|
||||
#include "strata/core/coupled_draft.hpp"
|
||||
#include "strata/core/expert_source.hpp"
|
||||
#include "strata/core/experimental_routed.hpp"
|
||||
#if defined(STRATA_NEXT_EXPERIMENTAL_KAR_EXPERTS)
|
||||
#include "kar_expert_miss.hpp"
|
||||
#endif
|
||||
@@ -1286,6 +1287,39 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Strict all-routed admission before device probing, contexts or native
|
||||
// resource setup. Native layout/geometry is confirmed after metadata load.
|
||||
const char* kar_expert_archive = std::getenv("STRATA_NEXT_KAR_EXPERTS_ARCHIVE");
|
||||
bool kar_all_routed = false, kar_prefill = false;
|
||||
std::string kar_option_error;
|
||||
if (!strata::core::parse_experimental_all_routed_flag(std::getenv("STRATA_NEXT_KAR_ALL_ROUTED"), kar_all_routed, kar_option_error)) {
|
||||
std::fprintf(stderr, "strata generate: %s\n", kar_option_error.c_str()); return 2;
|
||||
}
|
||||
if (kar_all_routed && !strata::prefill::parse_experimental_prefill_flag(std::getenv("STRATA_NEXT_KAR_PREFILL"), kar_prefill, kar_option_error)) {
|
||||
std::fprintf(stderr, "strata generate: %s\n", kar_option_error.c_str()); return 2;
|
||||
}
|
||||
if (kar_all_routed) {
|
||||
strata::core::ExperimentalRoutedProfile p;
|
||||
#if defined(STRATA_NEXT_EXPERIMENTAL_KAR_EXPERTS)
|
||||
p.built = true;
|
||||
#endif
|
||||
p.native_pack = !o.native_preset.empty(); p.prefill = kar_prefill; p.archive = kar_expert_archive;
|
||||
p.level = std::getenv("STRATA_NEXT_KAR_EXPERTS_LEVEL");
|
||||
p.chunk = o.prefill_chunk; p.automatic_chunk = o.prefill_auto; p.window = o.spec;
|
||||
p.no_pool = o.no_pool; p.no_capture = o.no_capture || o.graph_only || o.gpu_only_full || o.gpu_stages;
|
||||
p.multi_device = !o.layer_split.empty() || !o.split_device.empty() ||
|
||||
std::any_of(o.expert_cache_remote.begin(), o.expert_cache_remote.end(), [](int n) { return n != 0; });
|
||||
p.native_bank_option = o.mmap_experts || o.resident_cpu_experts || !o.shared_expert_arena.empty() ||
|
||||
o.pcie_frac != 0 || o.expert_cache_per_layer || o.expert_cache_cpu_order;
|
||||
p.native_cache = o.expert_cache; p.native_profile = !o.expert_profile.empty();
|
||||
p.adaptive_cache = o.adapt_every > 0 && o.adapt_swaps > 0;
|
||||
const char* device_plan = std::getenv("STRATA_VERIFY_DEVICE_PLAN");
|
||||
p.device_plan = device_plan && std::strcmp(device_plan, "0") != 0;
|
||||
if (!strata::core::validate_experimental_routed_profile(p, kar_option_error)) {
|
||||
std::fprintf(stderr, "strata generate: %s\n", kar_option_error.c_str()); return 2;
|
||||
}
|
||||
}
|
||||
|
||||
strata::core::set_coupled_draft(o.coupled_draft);
|
||||
if ((std::getenv("STRATA_KEYLESS_TRACE") || std::getenv("STRATA_KEYLESS_PREFILL_TRACE")) && (o.serve || o.max_new > 512)) {
|
||||
std::fprintf(stderr, "strata generate: STRATA_KEYLESS_TRACE is offline only and needs --max-new <= 512\n");
|
||||
@@ -1748,6 +1782,9 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
}
|
||||
const bool native_pack = strata::kernels::cpu::expert_layout().native;
|
||||
if (kar_all_routed && !native_pack) {
|
||||
std::fprintf(stderr, "strata generate: KAR all-routed requires a native expert layout\n"); return 2;
|
||||
}
|
||||
// STRATA_EARLY_REMOTE_CONTEXTS=1: create EVERY secondary context here, like CUDA1's. Under WSL2 the driver's
|
||||
// pinned/mapped host budget (dxg gpadl, ~1 GiB) is spent by CUDA0's weights and MTP before the later loop runs,
|
||||
// and a new context then fails with cudaErrorMemoryAllocation (CUDA2: "cudaSetDevice(2) failed: out of memory").
|
||||
@@ -1894,8 +1931,6 @@ int main(int argc, char** argv) {
|
||||
rope_cfg.type == RST::YaRN ? "YaRN" : "--yarn-attn-factor", rope_cfg.mscale());
|
||||
}
|
||||
}
|
||||
const char* kar_expert_archive = std::getenv("STRATA_NEXT_KAR_EXPERTS_ARCHIVE");
|
||||
bool kar_prefill = false;
|
||||
if (!strata::prefill::parse_experimental_prefill_flag(std::getenv("STRATA_NEXT_KAR_PREFILL"), kar_prefill, err)) {
|
||||
std::fprintf(stderr, "strata generate: %s\n", err.c_str()); return 2;
|
||||
}
|
||||
@@ -1927,7 +1962,10 @@ int main(int argc, char** argv) {
|
||||
// Native resident hits are the baseline. Route all otherwise CPU/PCIe
|
||||
// misses to the explicit experimental arm; use pcie-frac=0 in its baseline.
|
||||
o.pcie_frac = 0;
|
||||
if (kar_prefill)
|
||||
if (kar_all_routed)
|
||||
std::fprintf(stderr, "strata generate: experimental KAR all-routed ON: target native routed RAM/VRAM bank omitted; "
|
||||
"MTP/shared/dense/KV retained; quality not qualified\n");
|
||||
else if (kar_prefill)
|
||||
std::fprintf(stderr, "strata generate: experimental KAR prefill ON: all routed experts; native cache retained; quality not qualified\n");
|
||||
}
|
||||
#else
|
||||
@@ -2362,7 +2400,7 @@ int main(int argc, char** argv) {
|
||||
// An explicit number truncates the ranked list ("what would 2,000 slots give" without rebuilding the
|
||||
// file). `--expert-cache 0` used to take the count the profile was built for; the profile now ranks
|
||||
// every pair (issue #46: a card that holds more than the old 8,000 used to stop there), so it means auto.
|
||||
if (o.expert_cache == 0) o.expert_cache = -1;
|
||||
if (o.expert_cache == 0 && !kar_all_routed) o.expert_cache = -1;
|
||||
std::fprintf(stderr, "strata generate: profile %s: %zu ranked pairs, built for %lld slots\n",
|
||||
o.expert_profile.c_str(), profile.size(), (long long) pslots);
|
||||
}
|
||||
@@ -2684,7 +2722,11 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
strata::core::ArenaExpertSource arena_src;
|
||||
strata::core::ExpertSource* srcp = nullptr;
|
||||
if (o.mmap_experts) {
|
||||
if (kar_all_routed) {
|
||||
// No target routed IQ bank or mmap fallback. Null is intentional: the
|
||||
// strict callbacks must bypass every native source consumer.
|
||||
std::fprintf(stderr, "strata generate: target native routed expert source omitted (KAR all-routed)\n");
|
||||
} else if (o.mmap_experts) {
|
||||
// FileExpertSource maps the pack's experts.bin: a canonical pack has it; a native (IQ) pack has it when
|
||||
// built with `tools/iq_pack.py --experts-bin` (the per-layer blob sizes of its layout, PR #121). The low-RAM
|
||||
// mode: the experts come from the file through the OS cache instead of a pinned copy in RAM, for a PC whose
|
||||
@@ -3135,6 +3177,8 @@ int main(int argc, char** argv) {
|
||||
if (kar_expert_archive != nullptr) {
|
||||
drive.d.experimental_miss = &strata::kar::ExpertMiss::dispatch;
|
||||
drive.d.experimental_miss_user = &kar_expert_miss;
|
||||
drive.d.experimental_all_routed = kar_all_routed;
|
||||
drive.d.experimental_layers = g.n_layers;
|
||||
}
|
||||
#endif
|
||||
for (int r = 0; r < 3; ++r) if (o.expert_cache_remote[(size_t) r] > 0)
|
||||
@@ -3835,7 +3879,7 @@ int main(int argc, char** argv) {
|
||||
strata::prefill::Prefill::set_pinned_share(total ? (double) pinned / (double) total : 1.0);
|
||||
}
|
||||
auto lend_slots = [&](int64_t c) -> int64_t {
|
||||
const uint64_t need = strata::prefill::Prefill::bytes_needed(g, ss, c);
|
||||
const uint64_t need = strata::prefill::Prefill::bytes_needed(g, ss, c, kar_all_routed);
|
||||
const int64_t blob = (int64_t) strata::kernels::cpu::expert_layout().max_blob;
|
||||
int64_t k = (int64_t) ((need + (uint64_t) blob - 1) / (uint64_t) blob);
|
||||
if (xcache.slot_offsets() != nullptr) { // sized slots: take slots from the end until they hold `need`
|
||||
@@ -3959,7 +4003,11 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
strata::prefill::Prefill sp;
|
||||
#if defined(STRATA_NEXT_EXPERIMENTAL_KAR_EXPERTS)
|
||||
if (kar_prefill) sp.set_experimental_experts(&strata::kar::ExpertMiss::dispatch, &kar_expert_miss);
|
||||
if (kar_all_routed) {
|
||||
if (!sp.set_experimental_all_routed(&strata::kar::ExpertMiss::dispatch, &kar_expert_miss, err)) {
|
||||
std::fprintf(stderr, "strata generate: %s\n", err.c_str()); return 2;
|
||||
}
|
||||
} else if (kar_prefill) sp.set_experimental_experts(&strata::kar::ExpertMiss::dispatch, &kar_expert_miss);
|
||||
#endif
|
||||
void* borrow = nullptr;
|
||||
uint64_t borrow_bytes = 0;
|
||||
@@ -3986,7 +4034,7 @@ int main(int argc, char** argv) {
|
||||
std::vector<std::pair<int32_t, int32_t>> lent;
|
||||
};
|
||||
auto part_slots = [&](const PfPart& p, int64_t c) -> int64_t {
|
||||
const uint64_t need = strata::prefill::Prefill::bytes_needed(g, *p.ses, c);
|
||||
const uint64_t need = strata::prefill::Prefill::bytes_needed(g, *p.ses, c, kar_all_routed);
|
||||
strata::core::ExpertCache& xc = *p.cache;
|
||||
if (xc.slot_offsets() != nullptr) { // sized slots: from the end until they hold `need`
|
||||
int64_t k = 0;
|
||||
@@ -4114,7 +4162,7 @@ int main(int argc, char** argv) {
|
||||
const strata::core::OnDevice on(p.dev);
|
||||
size_t fb = 0, tb = 0;
|
||||
if (cudaMemGetInfo(&fb, &tb) != cudaSuccess) { (void) cudaGetLastError(); continue; }
|
||||
const uint64_t need = strata::prefill::Prefill::bytes_needed(g, *p.ses, chunk);
|
||||
const uint64_t need = strata::prefill::Prefill::bytes_needed(g, *p.ses, chunk, kar_all_routed);
|
||||
if ((uint64_t) fb >= need + (3ull << 29)) {
|
||||
std::fprintf(stderr, "strata serve: CUDA%d keeps its own prompt buffers (%.2f GiB of "
|
||||
"%.2f GiB free): no loan\n", p.dev < 0 ? 0 : p.dev,
|
||||
@@ -4183,7 +4231,7 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
}
|
||||
if (multi_gpu) sp.set_stage(0, split_at[0], &stages[0]->sp);
|
||||
if (!sp.init(wt, g, ss, srcp, &xcache, host_res.data(), o.prefill_chunk, main_cs, err, borrow, borrow_bytes))
|
||||
if (!sp.init(wt, g, ss, srcp, &xcache, host_res.empty() ? nullptr : host_res.data(), o.prefill_chunk, main_cs, err, borrow, borrow_bytes))
|
||||
return err.find("do not fit") != std::string::npos ? 2 : 1;
|
||||
return 0;
|
||||
};
|
||||
@@ -4201,7 +4249,7 @@ int main(int argc, char** argv) {
|
||||
const strata::core::OnDevice on(dev);
|
||||
size_t fb = 0, tb = 0;
|
||||
cudaMemGetInfo(&fb, &tb);
|
||||
const int64_t need = (int64_t) strata::prefill::Prefill::bytes_needed(g, i == 0 ? ss : stages[i - 1]->ss, c);
|
||||
const int64_t need = (int64_t) strata::prefill::Prefill::bytes_needed(g, i == 0 ? ss : stages[i - 1]->ss, c, kar_all_routed);
|
||||
if (need + kHeadroom > (int64_t) fb) {
|
||||
dev_out = dev < 0 ? 0 : dev; need_out = need; free_out = (int64_t) fb;
|
||||
return false;
|
||||
@@ -4317,6 +4365,7 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
strata::core::Verifier ver;
|
||||
strata::core::VerifyHits vh;
|
||||
vh.experimental_all_routed = kar_all_routed;
|
||||
vh.d_res = thits.d_res;
|
||||
vh.cache_base = thits.cache_base;
|
||||
vh.blob = thits.blob;
|
||||
@@ -5843,7 +5892,11 @@ int main(int argc, char** argv) {
|
||||
int64_t spec_pos = 0; // plan v0.3 P6: where the speculative loop starts (0 = not used)
|
||||
strata::prefill::Prefill prefill;
|
||||
#if defined(STRATA_NEXT_EXPERIMENTAL_KAR_EXPERTS)
|
||||
if (kar_prefill) prefill.set_experimental_experts(&strata::kar::ExpertMiss::dispatch, &kar_expert_miss);
|
||||
if (kar_all_routed) {
|
||||
if (!prefill.set_experimental_all_routed(&strata::kar::ExpertMiss::dispatch, &kar_expert_miss, err)) {
|
||||
std::fprintf(stderr, "strata generate: %s\n", err.c_str()); return 2;
|
||||
}
|
||||
} else if (kar_prefill) prefill.set_experimental_experts(&strata::kar::ExpertMiss::dispatch, &kar_expert_miss);
|
||||
#endif
|
||||
double prefill_batched_ms = 0;
|
||||
std::FILE* final_r = o.dump_final_r.empty() ? nullptr : std::fopen(o.dump_final_r.c_str(), "wb");
|
||||
@@ -6169,7 +6222,7 @@ int main(int argc, char** argv) {
|
||||
// round emits (accepted drafts + 1) tokens. `commit` keeps the state of the tokens that were emitted.
|
||||
const bool ended = o.stop_eos && !produced.empty() &&
|
||||
std::find(o.eos_ids.begin(), o.eos_ids.end(), (int64_t) produced.back()) != o.eos_ids.end();
|
||||
if (spec_pos > 0 && (int64_t) produced.size() < o.max_new && !ended) {
|
||||
if ((spec_pos > 0 || kar_all_routed) && (int64_t) produced.size() < o.max_new && !ended) {
|
||||
std::vector<int64_t> oracle;
|
||||
if (!o.spec_oracle.empty()) {
|
||||
std::ifstream in(o.spec_oracle);
|
||||
@@ -6180,7 +6233,7 @@ int main(int argc, char** argv) {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
if (thits.d_res == nullptr) {
|
||||
if (thits.d_res == nullptr && !kar_all_routed) {
|
||||
std::fprintf(stderr, "strata generate: --spec needs the device residency table (--expert-profile, "
|
||||
"--expert-cache and the token graph)\n");
|
||||
return 2;
|
||||
@@ -6188,6 +6241,7 @@ int main(int argc, char** argv) {
|
||||
mem_mark("the head and the prompt path");
|
||||
strata::core::Verifier ver;
|
||||
strata::core::VerifyHits vh;
|
||||
vh.experimental_all_routed = kar_all_routed;
|
||||
vh.d_res = thits.d_res;
|
||||
vh.cache_base = thits.cache_base;
|
||||
vh.blob = thits.blob;
|
||||
@@ -6619,7 +6673,7 @@ int main(int argc, char** argv) {
|
||||
std::printf("%-24s wait-park %.3f drain %.3f re-park %.3f ms/token\n",
|
||||
" pool phases", wp / per, dr / per, rp / per);
|
||||
}
|
||||
std::printf("%-24s %lld blobs read\n", " expert blobs", (long long) srcp->reads());
|
||||
std::printf("%-24s %lld blobs read\n", " expert blobs", (long long) (srcp ? srcp->reads() : 0));
|
||||
for (int r = 0; r < 3; ++r) if (o.expert_cache_remote[(size_t) r] > 0)
|
||||
std::printf(" CUDA%d experts %lld routed entries computed\n",
|
||||
r + 1, (long long) remote_experts[(size_t) r].computed());
|
||||
|
||||
Reference in New Issue
Block a user