Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦
C
feat(glm53): add routing usage telemetry
trigger2k2064c9e269ab0a
diff --git a/c/Makefile b/c/Makefileindex 80e26e1d..d12c661a 100644--- a/c/Makefile+++ b/c/Makefile@@ -1124,7 +1124,7 @@ NOCUDA_LDFLAGS = $(filter-out -lcudart -lstdc++ -lcuda -L$(CUDA_HOME)/lib64 \# GLM-5.3-Flash: routed experts stream from the int4-gs64 container.# METAL=1 accelerates resident matrices and routed MoE; CPU remains fallback.-glm53$(EXE): glm53.c cli_args.h st.h json.h tok.h tok_unicode.h tok_unicode_o200k.h compat.h serve_poll.h quant.h hyper_connections.h delta_attention.h sparse_index.h vision_tower.h backend_metal.h backend_vulkan.h edge_adapter_internal.h edge_adapters.h edge_runtime.h segment_adapter_internal.h segment_adapters.h segment_runtime.h $(METAL_OBJ) $(VK_OBJ) $(VK_SPV)+glm53$(EXE): glm53.c cli_args.h st.h json.h tok.h tok_unicode.h tok_unicode_o200k.h compat.h serve_poll.h route_trace.h quant.h hyper_connections.h delta_attention.h sparse_index.h vision_tower.h backend_metal.h backend_vulkan.h edge_adapter_internal.h edge_adapters.h edge_runtime.h segment_adapter_internal.h segment_adapters.h segment_runtime.h $(METAL_OBJ) $(VK_OBJ) $(VK_SPV)$(CC) $(CFLAGS) glm53.c $(METAL_OBJ) $(VK_OBJ) -o glm53$(EXE) $(LDFLAGS)kimi_k3$(EXE): kimi_k3.c cli_args.h st.h json.h tok.h tok_unicode.h tok_unicode_o200k.h compat.h quant.h omp_tune.h route_trace.h kv_prefix.h serve_codec.h backend_cuda.h backend_metal.h backend_vulkan.h edge_adapters.h edge_runtime.h edge_tok_internal.h hybrid_split.h segment_adapter_internal.h segment_adapters.h segment_runtime.h $(CUDA_OBJ) $(VK_OBJ) $(VK_SPV) $(METAL_OBJ)diff --git a/c/glm53.c b/c/glm53.cindex 433478e1..3cec6c44 100644--- a/c/glm53.c+++ b/c/glm53.c@@ -88,6 +88,7 @@ static int g_vk_ready = 0;#endif#include "compat.h"#include "serve_poll.h" /* CANCEL a meta' turno (#1332) */+#include "route_trace.h"#include <time.h>#ifndef _WIN32#include <sys/resource.h>@@ -123,6 +124,30 @@ typedef struct {int video_token, video_start_token, video_end_token;} Cfg;+static char g_glm53_usage[2100];++/* Routing telemetry belongs to the standalone/serve lifecycle. Segment may+ * host multiple engines in one process, while route_trace.h owns one process-+ * global stream/counter set, so range-native Segment loads stay detached. */+static void glm53_telemetry_init(const char *snap, const Cfg *c) {+ rt_init("glm53", c->n_layers, c->n_experts);+ for (int i = 0; i < c->first_dense; i++) rt_drop_row(i);+ rt_drop_row(c->n_layers); /* inclusive extra row; no routed MTP here */++ const char *up = getenv("COLI_USAGE");+ if (up && *up) snprintf(g_glm53_usage, sizeof g_glm53_usage, "%s", up);+ else snprintf(g_glm53_usage, sizeof g_glm53_usage, "%s/.coli_usage", snap);++ int64_t history = rt_load(g_glm53_usage);+ if (history > 0)+ fprintf(stderr, "[USAGE] expert history: %lld selections (%s)\n",+ (long long)history, g_glm53_usage);+}++static void glm53_telemetry_save(void) {+ if (g_glm53_usage[0]) rt_save(g_glm53_usage, 0);+}+static double req_num(jval *object, const char *key) {jval *value = json_get(object, key);if (!value || value->t != J_NUM) {@@ -1477,7 +1502,12 @@ static void ffn_layer(GModel *m, const GLayer *l, int index, const float *x,}for (int k = 0; k < topk; k++)mine_w[k] = mine_w[k] / (total + 1e-20f) * c->routed_scale;++ /* Record the exact experts and post-normalisation gates applied by+ * this layer. The shared helper also bumps .coli_usage counters. */+ rt_route(index, t, mine, mine_w, topk);}+ rt_trace_end();free(score);/* --- secondo e terzo tempo, a blocchi che stanno in cache ---@@ -2987,6 +3017,7 @@ int main(int argc, char **argv) {GModel served;memset(&served, 0, sizeof(served));model_load(&served, snap);+ glm53_telemetry_init(snap, &served.c);Tok serve_tok;char tokenizer_path[1024];snprintf(tokenizer_path, sizeof(tokenizer_path), "%s/tokenizer.json", snap);@@ -2994,6 +3025,8 @@ int main(int argc, char **argv) {const char *batch = getenv("SERVE_BATCH");arm_stops(snap, &serve_tok, batch && atoi(batch));serve_loop(&served, &serve_tok);+ glm53_telemetry_save();+ rt_destroy();tok_free(&serve_tok);return 0;}@@ -3041,6 +3074,7 @@ int main(int argc, char **argv) {memset(&model, 0, sizeof(model)); /* contatori e puntatori opzionali */const double load_start = now_s();model_load(&model, dir);+ glm53_telemetry_init(dir, &model.c);const double load_seconds = now_s() - load_start;if (getenv("GLM53_VERBOSE")) cfg_report(&model.c);@@ -3146,6 +3180,8 @@ int main(int argc, char **argv) {#endiffree(logits);session_close(&model, session);+ glm53_telemetry_save();+ rt_destroy();free(vision);free(tokens);return 0;diff --git a/c/route_trace.h b/c/route_trace.hindex d566d0ca..be3bfa11 100644--- a/c/route_trace.h+++ b/c/route_trace.h@@ -60,7 +60,7 @@#define RT_IKU1_MAGIC 0x31554B49u /* "IKU1" — inkling.c's usage_save/pins_load *//* engines that write this format; the table exists so a mismatch names both sides */-static const char *rt_engine_names[] = { "glm_moe_dsa", "inkling", "olmoe", "kimi_k3", "deepseek_v4", "qwen38", NULL };+static const char *rt_engine_names[] = { "glm_moe_dsa", "inkling", "olmoe", "kimi_k3", "deepseek_v4", "qwen38", "glm53", NULL };static uint32_t rt_hash(const char *s){ /* FNV-1a 32, stable across builds */uint32_t h = 2166136261u;diff --git a/c/tests/test_glm53_telemetry.py b/c/tests/test_glm53_telemetry.pynew file mode 100644index 00000000..dd7ff729--- /dev/null+++ b/c/tests/test_glm53_telemetry.py@@ -0,0 +1,35 @@+import pathlib+import unittest++ROOT = pathlib.Path(__file__).resolve().parents[1]+GLM = (ROOT / "glm53.c").read_text()+TRACE = (ROOT / "route_trace.h").read_text()+++class Glm53RoutingTelemetryTest(unittest.TestCase):+ def test_shared_route_trace_wiring(self):+ self.assertIn('#include "route_trace.h"', GLM)+ self.assertIn('rt_init("glm53", c->n_layers, c->n_experts);', GLM)+ self.assertIn('rt_route(index, t, mine, mine_w, topk);', GLM)+ self.assertIn('rt_trace_end();', GLM)++ def test_rows_and_usage_lifecycle(self):+ self.assertIn('for (int i = 0; i < c->first_dense; i++) rt_drop_row(i);', GLM)+ self.assertIn('rt_drop_row(c->n_layers);', GLM)+ self.assertIn('getenv("COLI_USAGE")', GLM)+ self.assertIn('rt_load(g_glm53_usage)', GLM)+ self.assertIn('rt_save(g_glm53_usage, 0)', GLM)++ def test_engine_identity_registered(self):+ self.assertIn('"glm53"', TRACE)++ def test_segment_open_does_not_attach_global_telemetry(self):+ start = GLM.index('static int glm53_segment_engine_open(')+ end = GLM.index('static void glm53_segment_engine_destroy(', start)+ segment_open = GLM[start:end]+ self.assertNotIn('glm53_telemetry_init', segment_open)+ self.assertNotIn('rt_init(', segment_open)+++if __name__ == '__main__':+ unittest.main()diff --git a/docs/routing-telemetry.md b/docs/routing-telemetry.mdindex 7b0ff661..ab9edd26 100644--- a/docs/routing-telemetry.md+++ b/docs/routing-telemetry.md@@ -6,9 +6,9 @@ the header both are implemented in. Background and design discussion in## Why one header-Six of colibrì's seven engines use this header: `colibri.c` (GLM-5.2),-`kimi_k3.c`, `inkling.c`, `olmoe.c`, `deepseek_v4.c`, and `qwen38.c`.-Qwen3.6 is the one existing exception. The learning cache described in+Seven of colibrì's eight engines use this header: `colibri.c` (GLM-5.2),+`kimi_k3.c`, `inkling.c`, `olmoe.c`, `deepseek_v4.c`, `qwen38.c`, and+`glm53.c`. Qwen3.6 is the one existing exception. The learning cache described in[tuning.md](tuning.md) is only as good as the history it reads. Before`route_trace.h`, that history was per-engine: `colibri.c` wrote sparse text,`inkling.c` wrote a dense binary block with an `IKU1` magic, and the other