Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦
C
Merge pull request #726 from ZacharyZcR/fix/e8-cuda-real-shape
Vincenzo Fornaro3d4f8485055a
diff --cc c/backend_cuda.cuindex d674b1fa,1ecec638..0ccd1496--- a/c/backend_cuda.cu+++ b/c/backend_cuda.cu@@@ -1238,10 -993,23 +1280,24 @@@ extern "C" int coli_cuda_expert_group(Call_q4&=(g->fmt==2||g->fmt==4)&&(u->fmt==2||u->fmt==4)&&(d->fmt==2||d->fmt==4)&&!(g->gs&1)&&!(u->gs&1)&&!(d->gs&1); /* even gs: a packed byte never straddles groups */any_g4|=g->fmt==4||u->fmt==4||d->fmt==4;+ any_e8|=g->fmt==6||u->fmt==6||d->fmt==6;+ all_e8&=g->fmt==6&&u->fmt==6&&d->fmt==6;total+=rows[c]; if(rows[c]>max_rows) max_rows=rows[c];}+ /* Mixed E8 groups cannot use either homogeneous grouped kernel. */+ if(any_e8&&!all_e8){+ int off=0;+ for(int c=0;c<count;c++){+ if(!coli_cuda_expert_mlp(gates[c],ups[c],downs[c],+ y+(size_t)off*D,x+(size_t)off*D,rows[c])) return 0;+ off+=rows[c];+ }+ { std::lock_guard<std::mutex> lock(g_group_stats_mu);+ g_group_calls++; g_group_experts+=(uint64_t)count; g_group_rows+=(uint64_t)total; }+ return 1;+ }DeviceContext *ctx=find_ctx(device); if(!select_ctx(ctx)) return 0;+ if(!prepare_group_weights(ctx,gates,ups,downs,count,host)) return 0;size_t xb=(size_t)total*D*sizeof(float), ib=(size_t)total*I*sizeof(float);if(!reserve(&ctx->x,&ctx->x_cap,xb)||!reserve(&ctx->y,&ctx->y_cap,xb)||!reserve(&ctx->gate,&ctx->gate_cap,ib)||!reserve(&ctx->up,&ctx->up_cap,ib)||@@@ -1398,11 -1171,13 +1459,14 @@@ extern "C" int coli_cuda_expert_group_ig->fmt,u->fmt,d->fmt,rows[c],total,g->gs,u->gs,d->gs};all_s4&=g->fmt==2&&u->fmt==2&&d->fmt==2;+ any_e8|=g->fmt==6||u->fmt==6||d->fmt==6;+ all_e8&=g->fmt==6&&u->fmt==6&&d->fmt==6;total+=rows[c]; if(rows[c]>max_rows) max_rows=rows[c];}+ if(any_e8&&!all_e8) return 0;if(total>8) return 0; /* decode-scale only */DeviceContext *ctx=find_ctx(device); if(!ctx||ctx->group_pending||!select_ctx(ctx)) return 0;+ if(!prepare_group_weights(ctx,gates,ups,downs,count,host)) return 0;size_t xb=(size_t)total*D*sizeof(float), ib=(size_t)total*I*sizeof(float);if(!reserve(&ctx->x,&ctx->x_cap,xb)||!reserve(&ctx->y,&ctx->y_cap,xb)||!reserve(&ctx->gate,&ctx->gate_cap,ib)||!reserve(&ctx->up,&ctx->up_cap,ib)||