Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦
C
kimi_k3, qwen38: EMAP and HITS, so the Brain tab exists on both
JustVugg7a8eec2f9bbb
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex acbc192a..343af3d2 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -522,6 +522,13 @@ jobs:exit 1figrep -qE "elements, expected|gated residual dimensions" qwen38-bad.log+ - name: Brain tab: EMAP after READY and STAT, HITS after every turn+ run: |+ cd c+ # the oracle fixture has no tokenizer; serve mode needs one+ python3 tools/make_edge_tiny_tokenizer.py --vocab-size "$(python3 -c 'import json;print(json.load(open("qwen38_tiny/config.json"))["vocab_size"])')" qwen38_tiny+ make qwen38 >/dev/null+ QWEN38_TINY=qwen38_tiny python3 -m unittest -v tests.test_qwen38_dashboardinkling-oracle:name: Inkling oracle (token-exact vs transformers)@@ -822,7 +829,7 @@ jobs:# rieseguiva un binario non strumentato. Uno di quei test era rosso da# settimane senza che nessuno potesse vederlo.- name: Build the engines those tests exercise- run: make -C c kimi_k3 inkling colibri olmoe+ run: make -C c kimi_k3 inkling colibri olmoe qwen38- name: Python test suiterun: cd c && python3 -m unittest discover -s tests -p 'test_*.py'diff --git a/c/Makefile b/c/Makefileindex 17f88907..df8808f7 100644--- a/c/Makefile+++ b/c/Makefile@@ -647,6 +647,9 @@ kimi-k3-tiny-check: kimi-k3-tiny-generate kimi_k3$(EXE)$(PYTHON) tests/test_kimi_k3_ckpt.py \--binary ./kimi_k3$(EXE) \--fixture ./kimi_k3_tiny+ $(PYTHON) tests/test_kimi_k3_dashboard.py \+ --binary ./kimi_k3$(EXE) \+ --fixture ./kimi_k3_tiny.PHONY: deepseek-v4 deepseek-v4-oracle deepseek-v4-tiny-generate \deepseek-v4-tiny-check deepseek-v4-cleandiff --git a/c/kimi_k3.c b/c/kimi_k3.cindex 8b7638ec..f3329441 100644--- a/c/kimi_k3.c+++ b/c/kimi_k3.c@@ -228,6 +228,7 @@ typedef struct {/* experts */ERef *eref; /* [n_layers][n_experts] (dense rows zeroed) */LCache *ecache;+ uint8_t **ehit; /* experts routed this turn, for HITS (dashboard Brain) */int64_t e_w1p, e_w1s, e_w2p, e_w2s, e_slot;uint64_t clock, hits, miss, ebytes;double t_attn, t_moe, t_eload, t_head;@@ -1508,6 +1509,16 @@ static uint64_t g_slot_index_probes;#else#define SLOT_INDEX_PROBE() ((void)0)#endif+/* One byte per expert: routed in this turn or not. The dashboard's Brain tab+ * reads it as the HITS bitmap after every turn (serve_hits), cleared there. */+static void ehit_mark(Model *m, int li, int eid){+ Cfg *c=&m->c;+ if(!m->ehit){+ m->ehit=calloc((size_t)c->n_layers,sizeof(uint8_t*));+ for(int i=0;i<c->n_layers;i++) m->ehit[i]=calloc((size_t)c->n_experts,1);+ }+ if(li>=0&&li<c->n_layers&&eid>=0&&eid<c->n_experts) m->ehit[li][eid]=1;+}static Slot *slot_indexed(Model *m, int li, int eid){LCache *lc=&m->ecache[li];if(eid<0||eid>=m->c.n_experts||!lc->slot_by_expert) return NULL;@@ -1786,6 +1797,7 @@ static void experts_apply_union(Model *m, int li, int nu, const int *uids,int nb=nu-base<LP_MAX?nu-base:LP_MAX;Slot *use[LP_MAX]; int missk[LP_MAX]; int qof[LP_MAX]; int nmiss=0;for(int j=0;j<nb;j++){+ ehit_mark(m,li,uids[base+j]);use[j]=slot_find(m,li,uids[base+j]); qof[j]=-1;if(!use[j]){ m->miss++; use[j]=&m->ws[nmiss]; qof[j]=nmiss; missk[nmiss++]=j; }}@@ -2868,6 +2880,44 @@ static void serve_tool(const char *id, const char *p, int n){coli_serve_write_tool(stdout,id,p,(size_t)n);}+/* ---------- dashboard protocol: EMAP / HITS ----------+ * Same stdout lines colibri.c emits for the web dashboard's Brain tab; the+ * gateway parses them, nothing else does. Rows are the sparse layers, columns+ * the experts. EMAP: one byte per expert as two hex digits, tier<<6 | heat+ * (tier 1 = resident in the layer cache, heat 0: this engine keeps no usage+ * counter). Printed once after READY and again after every turn, because+ * the cache fills as the turn runs. HITS: one bit per expert routed in the+ * turn, packed 8 per hex pair, printed after DONE next to PROF. */+static void serve_emap(Model *m){+ Cfg *c=&m->c; int E=c->n_experts, rows=0;+ for(int i=0;i<c->n_layers;i++) if(m->L[i].sparse) rows++;+ char *hex=malloc((size_t)rows*E*2+1); int w=0;+ for(int i=0;i<c->n_layers;i++){+ if(!m->L[i].sparse) continue;+ for(int e=0;e<E;e++){+ int b=(slot_indexed(m,i,e)?1:0)<<6;+ hex[w++]="0123456789abcdef"[b>>4]; hex[w++]="0123456789abcdef"[b&15];+ }+ }+ hex[w]=0;+ printf("EMAP %d %d %s\n",rows,E,hex); fflush(stdout); free(hex);+}+static void serve_hits(Model *m){+ Cfg *c=&m->c; int E=c->n_experts, rows=0;+ if(!m->ehit) ehit_mark(m,-1,-1); /* a turn that routed nothing still reports a bitmap: all zero */+ for(int i=0;i<c->n_layers;i++) if(m->L[i].sparse) rows++;+ int nb=(rows*E+7)/8; uint8_t *bm=calloc((size_t)nb,1); int bit=0;+ for(int i=0;i<c->n_layers;i++){+ if(!m->L[i].sparse) continue;+ for(int e=0;e<E;e++,bit++)+ if(m->ehit[i][e]){ bm[bit>>3]|=(uint8_t)(1<<(bit&7)); m->ehit[i][e]=0; }+ }+ char *hex=malloc((size_t)nb*2+1); int w=0;+ for(int b=0;b<nb;b++){ hex[w++]="0123456789abcdef"[bm[b]>>4]; hex[w++]="0123456789abcdef"[bm[b]&15]; }+ hex[w]=0;+ printf("HITS %d %d %s\n",rows,E,hex); fflush(stdout); free(hex); free(bm);+}+static int serve_one(Model *m, Tok *T, ServeReq *q){int cap=65536, *ids=malloc((size_t)cap*sizeof(int)), np=0;if(!ids){ coli_serve_write_error(stdout,q->id,"out of memory"); return 0; }@@ -2955,6 +3005,7 @@ static int serve_one(Model *m, Tok *T, ServeReq *q){int gen=0, limited=1, cancelled=0, xsup=0, xopen=0, xtl=0, xtool=0;char buf[512], xtag[320]; /* tool-call open tags carry attributes: call tool="..." index="..." (#1143) */double tg=now_s();+ int forwards=1; /* the prefill; decode steps are counted where they run */for(int s=0;s<q->max_tok&&!cancelled;s++){int tk=sample_tok(lo,m->c.vocab,q->temp,q->top_p);free(lo); lo=NULL;@@ -3003,7 +3054,7 @@ static int serve_one(Model *m, Tok *T, ServeReq *q){}if(cancelled){ limited=0; break; }if(eos){ limited=0; break; }- if(s+1<q->max_tok) lo=step_chunk(m,&tk,np+s,1);+ if(s+1<q->max_tok){ lo=step_chunk(m,&tk,np+s,1); forwards++; }}if(poll.fatal){ free(lo); free(ids); return -1; }free(lo); free(ids);@@ -3019,8 +3070,9 @@ static int serve_one(Model *m, Tok *T, ServeReq *q){if(done_bytes>0) fwrite(done_line,1,(size_t)done_bytes,stdout);double moe=m->t_moe-e0, disk=m->t_eload-d0;printf("PROF %.3f %d %d %.3f %.3f %.3f %.3f %.3f %d\n",- dt,np,gen,disk,0.0,moe>disk?moe-disk:moe,m->t_attn-a0,m->t_head-h0,gen+1);+ dt,np,gen,disk,0.0,moe>disk?moe-disk:moe,m->t_attn-a0,m->t_head-h0,forwards);fflush(stdout);+ serve_hits(m);#ifdef COLI_VULKANif(g_k3_vk){if(g_vk_up_auto)@@ -3043,11 +3095,12 @@ static void serve_loop(Model *m, Tok *T){* e' nato senza. */coli_serve_stdio_init();coli_serve_write_ready(stdout,rss_gb());+ serve_emap(m); /* after READY and STAT: the boot reader discards what precedes them */for(;;){ServeReq q={0}; int r;do r=serve_read_req(stdin,stdout,&q,NULL); while(r==0);if(r<0) return;- if(r==2){ int fatal=serve_one(m,T,&q); free(q.payload); if(fatal<0) return; }+ if(r==2){ int fatal=serve_one(m,T,&q); free(q.payload); if(fatal<0) return; serve_emap(m); }}}diff --git a/c/qwen38.c b/c/qwen38.cindex d7cdd67a..1e305d26 100644--- a/c/qwen38.c+++ b/c/qwen38.c@@ -1465,6 +1465,40 @@ static int q38_format_prof(char *out,size_t capacity,double wall_s,int prompt_toreturn count>=0&&(size_t)count<capacity?count:-1;}+/* ---------- dashboard protocol: EMAP / HITS ----------+ * Same stdout lines colibri.c emits for the web dashboard's Brain tab. Every+ * layer here is a MoE layer, so rows are all layers, columns the experts.+ * EMAP: one byte per expert as two hex digits, tier<<6 | heat (tier 1 =+ * resident in the layer cache; heat 0, no usage counter here). Printed after+ * READY and STAT, and again after every turn. HITS: one bit per expert routed+ * in the turn, packed 8 per hex pair, printed after DONE next to PROF. */+static void serve_emap(Model *m){+ const Cfg *c=&m->c; int E=c->experts, rows=c->layers;+ char *hex=(char*)malloc((size_t)rows*E*2+1); int w=0;+ for(int i=0;i<rows;i++){+ LCache *lc=&m->cache[i];+ for(int e=0;e<E;e++){+ int si=lc->by_expert?lc->by_expert[e]:-1;+ int b=(si>=0&&si<lc->n&&lc->slots[si].eid==e?1:0)<<6;+ hex[w++]="0123456789abcdef"[b>>4]; hex[w++]="0123456789abcdef"[b&15];+ }+ }+ hex[w]=0;+ printf("EMAP %d %d %s\n",rows,E,hex); fflush(stdout); free(hex);+}+static void serve_hits(Model *m){+ const Cfg *c=&m->c; int E=c->experts, rows=c->layers;+ if(!m->ehit)q38_ehit_mark(m,-1,-1); /* a turn that routed nothing still reports a bitmap: all zero */+ int nb=(rows*E+7)/8; uint8_t *bm=(uint8_t*)calloc((size_t)nb,1); int bit=0;+ for(int i=0;i<rows;i++)+ for(int e=0;e<E;e++,bit++)+ if(m->ehit[i][e]){ bm[bit>>3]|=(uint8_t)(1<<(bit&7)); m->ehit[i][e]=0; }+ char *hex=(char*)malloc((size_t)nb*2+1); int w=0;+ for(int b=0;b<nb;b++){ hex[w++]="0123456789abcdef"[bm[b]>>4]; hex[w++]="0123456789abcdef"[bm[b]&15]; }+ hex[w]=0;+ printf("HITS %d %d %s\n",rows,E,hex); fflush(stdout); free(hex); free(bm);+}+static int serve_one(Model *m, ServeReq *q){int *ids=NULL, np=0;encode_text_n(q->payload,(size_t)q->plen,&ids,&np); /* byte-counted prompt; qwen38 adds no BOS */@@ -1590,6 +1624,7 @@ static int serve_one(Model *m, ServeReq *q){if(profile_bytes>0)fwrite(profile,1,(size_t)profile_bytes,stdout);else fprintf(stderr,"[qwen38] internal error: PROF frame overflow\n");fflush(stdout);+ serve_hits(m);q38_tm_report_bank(&timers,"request");return input_eof?-1:0;}@@ -1606,6 +1641,7 @@ static void serve_loop(Model *m){fputs("\x01\x01READY\x01\x01\n",stdout);printf("STAT 0 0.00 0.0 %.2f\n",rss_gb());fflush(stdout);+ serve_emap(m); /* after READY and STAT: the boot reader discards what precedes them */for(;;){ServeReq q={0}; int r;do r=serve_read_req(stdin,stdout,&q,NULL); while(r!=2&&r>=0);@@ -1613,6 +1649,7 @@ static void serve_loop(Model *m){if(r==2){int status=serve_one(m,&q);free(q.payload);if(status<0){q38_prefix_cache_release(m);return;}+ serve_emap(m);}}}diff --git a/c/qwen38_core.h b/c/qwen38_core.hindex 4fbe7b2c..db3702fe 100644--- a/c/qwen38_core.h+++ b/c/qwen38_core.h@@ -114,6 +114,7 @@ typedef struct {GatedResidual final_gr;Layer *L;LCache *cache;+ uint8_t **ehit; /* experts routed this turn, for HITS (dashboard Brain) */Q38ExpertScaleCache *expert_scales;uint64_t clock, hits, miss;uint64_t expert_weight_reads, expert_scale_reads, expert_pair_reads;@@ -1238,7 +1239,19 @@ static void q38_load_expert(Model *m,int layer,int eid,Slot *s) {}}+/* One byte per expert: routed in this turn or not. The dashboard's Brain tab+ * reads it as the HITS bitmap after every turn (serve_hits in qwen38.c),+ * cleared there. Marked on both lookup paths, single and batched. */+static void q38_ehit_mark(Model *m,int layer,int eid) {+ const Cfg *c=&m->c;+ if(!m->ehit){+ m->ehit=(uint8_t**)calloc((size_t)c->layers,sizeof(uint8_t*));+ for(int i=0;i<c->layers;i++)m->ehit[i]=(uint8_t*)calloc((size_t)c->experts,1);+ }+ if(layer>=0&&layer<c->layers&&eid>=0&&eid<c->experts)m->ehit[layer][eid]=1;+}static Slot *q38_expert_get(Model *m,int layer,int eid) {+ q38_ehit_mark(m,layer,eid);LCache *lc=&m->cache[layer]; int si=lc->by_expert[eid];if(si>=0){m->hits++;lc->slots[si].used=++m->clock;return &lc->slots[si];}m->miss++; Slot *s;@@ -1271,6 +1284,7 @@ static int q38_expert_get_batch(Model *m,int layer,const int *experts,int count,for(int index=0;index<count;index++){int expert=experts[index];if(expert<0||expert>=m->c.experts)return 0;+ q38_ehit_mark(m,layer,expert);for(int previous=0;previous<index;previous++)if(experts[previous]==expert)return 0;int slot_index=cache->by_expert[expert];diff --git a/c/tests/test_kimi_k3_dashboard.py b/c/tests/test_kimi_k3_dashboard.pynew file mode 100644index 00000000..a675d53f--- /dev/null+++ b/c/tests/test_kimi_k3_dashboard.py@@ -0,0 +1,124 @@+#!/usr/bin/env python3+"""Brain tab on Kimi K3: EMAP after READY and STAT, HITS after every turn.++The dashboard reads two lines from the engine's stdout for its Brain tab:+EMAP (the grid: one row per sparse layer, one column per expert, two hex+digits per cell) and HITS (which experts the turn routed, one bit each,+packed 8 per hex pair, after DONE next to PROF). kimi_k3.c emitted neither,+so on Kimi K3 the tab was empty. Same harness as test_kimi_k3_ckpt.py: the+tiny fixture plus tests/tok_kimi_tiny.json as tokenizer.++Exit 0 when the lines arrive in the shape the gateway parses, 1 otherwise.+"""+import argparse+import json+import os+import shutil+import subprocess+import sys+import tempfile+from pathlib import Path++PROMPT = b"abcabcabc"+MAX_NEW = 3+++def read_until(process, kind, limit=400):+ lines = []+ for _ in range(limit):+ line = process.stdout.readline()+ if not line:+ raise RuntimeError("engine closed before " + kind)+ text = line.decode("latin-1").rstrip("\n")+ if text.split(" ", 1)[0] == "DATA":+ process.stdout.read(int(text.split()[2]))+ process.stdout.readline()+ continue+ lines.append(text)+ if text.startswith(kind):+ return lines+ raise RuntimeError(f"no {kind} within {limit} lines:\n" + "\n".join(lines[-10:]))+++def only(lines, kind):+ found = [l.split() for l in lines if l.startswith(kind + " ")]+ if len(found) != 1:+ raise AssertionError(f"expected exactly one {kind}, got {found}")+ return found[0]+++def check(binary, model, stderr_path):+ env = dict(os.environ, SERVE="1", SNAP=str(model))+ with open(stderr_path, "wb") as stderr_file:+ process = subprocess.Popen([str(binary)], stdin=subprocess.PIPE,+ stdout=subprocess.PIPE, stderr=stderr_file, env=env)+ try:+ read_until(process, "\x01\x01READY")+ boot = read_until(process, "EMAP")+ header = f"SUBMIT r1 0 {len(PROMPT)} {MAX_NEW} 0.0 1.0\n".encode()+ process.stdin.write(header + PROMPT + b"\n")+ process.stdin.flush()+ turn = read_until(process, "HITS")+ after = read_until(process, "EMAP")+ finally:+ process.stdin.close()+ process.wait(timeout=60)+ config = json.loads((model / "config.json").read_text())+ text_config = config.get("text_config", config)+ sparse = text_config["num_hidden_layers"] - text_config.get("first_k_dense_replace", 0)+ experts = text_config["num_experts"] if "num_experts" in text_config else text_config["n_routed_experts"]++ kinds = [l.split(" ", 1)[0] for l in boot]+ assert kinds.index("STAT") < kinds.index("EMAP"), "EMAP must follow READY and STAT"+ _, rows, cols, grid = only(boot, "EMAP")+ assert (int(rows), int(cols)) == (sparse, experts), f"EMAP {rows}x{cols}, config says {sparse}x{experts}"+ assert len(grid) == int(rows) * int(cols) * 2, "EMAP: two hex digits per cell"++ kinds = [l.split(" ", 1)[0] for l in turn]+ assert kinds.index("DONE") < kinds.index("HITS"), "HITS belongs after DONE, with PROF"+ _, hrows, hcols, hits = only(turn, "HITS")+ assert (hrows, hcols) == (rows, cols), "HITS must use EMAP's rows and columns"+ assert len(hits) == ((int(rows) * int(cols) + 7) // 8) * 2, "HITS: 8 experts per hex pair"+ assert int(hits, 16) != 0, "a 9-token prompt through the sparse layers routed no expert"++ prof = only(turn, "PROF")+ assert len(prof) == 10, "PROF keeps its ten fields"+ assert int(prof[3]) == MAX_NEW, "completion tokens"+ assert int(prof[9]) == MAX_NEW, "forwards: prefill plus one per token after the first"++ _, _, _, refreshed = only(after, "EMAP")+ assert int(refreshed, 16) != 0, "after a turn the cache holds experts: the refreshed grid shows them"+ return rows, cols, hits+++def main():+ parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])+ parser.add_argument("--binary", required=True)+ parser.add_argument("--fixture", required=True)+ parser.add_argument("--tokenizer",+ default=str(Path(__file__).parent / "tok_kimi_tiny.json"))+ args = parser.parse_args()+ base = Path(args.fixture)+ work = Path(tempfile.mkdtemp(prefix="kimi-k3-dash-"))+ try:+ model = work / "fixture"+ model.mkdir()+ shutil.copy(base / "config.json", model / "config.json")+ shutil.copy(base / "model.safetensors", model / "model.safetensors")+ shutil.copy(args.tokenizer, model / "tokenizer.json")+ try:+ rows, cols, hits = check(args.binary, model, work / "engine.stderr")+ except (AssertionError, RuntimeError) as failure:+ print(f"FAIL: {failure}")+ err = (work / "engine.stderr").read_text(errors="replace")+ if err:+ print(err[-2000:])+ return 1+ print(f"kimi_k3 dashboard: EMAP {rows}x{cols}, HITS {hits}")+ return 0+ finally:+ shutil.rmtree(work, ignore_errors=True)+++if __name__ == "__main__":+ sys.exit(main())diff --git a/c/tests/test_qwen38_dashboard.py b/c/tests/test_qwen38_dashboard.pynew file mode 100644index 00000000..29f83fcd--- /dev/null+++ b/c/tests/test_qwen38_dashboard.py@@ -0,0 +1,111 @@+"""The dashboard's Brain tab reads two lines from the engine's stdout: EMAP+(the grid, after READY and STAT and again after every turn) and HITS (which+experts the turn routed, after DONE next to PROF). qwen38.c emitted neither,+so on Qwen3.8 the tab was empty. This test drives the engine over stdio the+way the gateway does and reads the turn to its last line.++It needs a Qwen3.8 tiny fixture with a tokenizer.json and a built `qwen38`.+Set QWEN38_TINY to the fixture; without it the test is skipped with the+reason on the record. CI uses the oracle fixture and adds the byte tokenizer.+"""+import json+import os+import subprocess+import sys+import unittest+from pathlib import Path++HERE = Path(__file__).resolve().parent.parent+ENGINE = HERE / ("qwen38.exe" if sys.platform == "win32" else "qwen38")+FIXTURE = Path(os.environ.get("QWEN38_TINY", ""))+MAXTOK = 3+++def read_until(p, kind, limit=400):+ """Lines up to and including the first `kind`; DATA payloads consumed."""+ lines = []+ for _ in range(limit):+ line = p.stdout.readline()+ if not line:+ raise RuntimeError("engine closed: " + p.stderr.read().decode(errors="replace")[-2000:])+ text = line.decode("latin-1").rstrip("\n")+ if text.split(" ", 1)[0] == "DATA":+ p.stdout.read(int(text.split()[2]))+ p.stdout.readline()+ continue+ lines.append(text)+ if text.startswith(kind + " ") or text.startswith(kind):+ return lines+ raise RuntimeError(f"no {kind} within {limit} lines:\n" + "\n".join(lines[-10:]))+++def one_turn(prompt=b"abcabcabc"):+ """stdin stays open for the whole turn: the engine polls it per token and+ an EOF there is a cancel, which is what a `printf | ./qwen38` pipe gets."""+ env = dict(os.environ, SNAP=str(FIXTURE), SERVE="1")+ p = subprocess.Popen([str(ENGINE), "1", "8"], env=env, stdin=subprocess.PIPE,+ stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=0)+ try:+ read_until(p, "\x01\x01READY")+ boot = read_until(p, "EMAP")+ p.stdin.write(f"SUBMIT 7 0 {len(prompt)} {MAXTOK} 0 1\n".encode() + prompt + b"\n")+ p.stdin.flush()+ turn = read_until(p, "HITS")+ after = read_until(p, "EMAP")+ return boot, turn, after+ finally:+ p.stdin.close()+ try:+ p.wait(30)+ except subprocess.TimeoutExpired:+ p.kill()++[email protected](ENGINE.exists(), "qwen38 is not built")[email protected]((FIXTURE / "config.json").is_file() and (FIXTURE / "tokenizer.json").is_file(),+ "QWEN38_TINY not set to a Qwen3.8 fixture with a tokenizer")+class Qwen38DashboardTest(unittest.TestCase):+ @classmethod+ def setUpClass(cls):+ cls.boot, cls.turn, cls.after = one_turn()+ cls.config = json.loads((FIXTURE / "config.json").read_text())++ @staticmethod+ def only(lines, kind):+ found = [l.split() for l in lines if l.startswith(kind + " ")]+ assert len(found) == 1, f"expected exactly one {kind}: {found}"+ return found[0]++ def test_grid_after_ready_and_stat(self):+ """The boot reader consumes READY then STAT; EMAP must come after+ both, and is one row per layer (every layer is MoE here)."""+ kinds = [l.split(" ", 1)[0] for l in self.boot]+ self.assertLess(kinds.index("STAT"), kinds.index("EMAP"))+ _, rows, cols, hexs = self.only(self.boot, "EMAP")+ self.assertEqual(int(rows), self.config["num_hidden_layers"])+ self.assertEqual(int(cols), self.config["num_experts"])+ self.assertEqual(len(hexs), int(rows) * int(cols) * 2)++ def test_grid_refreshed_after_the_turn_shows_residents(self):+ """Tier bit 6: after a turn the cache holds experts, so the grid is no+ longer all zero (cap 1 keeps one per layer)."""+ _, _, _, hexs = self.only(self.after, "EMAP")+ self.assertNotEqual(int(hexs, 16), 0, "no expert resident after a turn")++ def test_hits_matches_the_grid(self):+ kinds = [l.split(" ", 1)[0] for l in self.turn]+ self.assertLess(kinds.index("DONE"), kinds.index("HITS"))+ _, rows, cols, hexs = self.only(self.turn, "HITS")+ _, erows, ecols, _ = self.only(self.boot, "EMAP")+ self.assertEqual((rows, cols), (erows, ecols))+ self.assertEqual(len(hexs), ((int(rows) * int(cols) + 7) // 8) * 2)+ self.assertNotEqual(int(hexs, 16), 0, "a 9-token prompt routed no expert at all")++ def test_prof_is_still_there(self):+ prof = self.only(self.turn, "PROF")+ self.assertEqual(len(prof), 10)+ self.assertEqual(int(prof[3]), MAXTOK)+++if __name__ == "__main__":+ unittest.main()