Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦
C
fix(telemetry): honour USAGE_SAVE=0 in every engine
ZacharyZcR269440de8f19
diff --git a/c/inkling.c b/c/inkling.cindex 45c3f60d..a98d08c5 100644--- a/c/inkling.c+++ b/c/inkling.c@@ -1105,8 +1105,7 @@ static int usage_save(Model *m, const char *snap) {(void)m; /* the counters live in route_trace.h now */char up[2048];const char *env = getenv("PIN");- const char *sv = getenv("USAGE_SAVE");- if (sv && *sv == '0') return 0;+ /* USAGE_SAVE=0 is honoured inside rt_save itself (#1039) */if (env && (!strcmp(env, "off") || !strcmp(env, "0"))) return 0;if (env) snprintf(up, sizeof(up), "%s", env);else snprintf(up, sizeof(up), "%s/.coli_usage", snap);diff --git a/c/kimi_k3.c b/c/kimi_k3.cindex 7b29b7fb..470f7973 100644--- a/c/kimi_k3.c+++ b/c/kimi_k3.c@@ -2712,9 +2712,8 @@ int main(int argc, char **argv){* rates this engine runs at). */printf("TUNE decode: %d tokens in %.3fs\n", ntok, dt);if(m.trace) fclose(m.trace);- { const char *sv=getenv("USAGE_SAVE");- if(!(sv && atoi(sv)==0) && g_k3_usage[0])- rt_save(g_k3_usage,0); } /* same bytes as every other engine */+ if(g_k3_usage[0]) /* USAGE_SAVE=0 honoured inside rt_save (#1039) */+ rt_save(g_k3_usage,0); /* same bytes as every other engine */if(g_k3_val_fp){ fflush(g_k3_val_fp); fclose(g_k3_val_fp); g_k3_val_fp=NULL; }if(g_k3_val_lfp){ fflush(g_k3_val_lfp); fclose(g_k3_val_lfp); g_k3_val_lfp=NULL; }#ifdef COLI_METALdiff --git a/c/route_trace.h b/c/route_trace.hindex 1e3cad8c..b6db7445 100644--- a/c/route_trace.h+++ b/c/route_trace.h@@ -321,6 +321,12 @@ static void rt_decay(void){static int rt_save(const char *path, int quiet){if(!rt_c || !path || !*path) return 0;+ /* USAGE_SAVE=0: read-only run — the history is loaded but never written back+ * (#1039: benchmark loops must not skew the very profile they are measuring).+ * Checked HERE so every engine honours the same switch with the same+ * truthiness; a requested skip is a success, not a save failure. */+ { const char *sv = getenv("USAGE_SAVE");+ if(sv && atoi(sv)==0) return 1; }rt_decay();int64_t tot = 0, nz = 0;for(int i = 0; i <= rt_nl; i++){diff --git a/c/tests/test_route_trace.c b/c/tests/test_route_trace.cindex 815132d2..f571d2ba 100644--- a/c/tests/test_route_trace.c+++ b/c/tests/test_route_trace.c@@ -301,9 +301,37 @@ int main(void){}}+ /* 8. USAGE_SAVE=0 is a read-only run (#1039): rt_save reports success but the+ * file must not be touched — a benchmark loop relies on the profile it measures+ * staying frozen. Enforced in rt_save itself so every engine gets it. */+ {+ rt_counts(3)[4] = 99;+#ifdef _WIN32+ _putenv_s("USAGE_SAVE", "0");+#else+ setenv("USAGE_SAVE", "0", 1);+#endif+ long before = fsize(TMP);+ check(rt_save(TMP, 1) == 1, "USAGE_SAVE=0: a requested skip is not a failure");+ check(fsize(TMP) == before, "USAGE_SAVE=0: the history file is not rewritten");+#ifdef _WIN32+ _putenv_s("USAGE_SAVE", "1");+#else+ setenv("USAGE_SAVE", "1", 1);+#endif+ check(rt_save(TMP, 1) == 1, "USAGE_SAVE=1: saving works again");+ check(fsize(TMP) != before, "USAGE_SAVE=1: the new counter reaches the file");+#ifdef _WIN32+ _putenv_s("USAGE_SAVE", "");+#else+ unsetenv("USAGE_SAVE");+#endif+ }+remove(TMP);if(g_nfails){ printf("route_trace: %d FAILED\n", g_nfails); return 1; }printf("route_trace: empty-history size, round trip, legacy read, refusals, "- "admitted-only totals, trusted read, dropped rows, old-reader contract ok\n");+ "admitted-only totals, trusted read, dropped rows, old-reader contract, "+ "USAGE_SAVE=0 read-only ok\n");return 0;}diff --git a/docs/ENVIRONMENT.md b/docs/ENVIRONMENT.mdindex 74f236e2..3cceffb4 100644--- a/docs/ENVIRONMENT.md+++ b/docs/ENVIRONMENT.md@@ -361,6 +361,8 @@ documented with defaults inthe ones you are most likely to set: `DSV4_CUDA` (GPU tier on/off),`COLI_CUDA_ATTN_BATCH=1`, `COLI_CUDA_MOE_BATCH=1`, `DSV4_CUDA_EXPERT_MIRRORS`,`V4_MOE_REFILL_GROUP`, `V4_PREFILL_SEGMENT`, `V4_PREFIX_CKPT*`, `CTX`.+`COLI_V4_SAVE_USAGE=0` is an engine-specific alias that disables only V4's+usage rewrite; the shared `USAGE_SAVE=0` covers this engine too.## OLMoE engine (`olmoe`)