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.
This commit is contained in:
Niko1221 committed 2026-10-03 18:14:12 +02:00
1 parent d95805c61a
commit 464ca57d7f
1 file changed
+7 -3
+7 -3
View File
@@ -1990,7 +1990,10 @@ int main(int argc, char** argv) {
const std::set<std::string> 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<std::string>& 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<std::string>& 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());