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(cuda): reject initialization of an active Qwen tier

ZacharyZcRcba5f3134447
diff --git a/c/qwen36_tier.c b/c/qwen36_tier.c
index b7ac14ed..94e1ab9b 100644
--- a/c/qwen36_tier.c
+++ b/c/qwen36_tier.c
@@ -491,6 +491,7 @@ static const float *G_fp8_lut;
static int G_upload_sync; /* QT_UPLOAD_SYNC=1: qt_issue waits for in-flight uploads first (tests) */
int qt_init_fp8(int nl, int ne, int D, int Ih, int cap, int topk, const float *e4m3_lut){
+ if(G.on) return 0;
G_fp8_stream = 1; G_fp8_lut = e4m3_lut;
int ok = qt_init(nl, ne, D, Ih, cap, topk, 0, 0);
if(!ok) G_fp8_stream = 0;
@@ -517,6 +518,7 @@ static size_t dev_alloc_footprint(size_t bytes){
int qt_init(int nl, int ne, int D, int Ih, int cap, int topk, int expert_gs,
int expert_is_int4){
+ if(G.on) return 0;
const char *e=getenv("COLI_CUDA");
if(!(e && *e=='1')) return 0;
if(cap != ne && !G_fp8_stream){
diff --git a/c/qwen36_tier.h b/c/qwen36_tier.h
index 228288d6..0e67c17d 100644
--- a/c/qwen36_tier.h
+++ b/c/qwen36_tier.h
@@ -92,6 +92,8 @@ int qt_dense_count(void);
* the tier copies what it uploads inside the qt_note call and keeps no
* pointer into the engine's slot. e4m3_lut is quant.h's E4M3_LUT, published
* to the backend so fmt=8 uploads are accepted. */
+/* Init returns 0 without changing an active tier. Shut down before reinit;
+ * callers must serialize init/shutdown with new work. */
int qt_init_fp8(int n_layers, int n_experts, int hidden, int inter,
int cap_experts_per_layer, int topk, const float *e4m3_lut);
int qt_init(int n_layers, int n_experts, int hidden, int inter,
diff --git a/c/tests/test_qwen36_tier_init_failure.c b/c/tests/test_qwen36_tier_init_failure.c
index 0d63b5b2..985ae01b 100644
--- a/c/tests/test_qwen36_tier_init_failure.c
+++ b/c/tests/test_qwen36_tier_init_failure.c
@@ -67,8 +67,34 @@ int main(void) {
failed=1;goto done;
}
}
+ fail_stage=0;
+ float lut[256]={0}, other_lut[256]={0};
+ for(int fp8=0;fp8<2;fp8++){
+ int rc=fp8 ? qt_init_fp8(1,2,64,32,2,1,lut) : qt_init(1,2,64,32,2,1,0,1);
+ if(!rc){failed=1;goto done;}
+ QSlot *slots=G.slot;
+ float *inputs=G.is_x;
+ pthread_t uploader_thread=G.th;
+ int allocations=live;
+ const float *table=G_fp8_lut;
+ if(qt_init(2,2,64,32,2,1,0,1) ||
+ qt_init_fp8(2,2,64,32,2,1,other_lut) ||
+ !G.on || G.nl!=1 || G.slot!=slots || G.is_x!=inputs ||
+ !pthread_equal(G.th,uploader_thread) || live!=allocations ||
+ G_fp8_stream!=fp8 || G_fp8_lut!=table){
+ fputs("active tier initialization corrupted live state\n",stderr);
+ failed=1;goto done;
+ }
+ qt_shutdown();
+ /* Until the separate shutdown PR lands, reclaim its retained host state. */
+ free(G.slot);G.slot=NULL;free(G.is_x);G.is_x=NULL;
+ free(G.heat0);G.heat0=NULL;free(G.fill_order);G.fill_order=NULL;
+ if(conds){pthread_cond_destroy(&G.cv);pthread_cond_destroy(&G.cv_take);}
+ if(mutexes) pthread_mutex_destroy(&G.mx);
+ if(live || mutexes || conds){failed=1;goto done;}
+ }
done:
remove(path);
- if(!failed) puts("tier init failure: ok (12 cases)");
+ if(!failed) puts("tier init failure: ok (12 failure cases and active int4/FP8 preservation)");
return failed;
}