Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦
C
docs(degrade-zero): per-layer drop reporting and env var docs (PR #906)
Kritika Garg37590cc358f1
diff --git a/c/colibri.c b/c/colibri.cindex 6f493dd0..11bbb3f2 100644--- a/c/colibri.c+++ b/c/colibri.c@@ -1207,12 +1207,13 @@ static int g_expert_budget=0; /* EXPERT_BUDGET=N -> cap distinct experts loaded* (arXiv 2602.16052): top-32 of 64 capture 93% routing weight. */static int64_t g_budget_dropped=0; /* total experts dropped by EXPERT_BUDGET across all layers */static int64_t g_budget_rescued=0; /* experts re-kept because a position would have been left with zero */-static int g_degrade_zero=0; /* DEGRADE_ZERO=1: zero-fill miss slots whose aggregate gate weight+static int g_degrade_zero=0; /* DEGRADE_ZERO=1: zero-fill miss slots whose per-position gate weight* is below DEGRADE_TAU instead of blocking on a demand-load.* Opt-in only; changes output. Decode-only (S<=4 guard in moe()). */static float g_degrade_tau=0.03f; /* DEGRADE_TAU=<f>: gate weight threshold (default 0.03).* Issue #865: tau=0.03 zeroes 21.8% of slots for +2.9% perplexity. */static int64_t g_degrade_dropped=0; /* cumulative miss slots zeroed by DEGRADE_ZERO across all layers */+static int64_t g_degrade_dropped_by_layer[512]; /* per-layer miss slots zeroed (for footer breakdown) *//* CACHE_ROUTE (paper 2412.00099 max-rank): opt-in only. Keep true top-J always;* fill remaining slots preferring pin∪LRU experts ranked within top-M (or mass ROUTE_P). */static int g_cache_route=0;@@ -4942,6 +4943,7 @@ static void moe(Model *m, Layer *l, int layer, float *x, int S, float *out, intfor(int j=0;j<nu;j++) if(!dg_keep[j]) dg_dropped++;if(dg_dropped){g_degrade_dropped+=dg_dropped;+ if(layer<512) g_degrade_dropped_by_layer[layer]+=dg_dropped;memset(seen,0,(size_t)E);for(int j=0;j<nu;j++) if(dg_keep[j]) seen[uniq[j]]=1;for(int s=0;s<S;s++){@@ -7601,8 +7603,22 @@ static void run_text(Model *m, const char *snap, const char *prompt, int ngen){printf(" | EXPERT_BUDGET=%d (dropped %lld experts, ~%.1f GB I/O saved)", g_expert_budget, (long long)g_budget_dropped, g_budget_dropped*18.9e6/1e9);if(g_budget_rescued) printf(" [%lld rescued: budget too tight, position would have had 0 routed experts]", (long long)g_budget_rescued);}- if(g_degrade_zero)- printf(" | DEGRADE_ZERO tau=%.3f (zeroed %lld miss slots)", g_degrade_tau, (long long)g_degrade_dropped);+ if(g_degrade_zero){+ printf(" | DEGRADE_ZERO tau=%.3f (zeroed %lld miss slots", g_degrade_tau, (long long)g_degrade_dropped);+ if(g_degrade_dropped>0){+ /* top-3 layers by drop count */+ int top[3]={-1,-1,-1}; int64_t tv[3]={0,0,0};+ for(int i=0;i<512;i++){+ int64_t v=g_degrade_dropped_by_layer[i]; if(!v) continue;+ if(v>tv[0]){tv[2]=tv[1];top[2]=top[1];tv[1]=tv[0];top[1]=top[0];tv[0]=v;top[0]=i;}+ else if(v>tv[1]){tv[2]=tv[1];top[2]=top[1];tv[1]=v;top[1]=i;}+ else if(v>tv[2]){tv[2]=v;top[2]=i;}+ }+ printf("; top layers:");+ for(int k=0;k<3&&top[k]>=0;k++) printf(" L%d:%lld",top[k],(long long)tv[k]);+ }+ printf(")");+ }printf("\n");printf("speculation: %.2f tokens/forward (%llu forwards per %llu tokens) | MTP acceptance %.0f%% (%llu/%llu)\n",m->n_fw?(double)m->n_emit/m->n_fw:1.0, (unsigned long long)m->n_fw, (unsigned long long)m->n_emit,diff --git a/docs/ENVIRONMENT.md b/docs/ENVIRONMENT.mdindex 3cceffb4..8c49a466 100644--- a/docs/ENVIRONMENT.md+++ b/docs/ENVIRONMENT.md@@ -268,6 +268,8 @@ These are for testing, benchmarking, or internal use — not part of the everyda| `COLI_CORPUS_MINACC` | `50` | Acceptance floor (percent) for the corpus source. Below it over a 24-proposal window the source pauses for 256 tokens, then re-arms — rejected drafts cost real time. || `EXPERT_BUDGET` | `0` (off) | Cap experts loaded per layer (MoE-Spec). **Quarantined:** silently forced to `0` unless `EXPERT_BUDGET_EXPERIMENTAL` is set — every tested value is either no faster or incoherent (issue #303). || `EXPERT_BUDGET_EXPERIMENTAL` | unset | Setting it (any value) allows `EXPERT_BUDGET>0` to actually take effect (expect garbage, #294). |+| `DEGRADE_ZERO` | `0` (off) | **Opt-in approximate mode:** miss slots with per-position gate weight < `DEGRADE_TAU` are zero-filled instead of triggering a blocking disk read. Decode-only (`S≤4`). Changes output — must be set explicitly. Measured on OLMoE-1B-7B: `tau=0.03` → +2.9% ppl, 21.8% slots zeroed; `tau=0.05` → +41% ppl. GLM-5.2 and Kimi K3 router contracts are unmeasured — treat `tau=0.03` as OLMoE-calibrated and tune per-model. `[PROF]` footer reports zeroed slot count and top-3 layers by drop share. See PR #906, issue #865. |+| `DEGRADE_TAU` | `0.03` | Gate weight threshold for `DEGRADE_ZERO` (clamped to `(0, 1]`). Compared per-position, post-`norm_topk`, pre-`routed_scale` — i.e. as a fraction of each position's routed mass. || `DSA` | on | Dynamic Sparse Attention indexer. `DSA=0` disables. || `DSA_FORCE` | `0` | Force the DSA path on. || `DSA_TOPK` | model value | Override the DSA index top-k (testing). |diff --git a/docs/tuning.md b/docs/tuning.mdindex 10312a0e..7b18beca 100644--- a/docs/tuning.md+++ b/docs/tuning.md@@ -150,6 +150,45 @@ COLI_CUDA=0` if you also want kernel-family/GPU independence. Acceptancepercentages are not comparable across engine versions under `--topp`([#163](https://github.com/JustVugg/colibri/issues/163) has the full story).+## Approximate mode: `DEGRADE_ZERO` (opt-in, OLMoE-calibrated)++`DEGRADE_ZERO=1` enables an opt-in degraded inference policy: when a prefetch+deadline is missed, experts whose per-position gate weight falls below+`DEGRADE_TAU` (default 0.03) are **zero-filled instead of loaded from disk**.+The slot contributes nothing to the layer output; the approximation is the+dropped mass, not a rescaled version of it (renorm is catastrophically worse —+see issue #865 for the measured A/B).++This reduces blocking disk reads on NVMe-bound workloads at the cost of a small+quality hit. Measured on OLMoE-1B-7B:++| `DEGRADE_TAU` | slots zeroed | ppl delta |+|---|---|---|+| 0.03 | ~22% | +2.9% |+| 0.05 | ~60% | +41% |++**These numbers are OLMoE-specific.** GLM-5.2 (`norm_topk=1`) and Kimi K3 have+different router contracts and expert counts — their operating points have not+been measured. Until they are, treat `tau=0.03` as a starting point and verify+quality on your model before relying on it.++The feature is decode-only (`S≤4` guard, same as `EXPERT_BUDGET`): dropping+experts during prefill corrupts the KV cache. A rescue rule ensures no token+position is left with zero routed experts. Resident (pinned or LRU-cached)+experts are never dropped regardless of weight.++The `[PROF]` footer reports the total zeroed slot count and the top-3 layers by+drop share when the flag is active, so a miscalibrated tau is visible rather+than silent.++```bash+DEGRADE_ZERO=1 DEGRADE_TAU=0.03 COLI_MODEL=/nvme/glm52_i4 ./coli chat+```++See [ENVIRONMENT.md](ENVIRONMENT.md) for the full variable reference and+[issue #865](https://github.com/JustVugg/colibri/issues/865) for the+measurement methodology.+## Conversations reopen warm`coli chat` persists the compressed MLA KV-cache to disk after every turn