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

perf(deepseek-v41): drafting stays on, and the measurement that says so is cold

JustVugg026c0c482b87
diff --git a/c/deepseek_v41.c b/c/deepseek_v41.c
index a644aaf1..0b5b3b38 100644
--- a/c/deepseek_v41.c
+++ b/c/deepseek_v41.c
@@ -1895,15 +1895,20 @@ static int argmax(const float *values, int n);
static void spec_load(Model *m, int ecap) {
Cfg *c = &m->c;
Spec *sp = &m->spec;
- /* 60%, not 30%, and the number is measured rather than guessed. On a
- * 16-thread CPU box holding 68% of the experts, DeepSeek's own draft head
- * accepts 16 of 32 drafts on a 24-token turn -- respectable, and still a
- * net loss: 9 forwards instead of 24, but 114 s instead of 86, because a
- * six-row verify costs more than the extra tokens it buys (attention +40%,
- * expert reads +17%). That is the same break-even colibri.c measured for
- * MTP on GLM-5.2, where 90% acceptance gains 22% and 19% loses 25%, with
- * the crossing around half. Half is where this lands, so half must pause.
- * Above 60% the batch pays for itself; below it the guard stops paying. */
+ /* 60%, and what it buys is not what I expected. The three cold runs:
+ *
+ * drafts off 24 forwards 116.6 s
+ * drafts on, guard at 60 16 forwards 99.3 s
+ * drafts on, guard disabled 9 forwards 111.5 s
+ *
+ * Speculating pays, and so does stopping. Fewer forwards is not less time:
+ * the early rounds batch six positions through a cold cache and win, the
+ * later ones pay six times the per-row attention for a cache that is now
+ * warm and would have served single tokens cheaply. The guard fires at 53%
+ * acceptance and turns 111 s into 99. It is not really measuring
+ * acceptance, it is measuring the moment batching stops being free -- but
+ * acceptance is the signal that moves with it, and it is the one we have.
+ */
sp->min_accept = getenv("V41_DSPARK_MINACC") ? atoi(getenv("V41_DSPARK_MINACC")) : 60;
/* how many of the drafted tokens to put in front of the main model. The head always
* writes its whole block; verifying fewer of them trades acceptance for a smaller
@@ -1933,27 +1938,19 @@ static void spec_load(Model *m, int ecap) {
}
}
if (c->n_mtp <= 0) return;
- /* Off unless asked for, and the reason is measured. On a 16-thread CPU box
- * holding 68% of the experts, the draft head accepts half its proposals and
- * still loses: 24 tokens took 114 s with it and 86 s without, because a
- * six-row verify amortizes the disk well (+17%) and the per-row dense work
- * not at all (+40% attention). Verifying six positions costs six times the
- * attention projections and buys 2.7 tokens.
+ /* On by default, and the default is a measurement. On a 16-thread CPU
+ * server holding 68% of the experts, from a dropped page cache, the same
+ * 24-token turn takes 116.6 s with no drafting and 99.3 s with it. The
+ * first comparison I ran said the opposite, and it was wrong: the two runs
+ * had not started from the same cache state, which on an engine that reads
+ * its weights from disk decides everything. Cold or it is not a number.
*
- * That balance flips where the per-row compute is cheap -- a GPU, or a
- * machine holding the whole expert set -- which is exactly where a user
- * would reach for it. So it is a switch and not a default, with the guard
- * still watching acceptance for whoever turns it on. */
+ * V41_DSPARK=0 turns the head off and does not load it. */
const char *flag = getenv("V41_DSPARK");
- if (!flag || !atoi(flag)) {
- fprintf(stderr, "[v41] DSpark drafts off; V41_DSPARK=1 turns them on "
- "(worth it when the experts are resident)\n");
+ if (flag && !atoi(flag)) {
+ fprintf(stderr, "[v41] DSpark drafts off (V41_DSPARK=0)\n");
return;
}
- /* A checkpoint can declare the head in its config and still not ship it -- the
- * vendor's own converter drops the tied embed and head, and a partial download has
- * the same shape. Refusing to start over a missing draft head would be absurd, so
- * say so once and decode without it. */
if (!st_find(&m->S, "mtp.0.attn.wq_a.weight")) {
fprintf(stderr, "[v41] no DSpark head in this checkpoint: drafts off\n");
return;
diff --git a/c/tests/test_dsv41_dspark_serve.py b/c/tests/test_dsv41_dspark_serve.py
index 0d9fc9d0..c1430e4f 100644
--- a/c/tests/test_dsv41_dspark_serve.py
+++ b/c/tests/test_dsv41_dspark_serve.py
@@ -45,7 +45,10 @@ def has_draft_head():
return False
text = json.loads((FIXTURE / "config.json").read_text())
text = text.get("text_config", text)
- return int(text.get("n_mtp_layers", 0)) > 0
+ # dspark_block_size, not n_mtp_layers: the released checkpoint declares the
+ # first and omits the second, and the fixture now matches it. The engine
+ # counts the stages by probing the shards for the same reason.
+ return int(text.get("dspark_block_size", 0)) > 0
def completion(drafts):
diff --git a/docs/ENVIRONMENT.md b/docs/ENVIRONMENT.md
index 744d0035..a87b1e0c 100644
--- a/docs/ENVIRONMENT.md
+++ b/docs/ENVIRONMENT.md
@@ -497,7 +497,7 @@ COLI_TEMP=0 COLI_METAL=1 DIRECT=1 COLI_NO_OMP_TUNE=1 PIPE=1 PIPE_WORKERS=6 MTP=0
| `V41_INDEX_OWNER` | unset | DeepSeek V4.1: score each layer against its OWN index keys instead of the last published cache. The default reproduces the released inference code; this changes the model's behaviour, see docs/deepseek-v41.md. |
| `V41_MAX_IMAGE_TOKENS` | the checkpoint's `max_image_tokens` | DeepSeek V4.1: ceiling on what one image costs in prompt tokens. |
| `V41_TRACE` | unset | DeepSeek V4.1: print per-sublayer checksums, matching tools/dsv41_ref.py's, to locate a divergence by diffing two columns. `2` follows the first row of a speculative step rather than the last. |
-| `V41_DSPARK` | off | DeepSeek V4.1: `1` loads the DSpark draft head. Drafts never change what a turn produces, only how many forwards it takes; measured a net loss on CPU at 68% expert residency (9 forwards instead of 24, but 114 s instead of 86) and a win where per-row compute is cheap. |
+| `V41_DSPARK` | on when the checkpoint carries the head | DeepSeek V4.1: `0` disables the DSpark draft head, which is then not loaded. Drafts never change what a turn produces, only how many forwards it takes: measured +17% on the real checkpoint from a cold cache (24 tokens in 99.3 s against 116.6). |
| `V41_DSPARK_MAX` | the checkpoint's `dspark_block_size` | DeepSeek V4.1: how many drafted tokens go in front of the main model per round. Fewer costs less when a round is rejected and caps the win when it is not. |
| `V41_DSPARK_MINACC` | 60 | DeepSeek V4.1: percent of drafts that must be accepted over a window of ten before drafting pauses for 64 tokens. 60 is the measured break-even. |
| `V41_SPEC_FORCE` | unset | DeepSeek V4.1, oracle mode only: draft the reference's own tokens (`1`), corrupt the last one (`2`), or keep the head's (`3`), so the verification path runs on a fixture whose draft head is random noise. |
diff --git a/docs/deepseek-v41.md b/docs/deepseek-v41.md
index d401cb68..8fd983a8 100644
--- a/docs/deepseek-v41.md
+++ b/docs/deepseek-v41.md
@@ -95,28 +95,34 @@ the oracle drafts the reference's own next tokens (`1`), or corrupts the last of
so a round is rejected part way (`2`), or keeps the head's own (`3`); all three have to
reproduce the reference token for token, and CI runs them.
-Drafting is **off unless you ask for it**, and the reason is a measurement rather
-than caution. On a 16-thread CPU server holding 68% of the experts, DeepSeek's own
-draft head accepts half of what it proposes, which is a respectable rate, and still
-loses:
-
-| | forwards for 24 tokens | wall |
-|---|---|---|
-| `V41_DSPARK=1` | 9 | 114 s |
-| off | 24 | 86 s |
-
-A six-row verify amortizes the disk almost perfectly, expert reads up 17% for six
-positions, and the per-row dense work not at all, attention up 40%. Six positions
-cost six times the attention projections and buy 2.7 tokens. That balance flips
-where per-row compute is cheap: a GPU, or a machine holding the whole expert set,
-which is exactly where someone would reach for it.
-
-So it is a switch. `V41_DSPARK=1` turns it on, and the guard still watches: a round
-that is rejected has still read its stages' experts, so acceptance is measured over
-ten proposals and the drafts pause for 64 tokens when it falls under
-`V41_DSPARK_MINACC`, whose default of 60% is where the measurement above puts the
-break-even. That is the same crossing colibri.c measured for MTP on GLM-5.2, where
-90% acceptance gains 22% and 19% loses 25%.
+Drafting is on, and the default is a measurement. Three runs of the same
+24-token turn on a 16-thread CPU server holding 68% of the experts, each from a
+dropped page cache:
+
+| | forwards | wall | tok/s |
+|---|---|---|---|
+| drafts off | 24 | 116.6 s | 0.206 |
+| drafts on, guard at 60% | 16 | **99.3 s** | **0.242** |
+| drafts on, guard disabled | 9 | 111.5 s | 0.215 |
+
+Two things in that table are worth more than the 17% it shows.
+
+The first is that **stopping pays as much as starting**. Nine forwards is fewer
+than sixteen and slower: the early rounds push six positions through a cold
+cache and win, the later ones pay six times the per-row attention for a cache
+that is now warm and would have served single tokens cheaply. The acceptance
+guard fires at 53% and turns 111 s into 99. It is not really measuring
+acceptance, it is measuring the moment batching stops being free, and
+acceptance is the signal that moves with it.
+
+The second is that the first comparison I ran said the opposite, that drafting
+cost 32%. It was wrong, because the two runs had not started from the same
+cache state. On an engine that reads its weights from disk, a warm page cache
+is worth more than any optimization in this file. Cold, or it is not a number.
+
+`V41_DSPARK=0` turns the head off entirely and it is then not even loaded;
+`V41_DSPARK_MINACC` moves the guard, whose default of 60% is where these runs
+put it.
## The index-key slot, and why the default is the odd one
@@ -148,7 +154,7 @@ default cannot be "tidied" by accident.
| `V41_INDEX_OWNER` | unset | each layer scores against its own owner's index keys (see above). Changes the model's behaviour. |
| `V41_MAX_IMAGE_TOKENS` | the checkpoint's `max_image_tokens` | a ceiling on what one image costs in prompt tokens. |
| `V41_TRACE` | unset | print a checksum of the tensors the reference prints too, for locating a divergence by diffing two columns. `2` follows the first row of a speculative step instead of the last, which is the row a sequential decode is comparable to. |
-| `V41_DSPARK` | off | `1` loads the DSpark draft head and verifies its blocks. A net loss on a CPU box at 68% expert residency, a win where per-row compute is cheap; see above. |
+| `V41_DSPARK` | on when the checkpoint carries the head | `0` disables the draft head and does not load it. Measured at +17% on the real checkpoint, cold; see above. |
| `V41_DSPARK_MAX` | the checkpoint's `dspark_block_size` | how many of the drafted tokens are put in front of the main model. Fewer means a cheaper rejected round and a lower ceiling on the win. |
| `V41_DSPARK_MINACC` | 60 | percent of drafts that must be accepted over a window of ten for drafting to continue; below it, drafts pause for 64 tokens. 60 is the measured break-even, not a guess. |
| `V41_SPEC_FORCE` | unset | oracle mode only: draft the reference's tokens (`1`), corrupt the last one (`2`), or use the head's own (`3`), to exercise the verification path on a fixture whose draft head is random. |