core: --expert-stats FILE, the routed experts every layer selects, from the heat engine's histograms

Which experts a served model actually uses, per layer, is what deciding how to spend an expert's
bits needs, and the core already has it: every routed layer's counts come back to a host bank once
a pass, and the heat engine drains the landed banks once a step, one step behind. --expert-stats
FILE credits the same rows to a host tally and writes it as JSON every 30 s and at shutdown,
through a temporary and a rename (place/xstats.h). No device work, no copy, no synchronisation;
where the heat engine is off (every expert in VRAM, a static plan) the drain runs for the tally
alone, and at shutdown the streams are drained and the banks still in the ring are credited.

Counts are filed by step kind: prefill (no decode rows), decode, mixed (one histogram cannot split
it) and draft, which is every routed layer past the trunk (an MTP or DSpark head; its bank holds
the step's last draft pass). Each rank files its passes' kinds when it issues them.

A histogram row is the rank's own experts from zero, so under expert parallelism (deepseek41) it
is the rank's slice. The map from a rank's index to the model's expert id comes from the container:
index e is the unit declared with group expert e, and the directory entry of that unit's weight
names the expert. An expert several ranks hold (a width slice each) is counted on the lowest; a
rank that counts nothing does not drain for the tally. Without directory ids the map falls back to
the indices (one rank, or every rank holding the model's count) or to rank order.

The file carries the model, the routed layers, each layer's expert count and top_k, tokens and
steps issued by kind, histograms, passes, observed tokens and selections per kind and layer, the
per-rank drain counters (lost, unmapped, unclassified), and counts[kind][layer][expert].
/server_info names the file. Router weights are not summed: they stay on the card.

Tests: xstats_test (the map, the tally's kinds and merge, the file); config_test lists the flag
and checks it is off until it names a file.
This commit is contained in:
baKon authored and StillDeadcode committed 2026-10-27 18:34:32 +01:00
1 parent fb8cb95b7e
commit 72a58d0c0c
10 files changed
+1164 -6

No files matched your search

+6
View File
@@ -293,6 +293,10 @@ static const Flag g_flags[] = {
" implementation is an oracle and a last resort, and falling back\n"
" to it is orders of magnitude of speed with nothing to say so." },
{ "--profile-ops", nullptr, "per-op device timing (see the caveat it prints)" },
{ "--expert-stats", "FILE", "count the routed experts every layer selects, apart for prefill, decode,\n"
" mixed steps and draft-head passes, and write the counts to FILE as\n"
" JSON every 30 s and at shutdown. From the routing histograms the core\n"
" already copies back: no device work, no synchronisation" },
{ "--live", nullptr, "the live view: cards, throughput, draft acceptance, the expert plane.\n"
" Redirected it prints one greppable key=value line instead" },
{ "-v", nullptr, "verbose" },
@@ -908,6 +912,7 @@ int config_parse(int argc, char** argv, Config* c) {
else if (S("--debug-placement")) c->debug_placement = true;
else if (S("--debug-accept-reference-kernels")) c->accept_reference_kernels = true;
else if (S("--profile-ops")) c->profile_ops = true;
else if (S("--expert-stats")) { if (!(v = need(i))) return RAD_E_INVAL; c->expert_stats = v; }
else if (S("--live")) c->live_view = true;
else {
RAD_ERR("unknown option '%s'", a.c_str());
@@ -1228,6 +1233,7 @@ const ShowRow kShow[] = {
{ "--debug-placement", [](const Config& c) { return onoff(c.debug_placement); } },
{ "--debug-accept-reference-kernels", [](const Config& c) { return onoff(c.accept_reference_kernels); } },
{ "--profile-ops", [](const Config& c) { return onoff(c.profile_ops); } },
{ "--expert-stats", [](const Config& c) { return or_none(c.expert_stats, "off"); } },
{ "--live", [](const Config& c) { return onoff(c.live_view); } },
{ "-v", [](const Config& c) { return onoff(c.given.count("-v") > 0); } },
{ "-vv", [](const Config& c) { return onoff(c.given.count("-vv") > 0); } },