Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦
C
build: clear the gcc 13 warnings left in make check
Marcello Costagliola695c255bcc3a
diff --git a/c/colibri.c b/c/colibri.cindex d1779fed..5a76fa8a 100644--- a/c/colibri.c+++ b/c/colibri.c@@ -901,7 +901,9 @@ static double edisk_s(void){ return atomic_load_explicit(&g_edisk_ns,memory_orde* served that gets labeled cold overstates the cold class, the bucket this line exists to* size). */static uint32_t g_direct_heat_ticks=0;+#ifndef COLIBRI_NO_MAINstatic int g_direct_heat_explicit=0; /* 1 if COLI_DISKCLASS_WINDOW was set (skip the auto-derive) */+#endif#define DC_COLD 0#define DC_WARM 1static _Atomic uint64_t g_dc_n[2]; /* [DC_COLD]/[DC_WARM]: loads classified */@@ -3947,7 +3949,9 @@ static void qt_matvec_rows(const QT *t, int r0, int n, const float *x, float *y)}}static int g_absorb=-1;+#if defined(COLI_METAL) || !defined(COLIBRI_NO_MAIN)static int g_metal_prefill=0; /* default 0: S>4 prefill attention stays on the CPU (bit-exact). COLI_METAL_PREFILL=1 opts it onto the GPU (~4x, near-tie divergence — see docs/metal.md, #622) */+#endif/* KV8=1: cache latente Lc/Rc in fp8 e4m3 + scala f32 per riga (~4x meno RAM del f32).* CPU-only in this PR — sui percorsi CUDA/Metal che leggono righe f32 si spegne da* solo (guardie !g_kv8), e forza COLI_CUDA_PIPE=0 (il pipe-prefill legge righe f32).diff --git a/c/deepseek_v4.c b/c/deepseek_v4.cindex e2a8bf27..34ae9998 100644--- a/c/deepseek_v4.c+++ b/c/deepseek_v4.c@@ -1350,7 +1350,7 @@ static int build_runtime_plan(ColiV4Engine *engine,uint64_t maximum_layer = 0, dense_total = 0;for (int layer = 0; layer < config->num_hidden_layers; layer++) {ColiDeepSeekV4LayerPlan layer_plan;- ColiDeepSeekV4LayerStats stats;+ ColiDeepSeekV4LayerStats stats = {0};if (coli_v4_layer_plan(&layer_plan, config, layer,error, error_size) ||coli_v4_layer_validate(&layer_plan, index, &stats,diff --git a/c/kimi_k3.c b/c/kimi_k3.cindex 34ba89ef..db98c365 100644--- a/c/kimi_k3.c+++ b/c/kimi_k3.c@@ -188,7 +188,9 @@ typedef struct {/* ---------- routed-expert streaming (native MXFP4 from the HF shards) ---- */typedef struct { int fd[6]; int64_t off[6]; int contig; } ERef; /* w1p w1s w2p w2s w3p w3s */+#ifndef KIMI_K3_NO_MAINstatic char g_k3_usage[2100]; /* <snap>/.coli_usage, or COLI_USAGE */+#endiftypedef struct { int eid; uint8_t *buf, *base; uint64_t used; int pinned; } Slot;/* pinned: seeded from .coli_usage at startup and never evicted. The LRU adapts to* THIS session; the pin knows the history of every session before it. Capped atdiff --git a/c/st.h b/c/st.hindex 8ad5ffd3..fc65de28 100644--- a/c/st.h+++ b/c/st.h@@ -449,7 +449,9 @@ static const char *st_basename(const char *p) {static void st_index_load(st_index *ix, const char *dir) {if (ix->tried) return;ix->tried = 1;- char path[1200]; snprintf(path, sizeof(path), "%s/model.safetensors.index.json", dir);+ char path[1200];+ int written = snprintf(path, sizeof(path), "%s/model.safetensors.index.json", dir);+ if (written < 0 || (size_t)written >= sizeof(path)) return;FILE *f = fopen(path, "rb");if (!f) return;fseek(f, 0, SEEK_END); long size = ftell(f); fseek(f, 0, SEEK_SET);diff --git a/c/tests/test_st_missing.c b/c/tests/test_st_missing.cindex 5d2adc88..c53128c6 100644--- a/c/tests/test_st_missing.c+++ b/c/tests/test_st_missing.c@@ -82,6 +82,26 @@ int main(void) {/* and a present tensor still reads fine with the index around */{ shards S; memset(&S, 0, sizeof S); st_init(&S, D); float v[8]; CHECK(st_read_f32(&S, "a", v, 0) == 8); st_destroy(&S); }wipe(D);++ /* 5. an index path that does not fit the buffer is refused, not opened truncated:+ * with a 1193-char directory, "<dir>/model" is all snprintf would keep of the name */+ {+ char dir[1200] = "tmp_st_long", p[1300]; size_t n = strlen(dir);+ CHECK(mkdir(dir, 0755) == 0);+ while (n < 1193) {+ size_t k = 1193 - n - 1 > 200 ? 200 : 1193 - n - 1;+ dir[n++] = '/'; memset(dir + n, 'd', k); n += k; dir[n] = 0;+ CHECK(mkdir(dir, 0755) == 0);+ }+ snprintf(p, sizeof p, "%s/model", dir);+ FILE *f = fopen(p, "wb"); CHECK(f != NULL); fputs("{\"weight_map\":{\"a\":\"x\"}}", f); fclose(f);+ st_index ix; memset(&ix, 0, sizeof ix); st_index_load(&ix, dir);+ int refused = ix.root == NULL && ix.map == NULL;+ remove(p);+ for (char *s; (s = strrchr(dir, '/')) != NULL; *s = 0) rmdir(dir);+ rmdir(dir);+ CHECK(refused);+ }puts("st_die_missing diagnosis tests: ok");return 0;}