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(glm53): pin whole-expert mirror fallback

trigger2k2089eeb698e1dd
diff --git a/c/glm53.c b/c/glm53.c
index 175308c3..38024dcf 100644
--- a/c/glm53.c
+++ b/c/glm53.c
@@ -1588,13 +1588,7 @@ static void glm53_mirror_setup(GModel *m, const char *primary_dir) {
valid ? " (COLI_DISK_WEIGHTS)" : " (startup bandwidth probe)");
}
-static void expert_read(GModel *m, int layer, int eid, Slot *slot) {
- const ERef *ref = &m->eref[(size_t)layer * m->c.n_experts + eid];
- int metal_slot = 0;
-#ifdef COLI_METAL
- metal_slot = g_metal_ready;
-#endif
-
+static int glm53_expert_read_replica(GModel *m, const ERef *ref, int layer, int eid) {
int rep = glm53_expert_replica(layer, eid);
/* A routed expert is one logical object. A partial mirror is allowed, but
@@ -1603,12 +1597,21 @@ static void expert_read(GModel *m, int layer, int eid, Slot *slot) {
* drives. */
if (rep > 0) {
for (int p = 0; p < GLM53_EXPERT_PIECES; p++) {
- if (st_fd_rep(&m->S, ref->fd[p], rep) < 0) {
- rep = 0;
- break;
- }
+ if (st_fd_rep(&m->S, ref->fd[p], rep) < 0)
+ return 0;
}
}
+ return rep;
+}
+
+static void expert_read(GModel *m, int layer, int eid, Slot *slot) {
+ const ERef *ref = &m->eref[(size_t)layer * m->c.n_experts + eid];
+ int metal_slot = 0;
+#ifdef COLI_METAL
+ metal_slot = g_metal_ready;
+#endif
+
+ int rep = glm53_expert_read_replica(m, ref, layer, eid);
/* The batched Metal MoE uses resolve() on expert pointers.
* st_map_shard_range() may return a pointer inside an mmap rather than its
diff --git a/c/tests/test_glm53_mirror.py b/c/tests/test_glm53_mirror.py
index f5a058f8..2c617cc0 100644
--- a/c/tests/test_glm53_mirror.py
+++ b/c/tests/test_glm53_mirror.py
@@ -96,30 +96,27 @@ class GLM53MirrorRoutingTests(unittest.TestCase):
self.assertNotIn("(equal fallback)", SRC)
self.assertNotIn("using equal weights", SRC)
- def test_whole_expert_replica_preflight_precedes_mmap(self):
+ def test_whole_expert_replica_preflight_helper(self):
fn = re.search(
- r"static void expert_read\(.*?\n\}",
+ r"static int glm53_expert_read_replica\(.*?\n\}",
SRC,
flags=re.S,
)
self.assertIsNotNone(fn)
body = fn.group(0)
- preflight = body.find(
- "for (int p = 0; p < GLM53_EXPERT_PIECES; p++)"
+ self.assertIn(
+ "for (int p = 0; p < GLM53_EXPERT_PIECES; p++)",
+ body,
)
- replica_check = body.find(
- "st_fd_rep(&m->S, ref->fd[p], rep)"
+ self.assertRegex(
+ body,
+ r"if\s*\(\s*st_fd_rep\(&m->S,\s*ref->fd\[p\],\s*rep\)"
+ r"\s*<\s*0\s*\)\s*return\s+0\s*;",
)
- fallback = body.find("rep = 0;")
- mmap_call = body.find("st_map_shard_range")
+ self.assertRegex(body, r"return\s+rep\s*;")
- self.assertGreaterEqual(preflight, 0)
- self.assertGreater(replica_check, preflight)
- self.assertGreater(fallback, replica_check)
- self.assertGreater(mmap_call, fallback)
-
- def test_partial_replica_falls_back_whole_expert(self):
+ def test_expert_read_preflights_before_mmap(self):
fn = re.search(
r"static void expert_read\(.*?\n\}",
SRC,
@@ -128,12 +125,13 @@ class GLM53MirrorRoutingTests(unittest.TestCase):
self.assertIsNotNone(fn)
body = fn.group(0)
- expected = re.compile(
- r"if\s*\(\s*st_fd_rep\(&m->S,\s*ref->fd\[p\],\s*rep\)\s*<\s*0\s*\)"
- r"\s*\{\s*rep\s*=\s*0\s*;\s*break\s*;\s*\}",
- flags=re.S,
+ preflight = body.find(
+ "glm53_expert_read_replica(m, ref, layer, eid)"
)
- self.assertRegex(body, expected)
+ mmap_call = body.find("st_map_shard_range")
+
+ self.assertGreaterEqual(preflight, 0)
+ self.assertGreater(mmap_call, preflight)
def test_mmap_uses_selected_replica_fd(self):
fn = re.search(