Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦
C
feat(kimi_k3): adopt the shared routing telemetry (#700)
Mario Gutiérrez116f65ab3b2e
diff --git a/c/Makefile b/c/Makefileindex b0c05cbd..74133d30 100644--- a/c/Makefile+++ b/c/Makefile@@ -464,7 +464,7 @@ olmoe$(EXE): olmoe.c st.h json.h compat.h sample.h tok.h tok_unicode.h tok_unicoinkling$(EXE): inkling.c st.h json.h compat.h $(INK_CUDA_OBJ)$(CC) $(CFLAGS) inkling.c $(INK_CUDA_OBJ) -o inkling$(EXE) $(LDFLAGS)-kimi_k3$(EXE): kimi_k3.c st.h json.h tok.h tok_unicode.h tok_unicode_o200k.h compat.h quant.h $(VK_OBJ) $(VK_SPV)+kimi_k3$(EXE): kimi_k3.c st.h json.h tok.h tok_unicode.h tok_unicode_o200k.h compat.h quant.h route_trace.h $(VK_OBJ) $(VK_SPV)$(CC) $(CFLAGS) kimi_k3.c $(VK_OBJ) -o kimi_k3$(EXE) $(LDFLAGS)# Use a baseline that matches the compiler target. macOS already targets adiff --git a/c/kimi_k3.c b/c/kimi_k3.cindex 24df36ef..904c0773 100644--- a/c/kimi_k3.c+++ b/c/kimi_k3.c@@ -80,6 +80,7 @@#include "st.h"#include "tok.h"#include "quant.h"+#include "route_trace.h" /* shared routing telemetry (#700) *//* ---------- config ---------- */typedef struct {@@ -1078,6 +1079,7 @@ static void moe_forward(Model *m, Layer *l, int li, const float *x, int C, float}}keff[t]=Kt;+ rt_route(li,t,idx,wsel,Kt); /* traces and counts, one call */}float *z=falloc((int64_t)C*LT), *u=falloc((int64_t)C*LT);float *gate=falloc(MI), *up=falloc(MI), *hz=falloc(LT);@@ -1597,6 +1599,15 @@ int main(int argc, char **argv){int nlayers=getenv("K3_LAYERS")?atoi(getenv("K3_LAYERS")):0;Model m;model_init(&m,snap,nlayers);+ rt_init("kimi_k3",m.c.n_layers,m.c.n_experts); /* counters, identity, ROUTE_TRACE */+ /* A layer with no counter row is a layer that cannot be credited: dense layers do not+ * route, and K3 has no MTP row. Without this a history record naming one of them is+ * silently absorbed and written back out. See docs/routing-telemetry.md. */+ for(int i=0;i<m.c.n_layers;i++) if(!m.L[i].sparse) rt_drop_row(i);+ rt_drop_row(m.c.n_layers);+ { const char *up=getenv("COLI_USAGE"); /* optional history to seed from */+ if(up&&*up){ int64_t h=rt_load(up);+ if(h>0) fprintf(stderr,"[USAGE] expert history: %lld selections (%s)\n",(long long)h,up); } }if(getenv("K3_TRACE")){m.trace=fopen(getenv("K3_TRACE"),"wb");if(!m.trace){ perror(getenv("K3_TRACE")); return 1; }@@ -1715,5 +1726,7 @@ int main(int argc, char **argv){fprintf(stderr,"[K3] time: attn %.1fs moe %.1fs (eload %.1fs) head %.1fs | RSS %.1f GB\n",m.t_attn,m.t_moe,m.t_eload,m.t_head,rss_gb());if(m.trace) fclose(m.trace);+ { const char *up=getenv("COLI_USAGE");+ if(up&&*up) rt_save(up,0); } /* same bytes as every other engine */return 0;}