Skip to content

Run frontier MoE models on hardware you already own β€” pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦

C

olmoe: emit ROUTE_TRACE records (it announced the stream and wrote nothing)

Khalid Alnujaidi9b64a0af8bb6
diff --git a/c/olmoe.c b/c/olmoe.c
index 15083f78..1a05e5f6 100644
--- a/c/olmoe.c
+++ b/c/olmoe.c
@@ -18,6 +18,11 @@
* PILOT_EVICT_GUARD=0/1 : 1=enable LFRU prefetch eviction guard (default), 0=disable
* EXPERT_DROP=0/1: 1=fadvise(DONTNEED) after each expert read (old behaviour,
* for RAM-tight boxes); 0=keep pages cached (default)
+ * ROUTE_TRACE=<path>: log every routing decision (one line per moe call,
+ * position and layer: "<call> <row> <layer> <id>:<gate> ...")
+ * for offline analysis β€” tools/route_pairs.py,
+ * tools/route_coupling_report.py, tools/residency_sim.py.
+ * Measurement only: it cannot change which experts run.
* (expert queue is sorted by eid for SSD read locality)
*/
#define _GNU_SOURCE
@@ -899,11 +904,24 @@ static void moe(Model *m, Layer *l, int layer, float *x, int S, float *out) {
idx[kk] = best; val[kk] = pr[best];
}
if (c->norm_topk) { float sm=0; for(int kk=0;kk<K;kk++) sm+=val[kk]; for(int kk=0;kk<K;kk++) val[kk]/=sm; }
- /* IMPROVEMENT 2: update activation heatmap (before pinning activates) */
- if (!m->hot_pinned && m->freq) {
- uint32_t *freq_l = m->freq[layer];
- if (freq_l) for (int kk = 0; kk < K; kk++) if (idx[kk] >= 0) freq_l[idx[kk]]++;
- }
+ /* IMPROVEMENT 2 activation heatmap AND the ROUTE_TRACE stream, in one
+ * call. The counters were the only thing this engine recorded, and it
+ * recorded them HERE, before pinning activates β€” rt_count keeps that
+ * placement exactly. The trace is the half olmoe never had: it emits a
+ * line per (moe call, position, layer), so tools/route_pairs.py,
+ * route_coupling_report.py and residency_sim.py can read this engine's
+ * routing the same way they read GLM's. Until now olmoe announced
+ * ROUTE_TRACE at startup and then wrote a zero-byte file, because
+ * rt_init() opens the stream but nothing here ever called rt_trace():
+ * every consumer silently saw "no data" instead of an error.
+ *
+ * Only rt_route() is unconditional: it is a no-op for the counts when
+ * this engine has no counter row (the !hot_pinned guard below is
+ * unchanged) and a no-op for the trace when ROUTE_TRACE is unset, so a
+ * run without the variable behaves exactly as before. Measurement only,
+ * never the computation: idx[] and val[] are the ids and the
+ * post-normalisation gates the layer is about to apply. */
+ if (!m->hot_pinned) rt_route(layer, s, idx, val, K);
const float *xs = x + (int64_t)s*D;
for (int kk = 0; kk < K; kk++) {
Slot *e; expert_get(m, layer, idx[kk], &e);
@@ -932,6 +950,15 @@ static void moe(Model *m, Layer *l, int layer, float *x, int S, float *out) {
}
}
free(logits); free(g); free(u); free(hh);
+ /* Advance the trace call counter: once per moe() invocation, after all of
+ * its rows are traced. rt_trace_end() is a no-op when no stream is open.
+ *
+ * Outside the row loop on purpose. A batch of S == 0 traces no rows and
+ * must still consume a call id, or the ids stop being consecutive and
+ * residency_sim.py rejects the trace outright ("trace lacks advancing GLM
+ * call ids") rather than merging two forwards into one position space. GLM
+ * and glm53 advance theirs the same way. */
+ rt_trace_end();
}
static void layers_forward_range(Model *m, float *x, int S, int pos_base,
diff --git a/docs/experiments/cnre-offline-simulator.md b/docs/experiments/cnre-offline-simulator.md
index 2b357378..490c2867 100644
--- a/docs/experiments/cnre-offline-simulator.md
+++ b/docs/experiments/cnre-offline-simulator.md
@@ -31,9 +31,20 @@ model this existing overlap. Long-prefill felt-wait estimates are therefore
conservative and must be checked with lower `felt_fraction` sensitivity.
Kimi K3 traces are not currently safe input because that engine emits routes
-without advancing the trace call ID. Inkling and OLMoE initialize routing
-telemetry but do not currently emit route records. Their cache traversal also
-differs from GLM, so each needs an explicit engine profile before inclusion.
+without advancing the trace call ID. Inkling initializes routing telemetry but
+does not currently emit route records. Their cache traversal also differs from
+GLM, so each needs an explicit engine profile before inclusion.
+
+OLMoE **does** emit route records now. It announced `ROUTE_TRACE` at startup
+and wrote a zero-byte file for as long as the stream existed, because
+`rt_init()` opens the file but nothing in `moe()` ever called `rt_trace()` β€” a
+consumer saw "no data" rather than an error. `moe()` calls `rt_route()` per
+position and `rt_trace_end()` once per invocation, so the stream has one line
+per `(moe call, position, layer)` with `call` advancing once per layer per
+forward (16 calls per forward on OLMoE, rows `0..S-1` within each). It still
+needs an engine profile before this simulator accepts it, because its cache
+traversal is per-layer LRU with a `--cap` slot budget and its gates are raw
+softmax weights rather than a renormalised top-k (`norm_topk_prob=false`).
## Trace contract
@@ -240,7 +251,9 @@ first useful campaign needs:
3. Exact commit, model/container identity, DRAFT/sampling settings, cache state,
prefill chunk, and frozen `.coli_usage` snapshot.
4. Separate instrumentation fixes and engine profiles before Kimi K3, Inkling,
- or OLMoE data is interpreted by this simulator.
+ or OLMoE data is interpreted by this simulator. OLMoE's instrumentation fix
+ (it emitted no route records) has landed, so only its engine profile and a
+ trace campaign remain.
No server is required to run the simulator. A model-capable machine is needed
only to collect missing traces and later validate a policy end to end.