diff --git a/c/glm.c b/c/glm.c index 28a32ad..8ea02ed 100644 --- a/c/glm.c +++ b/c/glm.c @@ -2419,9 +2419,11 @@ static void moe(Model *m, Layer *l, int layer, float *x, int S, float *out, int if(!seen[e]){ seen[e]=1; uniq[nu++]=e; } } /* EXPERT_BUDGET: cap distinct experts per layer to reduce disk I/O on cold/low-RAM - * hosts. Keep the highest-aggregate-gate-weight experts; drop the rest from idxs[] - * so they're never loaded. (MoE-Spec arXiv 2602.16052: top-32 of 64 capture 93% - * routing weight.) Complementary to TOPP (per-position) — this trims cross-position. */ + * hosts. MISS-AWARE: always keep cache hits (pin/LRU — they're free, no disk I/O), + * only drop from misses. From the misses, keep the highest-aggregate-gate-weight + * ones up to the budget; drop the rest from idxs[] so they're never loaded. + * (MoE-Spec arXiv 2602.16052: top-32 of 64 capture 93% routing weight.) + * Complementary to TOPP (per-position) — this trims cross-position. */ if(g_expert_budget>0 && nu>g_expert_budget){ /* compute aggregate gate weight per unique expert */ float *wsum=falloc(nu); for(int j=0;jpin[layer]; + for(int z=0;znpin[layer];z++) if(P[z].eid==eid){ found=1; break; } + if(!found){ ESlot *Sl=m->ecache[layer]; int nn=m->ecn[layer]; + for(int z=0;zbv){ bv=wsum[j]; best=j; } - if(best<0) break; keep[best]=1; nkeep++; - } + for(int j=0;jbv){ bv=wsum[j]; best=j; } + if(best<0) break; keep[best]=1; nkeep++; } /* build a lookup: for each expert id, is it kept? (reuse seen[]) */ memset(seen,0,(size_t)E); @@ -2463,7 +2477,7 @@ static void moe(Model *m, Layer *l, int layer, float *x, int S, float *out, int int nu2=0; for(int j=0;j