From 464ca57d7f534e42be881baf080efdff72784f36 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Sat, 3 Oct 2026 18:14:12 +0200 Subject: [PATCH] layer split trim: CUDA0 keeps every layer's router with --mmap-experts (PR #639 follow-up) The file tier's routing-aware prefetch (RouterLookahead) copies all layers' ffn_gate_inp.weight from CUDA0's arena. With CUDA0 trimmed to its own layers it found them missing and turned itself off ("the routers are not BF16 in the arena"). CUDA0 now keeps the routers (~2.5 MiB a layer) when --mmap-experts is on; the other stages and the runs without --mmap-experts trim as before. --- src/program/generate.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/program/generate.cpp b/src/program/generate.cpp index 30cb7957..b7bc46e0 100644 --- a/src/program/generate.cpp +++ b/src/program/generate.cpp @@ -1990,7 +1990,10 @@ int main(int argc, char** argv) { const std::set skip_base = skip; const bool stage_trim = multi_gpu && !split_auto && !split_at.empty() && !(std::getenv("STRATA_STAGE_TRIM") && std::string(std::getenv("STRATA_STAGE_TRIM")) == "0"); - auto add_foreign = [&](int64_t lb, int64_t le, std::set& out) { + // keep_routers: CUDA0 with --mmap-experts keeps every layer's router (ffn_gate_inp, ~2.5 MiB a layer) - the file + // tier's routing-aware prefetch (RouterLookahead, below) copies all of them from CUDA0's arena, and would + // otherwise turn itself off + auto add_foreign = [&](int64_t lb, int64_t le, std::set& out, bool keep_routers) { std::FILE* f = std::fopen((o.pack + "/index.txt").c_str(), "rb"); if (!f) return; char line[1024], name[256]; @@ -1998,13 +2001,14 @@ int main(int argc, char** argv) { if (line[0] == '#' || std::sscanf(line, "%255s", name) != 1) continue; const std::string n = name; if (n.rfind("blk.", 0) != 0 || n.find("ple") != std::string::npos) continue; + if (keep_routers && n.ends_with(".ffn_gate_inp.weight")) continue; const int64_t l = std::atoll(name + 4); if (l < lb || l >= le) out.insert(n); } std::fclose(f); }; if (stage_trim) { - add_foreign(0, split_at[0], skip); + add_foreign(0, split_at[0], skip, o.mmap_experts); strata::core::NativeDense::set_layer_range(0, (int) split_at[0]); std::fprintf(stderr, "strata generate: layer split: CUDA0 loads the dense weights of layers 0-%lld only\n", (long long) split_at[0] - 1); @@ -2332,7 +2336,7 @@ int main(int argc, char** argv) { uint64_t pool_s = pool_bytes; if (stage_trim) { const int64_t lb = split_at[i], le = i + 1 < split_at.size() ? split_at[i + 1] : g.n_layers; - add_foreign(lb, le, skip_s); + add_foreign(lb, le, skip_s, false); strata::core::NativeDense::set_layer_range((int) lb, (int) le); if (!strata::core::WeightTable::pool_bytes(o.pack, pool_s, err, &skip_s)) { std::fprintf(stderr, "strata generate: %s\n", err.c_str());