Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦
C
fix(deepseek-v41): coli run, the chat's stderr, and a missing header dependency
JustVugg23f98cd9affe
diff --git a/c/Makefile b/c/Makefileindex c384421d..f21c59ba 100644--- a/c/Makefile+++ b/c/Makefile@@ -1049,7 +1049,7 @@ qwen36$(EXE): qwen36.c serve_poll.h cli_args.h qwen36_tier.h st.h json.h compat.# stream from the official checkpoint and quant.h's mxfp4 kernel reads them as they# are, so there is no conversion target here to go with it.deepseek_v41$(EXE): deepseek_v41.c cli_args.h st.h json.h tok.h tok_unicode.h compat.h quant.h \- hyper_connections.h serve_codec.h serve_poll.h .build-config+ sparse_attn.h hyper_connections.h serve_codec.h serve_poll.h .build-config$(CC) $(CFLAGS) deepseek_v41.c -o deepseek_v41$(EXE) $(LDFLAGS)qwen38$(EXE): qwen38.c cli_args.h qwen38_core.h qwen38_nfc.h qwen38_nfc_tables.h st.h json.h compat.h quant.h route_trace.h tok.h tok_unicode.h tok_unicode_o200k.h serve_codec.h edge_adapter_internal.h edge_adapters.h edge_runtime.h qwen38_vision.h segment_adapter_internal.h segment_adapters.h segment_runtime.hdiff --git a/c/deepseek_v41.c b/c/deepseek_v41.cindex 21513bca..6f1fcb90 100644--- a/c/deepseek_v41.c+++ b/c/deepseek_v41.c@@ -247,6 +247,15 @@ typedef struct { float *w; int64_t n; } WF; /* f32#define FP8_TILE 32+/* Per-turn accounting on stderr. Off by default because `coli chat` shows the+ * engine's stderr right next to the answer; V41_STATS=1 turns it on, which is+ * what the benchmarks and the server scripts use. */+static int v41_stats(void) {+ static int on = -1;+ if (on < 0) on = getenv("V41_STATS") ? atoi(getenv("V41_STATS")) : 0;+ return on;+}+/* V41_TRACE=1 prints a checksum of the tensors the reference prints too, so a* divergence is located by diffing two columns rather than by reading two forwards. */static int g_trace = 0;@@ -2967,10 +2976,11 @@ static int spec_ready(Spec *sp) {* half of what it needs to be. */if (sp->window_prop >= 10 &&sp->window_acc * 100 < sp->window_prop * (uint64_t)sp->min_accept) {- fprintf(stderr, "[v41] DSpark: %.0f%% of the last %llu drafts accepted (under "- "%d%%), pausing for 64 tokens\n",- 100.0 * (double)sp->window_acc / (double)sp->window_prop,- (unsigned long long)sp->window_prop, sp->min_accept);+ if (v41_stats())+ fprintf(stderr, "[v41] DSpark: %.0f%% of the last %llu drafts accepted "+ "(under %d%%), pausing for 64 tokens\n",+ 100.0 * (double)sp->window_acc / (double)sp->window_prop,+ (unsigned long long)sp->window_prop, sp->min_accept);sp->pause = 64;sp->window_prop = sp->window_acc = 0;return 0;@@ -3228,7 +3238,12 @@ static void serve_loop(Model *m, Tok *tokenizer, const char *snap) {}}free(batch); free(confidence);- if (m->engram.active) {+ /* Per-turn accounting goes to stderr, and stderr is what the user reads+ * their answer next to in `coli chat`: four lines a turn between the+ * question and the reply is noise, not instrumentation. Off unless asked+ * for, and the benches ask for it. */+ int stats = v41_stats();+ if (stats && m->engram.active) {/* What the n-gram memory actually cost this turn. Rows are 264* bytes and the traffic is Zipfian, so the useful question is not* how many rows were read but how many of them the cache already@@ -3245,7 +3260,7 @@ static void serve_loop(Model *m, Tok *tokenizer, const char *snap) {tab->misses * (double)(m->engram.head_dim + m->engram.head_dim / 32) / 1e6);}}- {+ if (stats) {/* Expert streaming, per turn: how many bytes the LRU had to fetch and* what rate the reads actually achieved. The rate is the number that* matters -- the device is worth several GB/s, so a figure far under@@ -3259,7 +3274,7 @@ static void serve_loop(Model *m, Tok *tokenizer, const char *snap) {seconds > 0 ? turn_bytes / 1e9 / seconds : 0.0,prefill_bytes / 1e6, prefill_disk, prefill_expert, prefill_wall);}- if (m->spec.active && m->spec.proposed > proposed0)+ if (stats && m->spec.active && m->spec.proposed > proposed0)fprintf(stderr, "[v41] DSpark: %llu of %llu drafts accepted this turn\n",(unsigned long long)(m->spec.accepted - accepted0),(unsigned long long)(m->spec.proposed - proposed0));diff --git a/c/family_registry.py b/c/family_registry.pyindex b7ef9ada..e13fb9b1 100644--- a/c/family_registry.py+++ b/c/family_registry.py@@ -1327,7 +1327,13 @@ FAMILIES = (# at the gateway rather than desync the wire.capabilities=FamilyCapabilities(True, False, False, True),has_gateway_adapter=True,- has_cli_adapter=True,+ # coli run stays unwired, for the reason qwen36 gives above and one more:+ # cmd_run dispatches per arch after this gate, and with no deepseek_v41+ # branch of its own the launcher would fall through to GLM's binary and+ # GLM's prompt template. The engine speaks the SERVE protocol and nothing+ # else, so a one-shot has nowhere to go but the gateway -- which is what+ # coli chat, coli serve and coli web already use.+ has_cli_adapter=False,),)diff --git a/c/tests/test_dsv41_dspark_serve.py b/c/tests/test_dsv41_dspark_serve.pyindex c1430e4f..710e6516 100644--- a/c/tests/test_dsv41_dspark_serve.py+++ b/c/tests/test_dsv41_dspark_serve.py@@ -54,7 +54,10 @@ def has_draft_head():def completion(drafts):"""One turn through the gateway, with drafting on or off. Returns (text, log)."""port = free_port()- environment = {**os.environ, "V41_DSPARK": "1" if drafts else "0"}+ # V41_STATS: the per-turn "N of M drafts accepted" line is what this test reads,+ # and it is off by default so that `coli chat` does not print accounting between+ # the question and the answer. A test that measures asks to be told.+ environment = {**os.environ, "V41_DSPARK": "1" if drafts else "0", "V41_STATS": "1"}process = subprocess.Popen([sys.executable, str(HERE / "coli"), "serve", "--model", str(FIXTURE),"--port", str(port), "--cap", "4"],diff --git a/docs/deepseek-v41.md b/docs/deepseek-v41.mdindex 63b2134e..8b396705 100644--- a/docs/deepseek-v41.md+++ b/docs/deepseek-v41.md@@ -240,6 +240,7 @@ and costs the contention. Anything that tries again has to start from that.| variable | default | what it does ||---|---|---|+| `V41_STATS` | off | per-turn accounting on stderr: the n-gram cache, the expert bytes and their rate, and how many drafts were accepted. Off by default because `coli chat` shows the engine's stderr next to the answer. || `V41_READ_DEPTH` | 8 | expert tensors read at once when a step misses the cache (see above). `1` restores the serial read the engine used to do, for an A/B. || `V41_ENGRAM_ROWS` | 65536 | rows of engram cache per table. The traffic is Zipfian: common 2-grams repeat constantly, so a small cache absorbs most of it. 65536 rows is 64 MB per table on the released head_dim. || `V41_INDEX_OWNER` | unset | each layer scores against its own owner's index keys (see above). Changes the model's behaviour. |