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

test(qwen36): verify each attention projection failure with poisoned output

ZacharyZcRf17038dce830
diff --git a/c/tests/qwen36_fake_cuda.h b/c/tests/qwen36_fake_cuda.h
index 03e9b01d..12980214 100644
--- a/c/tests/qwen36_fake_cuda.h
+++ b/c/tests/qwen36_fake_cuda.h
@@ -19,6 +19,7 @@
* sleeps here; NULL (the default) uploads instantly. */
#ifndef QWEN36_FAKE_CUDA_H
#define QWEN36_FAKE_CUDA_H
+#include <math.h>
#include <stdio.h>
#include <stdlib.h>
@@ -110,11 +111,14 @@ void coli_cuda_stats(int device, size_t *count, size_t *bytes) {
* device). Counted, never computed: the placement tests check WHERE work
* went; the arithmetic has its own oracle in the CUDA build. Parameters are
* unused on purpose (CFLAGS carry -Wno-unused-parameter). */
-static int fake_matmuls, fake_matmul_fail, fake_matmul_rows;
+static int fake_matmuls, fake_matmul_fail, fake_matmul_rows, fake_matmul_fail_at;
int coli_cuda_matmul(ColiCudaTensor **tensor, float *y, const float *x, const void *weights, const float *scales, int fmt, int S, int I, int O, int device, int gs) {
fake_matmuls++;
fake_matmul_rows = S;
- if (fake_matmul_fail) return 0;
+ if (fake_matmul_fail || fake_matmuls == fake_matmul_fail_at) {
+ for(int i=0;i<S*O;i++) y[i]=NAN;
+ return 0;
+ }
ColiCudaTensor *t = tensor ? *tensor : NULL;
if (fake_dense_compute && t && t->fmt == 1 && t->w && t->sc && t->I == I && t->O == O) {
const int8_t *q = (const int8_t *)t->w;
diff --git a/c/tests/test_qwen36_trunk_dense.c b/c/tests/test_qwen36_trunk_dense.c
index ef969576..77e380fa 100644
--- a/c/tests/test_qwen36_trunk_dense.c
+++ b/c/tests/test_qwen36_trunk_dense.c
@@ -176,16 +176,33 @@ int main(void) {
attention(&m, at, 1, x, S, 0, gpu);
ck(fake_matmuls == calls + 4 && fake_matmul_rows == S,
"prefill dispatches all four projections as batches");
- fake_matmul_fail = 1;
- attention(&m, at, 1, x, S, 0, fallback);
- fake_matmul_fail = 0;
- double gap = 0, scale = 1e-6;
- for (int i = 0; i < S * D; i++) {
- gap = fmax(gap, fabs((double)gpu[i] - cpu[i]));
- gap = fmax(gap, fabs((double)fallback[i] - cpu[i]));
- scale = fmax(scale, fabs(cpu[i]));
+ int handles[]={at->qth_q,at->qth_k,at->qth_v,at->qth_o};
+ for(int failure=0;failure<4;failure++){
+ for(int i=0;i<4;i++) G_dense[handles[i]-1].on=1;
+ calls=fake_matmuls;
+ fake_matmul_fail_at=calls+failure+1;
+ attention(&m,at,1,x,S,0,fallback);
+ fake_matmul_fail_at=0;
+ ck(fake_matmuls==calls+4,"each projection attempted once on first failure");
+ for(int i=0;i<4;i++)
+ ck(G_dense[handles[i]-1].on==(i!=failure),"only failed projection disabled");
+ for(int pass=0;pass<2;pass++){
+ double gap=0, scale=1e-6;
+ int finite=1;
+ for(int i=0;i<S*D;i++){
+ finite &= isfinite(cpu[i]) && isfinite(gpu[i]) && isfinite(fallback[i]);
+ gap=fmax(gap,fabs((double)gpu[i]-cpu[i]));
+ gap=fmax(gap,fabs((double)fallback[i]-cpu[i]));
+ scale=fmax(scale,fabs(cpu[i]));
+ }
+ ck(finite && gap/scale<1e-4,"poisoned GPU output replaced by finite CPU-equivalent output");
+ if(pass==0){
+ calls=fake_matmuls;
+ attention(&m,at,1,x,S,0,fallback);
+ ck(fake_matmuls==calls+3,"disabled handle stays on CPU; healthy projections stay on GPU");
+ }
+ }
}
- ck(gap / scale < 1e-4, "batch attention and failed-backend fallback agree with CPU");
free(x); free(m.K[1]); free(m.V[1]); free(m.K); free(m.V); free(m.attn_sc);
}