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

fix(pilot): the prefetch worker outlives the Model it dereferences

JustVuggff5829c55d23
diff --git a/c/colibri.c b/c/colibri.c
index 8c75fc0e..fb69983c 100644
--- a/c/colibri.c
+++ b/c/colibri.c
@@ -11079,7 +11079,13 @@ int main(int argc, char **argv){
atexit(cluster_close_all);
}
#endif
- Model m; double t0=now_s(); model_init(&m,snap,cap,ebits,dbits);
+ /* static, not a stack local: the PILOT prefetch worker is detached and
+ * loops forever, and it keeps this address in the global pilot_m. A stack
+ * Model dies when main returns while that thread is still dereferencing
+ * it -- ASan: stack-use-after-return, READ of size 8, in a worker thread,
+ * with the run's tokens already correct (#1262). Static storage outlives
+ * every thread, so the pointer the worker holds stays valid. */
+ static Model m; double t0=now_s(); model_init(&m,snap,cap,ebits,dbits);
/* KV_TQ requires power-of-two row widths: both codecs rotate through a
* radix-2 FWHT, and coli_kvq_quant_row returns an inert radius 0 for any
* other width. On a model whose kv_lora/qk_rope are not powers of two that
diff --git a/c/olmoe.c b/c/olmoe.c
index fd5028d0..65500fdf 100644
--- a/c/olmoe.c
+++ b/c/olmoe.c
@@ -1493,7 +1493,13 @@ int main(int argc, char **argv) {
fprintf(stderr, "CTX must be 1..4096 (got %d)\n", ctx_cap);
return 1;
}
- Model m; model_init(&m, snap, cap, bits);
+ /* static, not a stack local: the PILOT prefetch worker is detached and
+ * loops forever, and it keeps this address in the global pilot_m. A stack
+ * Model dies when main returns while that thread is still dereferencing
+ * it -- ASan: stack-use-after-return, READ of size 8, in a worker thread,
+ * with the run's tokens already correct (#1262). Static storage outlives
+ * every thread, so the pointer the worker holds stays valid. */
+ static Model m; model_init(&m, snap, cap, bits);
m.max_t = ctx_cap;
m.K = calloc(m.c.n_layers, sizeof(float*)); m.V = calloc(m.c.n_layers, sizeof(float*));
for (int i = 0; i < m.c.n_layers; i++) {
@@ -1525,7 +1531,13 @@ int main(int argc, char **argv) {
fprintf(stderr, "CTX must be 1..4096 (got %d)\n", ctx_cap);
return 1;
}
- Model m; model_init(&m, snap, cap, bits);
+ /* static, not a stack local: the PILOT prefetch worker is detached and
+ * loops forever, and it keeps this address in the global pilot_m. A stack
+ * Model dies when main returns while that thread is still dereferencing
+ * it -- ASan: stack-use-after-return, READ of size 8, in a worker thread,
+ * with the run's tokens already correct (#1262). Static storage outlives
+ * every thread, so the pointer the worker holds stays valid. */
+ static Model m; model_init(&m, snap, cap, bits);
printf("resident weights loaded in %.1fs | RSS after load: %.2f GB\n", m.dense_load_s, rss_gb());
Tok T;
char tokpath[2048]; snprintf(tokpath, sizeof(tokpath), "%s/tokenizer.json", snap);
@@ -1551,7 +1563,13 @@ int main(int argc, char **argv) {
int np, nfull; int *prompt = read_int_array(ref,"prompt_ids",&np); int *full = read_int_array(ref,"full_ids",&nfull);
int n_new = nfull - np;
- Model m; model_init(&m, snap, cap, bits);
+ /* static, not a stack local: the PILOT prefetch worker is detached and
+ * loops forever, and it keeps this address in the global pilot_m. A stack
+ * Model dies when main returns while that thread is still dereferencing
+ * it -- ASan: stack-use-after-return, READ of size 8, in a worker thread,
+ * with the run's tokens already correct (#1262). Static storage outlives
+ * every thread, so the pointer the worker holds stays valid. */
+ static Model m; model_init(&m, snap, cap, bits);
printf("resident weights loaded in %.1fs | RSS after load: %.2f GB\n", m.dense_load_s, rss_gb());
if (getenv("PPL") && atoi(getenv("PPL")) == 1) { /* loss-meter mode: teacher-forced NLL */
diff --git a/c/qwen36.c b/c/qwen36.c
index 28b6e553..9307c731 100644
--- a/c/qwen36.c
+++ b/c/qwen36.c
@@ -2606,7 +2606,13 @@ int main(int argc, char **argv) {
if (getenv("ENC_DEBUG") && np <= 300) { fprintf(stderr, "[enc] prompt ids: "); for (int i=0;i<np;i++) fprintf(stderr, "%d ", prompt[i]); fprintf(stderr, "\n"); }
}
- Model m; model_init(&m, snap, cap, bits);
+ /* static, not a stack local: the PILOT prefetch worker is detached and
+ * loops forever, and it keeps this address in the global pilot_m. A stack
+ * Model dies when main returns while that thread is still dereferencing
+ * it -- ASan: stack-use-after-return, READ of size 8, in a worker thread,
+ * with the run's tokens already correct (#1262). Static storage outlives
+ * every thread, so the pointer the worker holds stays valid. */
+ static Model m; model_init(&m, snap, cap, bits);
g_expert_gs = m.c.expert_gs;
if (g_expert_gs) fprintf(stderr, "[qwen36] group-scaled experts: gs=%d\n", g_expert_gs);
fprintf(stderr, "resident weights loaded in %.1fs | RSS after load: %.2f GB\n", m.dense_load_s, rss_gb());