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(v4): generate target-only oracle in CI

DrewZf8888ae50b48
diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml
index 10db7be5..fd050494 100644
--- a/.github/workflows/check.yml
+++ b/.github/workflows/check.yml
@@ -21,18 +21,18 @@ env:
jobs:
linux:
- name: Linux (colibri + tiny V4 oracle)
+ name: Linux
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- - name: make check (includes tiny V4 oracle)
+ - name: make check
run: make -C c check
windows:
# The job that would have caught #68/#137 pre-merge: native MinGW-w64
# (MSYS2/UCRT64), the exact toolchain the README's Windows port targets.
- name: Windows UCRT64 (colibri + tiny V4 oracle)
+ name: Windows UCRT64
runs-on: windows-latest
timeout-minutes: 20
defaults:
@@ -48,7 +48,7 @@ jobs:
make
mingw-w64-ucrt-x86_64-gcc
mingw-w64-ucrt-x86_64-python
- - name: make check (includes tiny V4 oracle)
+ - name: make check
run: make -C c check
# The Windows engine as this branch builds it. Small, and it makes an
@@ -59,6 +59,22 @@ jobs:
name: colibri-windows-exe
path: c/colibri.exe
+ v4-tiny:
+ name: Linux (generated tiny V4 target oracle)
+ runs-on: ubuntu-latest
+ timeout-minutes: 20
+ steps:
+ - uses: actions/checkout@v4
+ - uses: actions/setup-python@v5
+ with:
+ python-version: '3.13'
+ cache: pip
+ cache-dependency-path: c/tools/requirements-deepseek-v4-tiny.txt
+ - name: Install pinned tiny-fixture dependencies
+ run: python -m pip install -r c/tools/requirements-deepseek-v4-tiny.txt
+ - name: Generate fixture and run target oracle
+ run: make -C c deepseek-v4-tiny-check
+
macos:
# clang; libomp for the threaded path (Makefile falls back to
# single-threaded automatically if it's ever missing).
diff --git a/c/deepseek_v4_tiny/dspark/config.json b/c/deepseek_v4_tiny/dspark/config.json
deleted file mode 100644
index 5d7fa957..00000000
--- a/c/deepseek_v4_tiny/dspark/config.json
+++ /dev/null
@@ -1,69 +0,0 @@
-{
- "architectures": [
- "DeepseekV4ForCausalLM"
- ],
- "model_type": "deepseek_v4",
- "transformers_version": "5.14.1",
- "torch_dtype": "bfloat16",
- "expert_dtype": "fp4",
- "scoring_func": "sqrtsoftplus",
- "topk_method": "noaux_tc",
- "hidden_size": 128,
- "num_hidden_layers": 3,
- "num_attention_heads": 4,
- "num_key_value_heads": 1,
- "head_dim": 32,
- "q_lora_rank": 128,
- "qk_rope_head_dim": 16,
- "o_groups": 1,
- "o_lora_rank": 128,
- "sliding_window": 8,
- "index_n_heads": 2,
- "index_head_dim": 32,
- "index_topk": 2,
- "n_routed_experts": 4,
- "num_experts_per_tok": 2,
- "n_shared_experts": 1,
- "moe_intermediate_size": 128,
- "num_hash_layers": 1,
- "num_nextn_predict_layers": 1,
- "hc_mult": 2,
- "hc_sinkhorn_iters": 3,
- "vocab_size": 128,
- "max_position_embeddings": 128,
- "rms_norm_eps": 1e-06,
- "hc_eps": 1e-06,
- "routed_scaling_factor": 1.5,
- "swiglu_limit": 10.0,
- "rope_theta": 10000.0,
- "compress_rope_theta": 40000.0,
- "compress_ratios": [
- 0,
- 4,
- 8,
- 0
- ],
- "rope_scaling": {
- "type": "yarn",
- "factor": 1.0,
- "original_max_position_embeddings": 128,
- "beta_fast": 32,
- "beta_slow": 1
- },
- "quantization_config": {
- "activation_scheme": "dynamic",
- "fmt": "e4m3",
- "scale_fmt": "ue8m0",
- "quant_method": "fp8",
- "weight_block_size": [
- 128,
- 128
- ]
- },
- "dspark_block_size": 2,
- "dspark_noise_token_id": 3,
- "dspark_markov_rank": 16,
- "dspark_target_layer_ids": [
- 1
- ]
-}
diff --git a/c/deepseek_v4_tiny/dspark/model.safetensors b/c/deepseek_v4_tiny/dspark/model.safetensors
deleted file mode 100644
index 5d177f38..00000000
Binary files a/c/deepseek_v4_tiny/dspark/model.safetensors and /dev/null differ
diff --git a/c/deepseek_v4_tiny/dspark/tokenizer.json b/c/deepseek_v4_tiny/dspark/tokenizer.json
deleted file mode 100644
index 54a09a4d..00000000
--- a/c/deepseek_v4_tiny/dspark/tokenizer.json
+++ /dev/null
@@ -1 +0,0 @@
-{"version":"1.0","truncation":null,"padding":null,"added_tokens":[{"id":0,"content":"<t000>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":1,"content":"<t001>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":2,"content":"<t002>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":3,"content":"<t003>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":4,"content":"<t004>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":5,"content":"<t005>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":6,"content":"<t006>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":7,"content":"<t007>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":8,"content":"<t008>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":9,"content":"<t009>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":10,"content":"<t010>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":11,"content":"<t011>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":12,"content":"<t012>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":13,"content":"<t013>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":14,"content":"<t014>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":15,"content":"<t015>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":16,"content":"<t016>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":17,"content":"<t017>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":18,"content":"<t018>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":19,"content":"<t019>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":20,"content":"<t020>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":21,"content":"<t021>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":22,"content":"<t022>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":23,"content":"<t023>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":24,"content":"<t024>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":25,"content":"<t025>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":26,"content":"<t026>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":27,"content":"<t027>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":28,"content":"<t028>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":29,"content":"<t029>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":30,"content":"<t030>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":31,"content":"<t031>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":32,"content":"<t032>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":33,"content":"<t033>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":34,"content":"<t034>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":35,"content":"<t035>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":36,"content":"<t036>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":37,"content":"<t037>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":38,"content":"<t038>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":39,"content":"<t039>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":40,"content":"<t040>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":41,"content":"<t041>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":42,"content":"<t042>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":43,"content":"<t043>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":44,"content":"<t044>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":45,"content":"<t045>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":46,"content":"<t046>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":47,"content":"<t047>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":48,"content":"<t048>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":49,"content":"<t049>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":50,"content":"<t050>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":51,"content":"<t051>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":52,"content":"<t052>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":53,"content":"<t053>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":54,"content":"<t054>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":55,"content":"<t055>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":56,"content":"<t056>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":57,"content":"<t057>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":58,"content":"<t058>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":59,"content":"<t059>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":60,"content":"<t060>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":61,"content":"<t061>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":62,"content":"<t062>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":63,"content":"<t063>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":64,"content":"<t064>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":65,"content":"<t065>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":66,"content":"<t066>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":67,"content":"<t067>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":68,"content":"<t068>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":69,"content":"<t069>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":70,"content":"<t070>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":71,"content":"<t071>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":72,"content":"<t072>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":73,"content":"<t073>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":74,"content":"<t074>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":75,"content":"<t075>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":76,"content":"<t076>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":77,"content":"<t077>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":78,"content":"<t078>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":79,"content":"<t079>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":80,"content":"<t080>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":81,"content":"<t081>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":82,"content":"<t082>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":83,"content":"<t083>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":84,"content":"<t084>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":85,"content":"<t085>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":86,"content":"<t086>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":87,"content":"<t087>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":88,"content":"<t088>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":89,"content":"<t089>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":90,"content":"<t090>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":91,"content":"<t091>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":92,"content":"<t092>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":93,"content":"<t093>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":94,"content":"<t094>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":95,"content":"<t095>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":96,"content":"<t096>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":97,"content":"<t097>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":98,"content":"<t098>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":99,"content":"<t099>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":100,"content":"<t100>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":101,"content":"<t101>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":102,"content":"<t102>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":103,"content":"<t103>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":104,"content":"<t104>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":105,"content":"<t105>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":106,"content":"<t106>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":107,"content":"<t107>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":108,"content":"<t108>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":109,"content":"<t109>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":110,"content":"<t110>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":111,"content":"<t111>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":112,"content":"<t112>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":113,"content":"<t113>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":114,"content":"<t114>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":115,"content":"<t115>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":116,"content":"<t116>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":117,"content":"<t117>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":118,"content":"<t118>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":119,"content":"<t119>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":120,"content":"<t120>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":121,"content":"<t121>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":122,"content":"<t122>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":123,"content":"<t123>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":124,"content":"<t124>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":125,"content":"<t125>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":126,"content":"<t126>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true},{"id":127,"content":"<t127>","single_word":false,"lstrip":false,"rstrip":false,"normalized":false,"special":true}],"normalizer":null,"pre_tokenizer":null,"post_processor":null,"decoder":null,"model":{"type":"BPE","dropout":null,"unk_token":null,"continuing_subword_prefix":"","end_of_word_suffix":"","fuse_unk":false,"byte_fallback":false,"ignore_merges":true,"vocab":{"x":127},"merges":[]}}
diff --git a/c/deepseek_v4_tiny/model.safetensors b/c/deepseek_v4_tiny/model.safetensors
deleted file mode 100644
index 9abc02a0..00000000
Binary files a/c/deepseek_v4_tiny/model.safetensors and /dev/null differ
diff --git a/c/tests/test_deepseek_v4_tiny.py b/c/tests/test_deepseek_v4_tiny.py
index fe11b991..7e06d6b8 100644
--- a/c/tests/test_deepseek_v4_tiny.py
+++ b/c/tests/test_deepseek_v4_tiny.py
@@ -1,15 +1,20 @@
#!/usr/bin/env python3
-"""Dependency-free token-exact checks for the committed tiny V4 fixture."""
+"""Dependency-free token-exact checks for the generated tiny V4 target fixture."""
from __future__ import annotations
import argparse
import json
+import os
import re
import subprocess
+import sys
import tempfile
from pathlib import Path
+sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
+import openai_server
+
def run(label: str, command: list[str]) -> subprocess.CompletedProcess[str]:
result = subprocess.run(
@@ -40,7 +45,6 @@ def flat_oracle(case: dict[str, object]) -> dict[str, object]:
def check_target(
binary: Path,
model: Path,
- draft: Path,
name: str,
case: dict[str, object],
temporary: Path,
@@ -60,21 +64,17 @@ def check_target(
str(len(full)),
"--greedy",
str(len(generated)),
- "--draft-model",
- draft.as_posix(),
],
)
- expected_tf = f"{len(full)}/{len(full)} positions"
- expected_greedy = f"{len(generated)}/{len(generated)} tokens"
- if expected_tf not in result.stdout:
+ if f"{len(full)}/{len(full)} positions" not in result.stdout:
raise AssertionError(f"target {name}: missing exact teacher-forcing result")
- if expected_greedy not in result.stdout:
+ if f"{len(generated)}/{len(generated)} tokens" not in result.stdout:
raise AssertionError(f"target {name}: missing exact greedy result")
print(f"PASS target {name}: teacher forcing and greedy token-exact")
def check_prefix_is_rejected(
- binary: Path, model: Path, draft: Path, case: dict[str, object], temporary: Path
+ binary: Path, model: Path, case: dict[str, object], temporary: Path
) -> None:
truncated = flat_oracle(case)
truncated["full_ids"] = truncated["full_ids"][:-1]
@@ -91,8 +91,6 @@ def check_prefix_is_rejected(
str(len(truncated["full_ids"])),
"--greedy",
str(len(case["greedy_new_ids"])),
- "--draft-model",
- draft.as_posix(),
],
text=True,
encoding="utf-8",
@@ -113,14 +111,13 @@ def token_prompt(ids: list[int]) -> str:
def check_session(
binary: Path,
model: Path,
- draft: Path,
name: str,
case: dict[str, object],
temporary: Path,
- dspark: bool,
ordinal: int = 0,
+ compatibility_flag: bool = False,
) -> list[int]:
- record = temporary / f"{name}-{'dspark' if dspark else 'target'}-{ordinal}.json"
+ record = temporary / f"{name}-target-{ordinal}.json"
command = [
binary.as_posix(),
model.as_posix(),
@@ -130,12 +127,10 @@ def check_session(
str(case["max_new_tokens"]),
"--record-oracle",
record.as_posix(),
- "--draft-model",
- draft.as_posix(),
]
- if not dspark:
+ if compatibility_flag:
command.append("--no-dspark")
- result = run(f"session {name} dspark={dspark}", command)
+ result = run(f"target session {name}", command)
actual = json.loads(record.read_text(encoding="utf-8"))
expected_prompt = case["prompt_ids"]
expected_full = case["greedy_full_ids"]
@@ -146,38 +141,58 @@ def check_session(
)
if actual.get("full_ids") != expected_full:
raise AssertionError(
- f"session {name} dspark={dspark}: exact output mismatch: "
+ f"session {name}: exact output mismatch: "
f"expected {expected_full}, got {actual.get('full_ids')}"
)
stats = re.search(
- r"v4_tokens prompt=(\d+) generated=(\d+).*?"
- r"speculative_rounds=(\d+) proposed=(\d+) accepted=(\d+).*?enabled=(\d+)",
+ r"v4_tokens prompt=(\d+) generated=(\d+).*?target_only=1",
result.stderr,
)
if not stats:
- raise AssertionError(f"session {name}: missing generation statistics")
- prompt_count, generated_count, rounds, proposed, _accepted, enabled = (
- int(value) for value in stats.groups()
- )
+ raise AssertionError(f"session {name}: missing target-only statistics")
+ prompt_count, generated_count = (int(value) for value in stats.groups())
if prompt_count != len(expected_prompt) or generated_count != case["max_new_tokens"]:
raise AssertionError(
- f"session {name}: length mismatch: prompt={prompt_count} generated={generated_count}"
- )
- if dspark and (enabled != 1 or rounds < 1 or proposed < 1):
- raise AssertionError(
- f"session {name}: DSpark was not exercised: "
- f"enabled={enabled} rounds={rounds} proposed={proposed}"
- )
- if not dspark and (enabled != 0 or rounds or proposed):
- raise AssertionError(
- f"session {name}: drafting was not disabled: "
- f"enabled={enabled} rounds={rounds} proposed={proposed}"
+ f"session {name}: length mismatch: "
+ f"prompt={prompt_count} generated={generated_count}"
)
- mode = "DSpark" if dspark else "target session"
- print(f"PASS {mode} {name}: exact IDs and exact length")
+ if compatibility_flag and "compatibility no-op" not in result.stderr:
+ raise AssertionError("--no-dspark compatibility notice was not emitted")
+ print(f"PASS target session {name}: exact IDs and exact length")
return actual["full_ids"]
+def check_serve(binary: Path, model: Path, case: dict[str, object]) -> None:
+ engine = openai_server.Engine(
+ binary,
+ model,
+ max_tokens=int(case["max_new_tokens"]),
+ env=dict(os.environ, CTX="128"),
+ kv_slots=1,
+ )
+ try:
+ expected = token_prompt(case["greedy_new_ids"])
+ for ordinal in range(2):
+ pieces: list[str] = []
+ stats = engine.generate(
+ token_prompt(case["prompt_ids"]),
+ int(case["max_new_tokens"]),
+ 0.0,
+ 1.0,
+ pieces.append,
+ )
+ actual = "".join(pieces)
+ if actual != expected:
+ raise AssertionError(
+ f"serve round {ordinal}: expected {expected!r}, got {actual!r}"
+ )
+ if stats["prompt_tokens"] != len(case["prompt_ids"]):
+ raise AssertionError(f"serve round {ordinal}: bad prompt stats {stats}")
+ finally:
+ engine.close()
+ print("PASS target serve: persistent SUBMIT/DATA/DONE protocol is token-exact")
+
+
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument("--binary", type=Path, required=True)
@@ -186,7 +201,6 @@ def main() -> int:
binary = args.binary.resolve()
fixture = args.fixture.resolve()
- draft = fixture / "dspark"
reference = json.loads((fixture / "ref.json").read_text(encoding="utf-8"))
if reference.get("source") != "transformers":
raise AssertionError("tiny oracle must come from independent Transformers")
@@ -194,49 +208,26 @@ def main() -> int:
with tempfile.TemporaryDirectory(prefix="colibri-v4-tiny-") as directory:
temporary = Path(directory)
- check_target(binary, fixture, draft, "short", cases["short"], temporary)
- check_prefix_is_rejected(binary, fixture, draft, cases["short"], temporary)
- check_target(binary, fixture, draft, "compressed", cases["compressed"], temporary)
- check_target(binary, fixture, draft, "long", cases["long"], temporary)
+ check_target(binary, fixture, "short", cases["short"], temporary)
+ check_prefix_is_rejected(binary, fixture, cases["short"], temporary)
+ check_target(binary, fixture, "compressed", cases["compressed"], temporary)
+ check_target(binary, fixture, "long", cases["long"], temporary)
- # Repeated process-level engine/session lifecycles also validate that
- # drafting is genuinely disabled on the ordinary runtime path.
for ordinal in range(3):
check_session(
binary,
fixture,
- draft,
"short",
cases["short"],
temporary,
- dspark=False,
ordinal=ordinal,
+ compatibility_flag=ordinal == 0,
)
- # The 72-token case crosses the target and DSpark 64-token prefill
- # chunk boundary and verifies absolute-position continuity.
- target_long = check_session(
- binary,
- fixture,
- draft,
- "long",
- cases["long"],
- temporary,
- dspark=False,
- )
- dspark_long = check_session(
- binary,
- fixture,
- draft,
- "long",
- cases["long"],
- temporary,
- dspark=True,
- )
- if dspark_long != target_long:
- raise AssertionError("DSpark output differs from target-only output")
- print("PASS DSpark enabled/disabled identity: exact full sequence")
+ # The 72-token case crosses the 64-token target prefill chunk boundary.
+ check_session(binary, fixture, "long", cases["long"], temporary)
+ check_serve(binary, fixture, cases["short"])
- print("PASS tiny DeepSeek V4 oracle: all checks completed")
+ print("PASS tiny DeepSeek V4 target oracle: all checks completed")
return 0
diff --git a/c/tests/test_make_deepseek_v4_oracle.py b/c/tests/test_make_deepseek_v4_oracle.py
index 608e585a..5a93c381 100644
--- a/c/tests/test_make_deepseek_v4_oracle.py
+++ b/c/tests/test_make_deepseek_v4_oracle.py
@@ -1,7 +1,4 @@
import importlib.util
-import json
-import tempfile
-import types
import unittest
from pathlib import Path
from unittest import mock
@@ -14,7 +11,7 @@ assert SPEC.loader is not None
SPEC.loader.exec_module(ORACLE)
-class DSparkIdentityTests(unittest.TestCase):
+class TargetOracleTests(unittest.TestCase):
def test_make_target_uses_supported_validation_flags(self):
makefile = (Path(__file__).resolve().parents[1] / "Makefile").read_text(
encoding="utf-8"
@@ -23,47 +20,26 @@ class DSparkIdentityTests(unittest.TestCase):
target = target.split("\nelse\n", 1)[0]
self.assertIn("--validate", target)
self.assertIn("--teacher-forcing", target)
- self.assertIn("--check-dspark", target)
+ self.assertNotIn("--check-dspark", target)
self.assertNotIn("--continuation", target)
- def run_validation(self, generated: list[list[int]]) -> int:
- with tempfile.TemporaryDirectory() as directory:
- oracle_path = Path(directory) / "oracle.json"
- oracle_path.write_text(
- json.dumps({"prompt_ids": [1], "full_ids": [1, 2, 3]}),
- encoding="utf-8",
+ def run_validation(self, returncode: int) -> int:
+ process = mock.Mock(returncode=returncode)
+ with mock.patch.object(ORACLE, "run_c", return_value=process):
+ return ORACLE.validate(
+ Path("deepseek_v4"),
+ "/model",
+ Path("oracle.json"),
+ teacher_forcing=2,
+ greedy=2,
+ memory_gb=None,
)
- outputs = list(generated)
- def fake_run(binary, args, env=None):
- if "--record-oracle" in args:
- output = Path(args[args.index("--record-oracle") + 1])
- tokens = outputs.pop(0)
- output.write_text(
- json.dumps({
- "prompt_ids": [1],
- "full_ids": [1, *tokens],
- }),
- encoding="utf-8",
- )
- return types.SimpleNamespace(returncode=0)
+ def test_validation_success(self):
+ self.assertEqual(self.run_validation(0), 0)
- with mock.patch.object(ORACLE, "run_c", side_effect=fake_run):
- return ORACLE.validate(
- Path("deepseek_v4"),
- "/model",
- oracle_path,
- teacher_forcing=2,
- greedy=2,
- memory_gb=None,
- check_dspark=True,
- )
-
- def test_empty_outputs_do_not_pass_identity(self):
- self.assertNotEqual(self.run_validation([[], []]), 0)
-
- def test_exact_full_length_outputs_pass_identity(self):
- self.assertEqual(self.run_validation([[2, 3], [2, 3]]), 0)
+ def test_validation_failure_is_propagated(self):
+ self.assertEqual(self.run_validation(3), 3)
if __name__ == "__main__":
diff --git a/c/tools/make_deepseek_v4_oracle.py b/c/tools/make_deepseek_v4_oracle.py
index afe63760..ccc42f83 100644
--- a/c/tools/make_deepseek_v4_oracle.py
+++ b/c/tools/make_deepseek_v4_oracle.py
@@ -5,7 +5,6 @@ This is intentional heavy validation — not part of light `make check`.
Comparison contract (documented in the JSON and docs/deepseek-v4.md):
- top-1 token exact match for teacher-forcing and greedy windows
- - optional DSpark on/off greedy token identity
- logits max-abs / top-k ranking are reserved for a future transformers
oracle (`source=transformers`); coli-self fixtures only claim token match
@@ -13,9 +12,8 @@ Preferred source when transformers + DeepseekV4ForCausalLM are available:
record reference tokens from the official implementation.
Fallback (current default on most machines):
- drive the C engine with --record-oracle / --no-dspark (source=coli-self).
- That proves reproducibility and DSpark losslessness vs the target path, not
- bit-exact parity with Hugging Face.
+ drive the target-only C engine with --record-oracle (source=coli-self).
+ That proves reproducibility, not bit-exact parity with Hugging Face.
"""
from __future__ import annotations
@@ -63,7 +61,6 @@ def try_transformers_oracle(model: str, prompt: str, max_new: int) -> dict | Non
"comparison": {
"top1_token": "exact",
"logits": "max abs error may be reported by future tooling",
- "dspark": "greedy tokens must match --no-dspark",
},
"prompt_ids": prompt_ids,
"full_ids": full,
@@ -89,7 +86,7 @@ def coli_self_oracle(
memory_gb: float | None,
) -> dict:
args = [model, prompt, "--max-tokens", str(max_new),
- "--record-oracle", str(output), "--no-dspark"]
+ "--record-oracle", str(output)]
if memory_gb is not None:
args.extend(["--memory-gb", str(memory_gb)])
proc = run_c(binary, args)
@@ -105,7 +102,6 @@ def validate(
teacher_forcing: int,
greedy: int,
memory_gb: float | None,
- check_dspark: bool,
) -> int:
args = [
model,
@@ -120,49 +116,8 @@ def validate(
print("[oracle] token validation FAILED", file=sys.stderr)
return proc.returncode
- if not check_dspark:
- print("[oracle] token validation OK (DSpark check skipped)", file=sys.stderr)
- return 0
-
- data = json.loads(oracle_path.read_text(encoding="utf-8"))
- prompt = data.get("prompt") or "What is the capital of France?"
- full = data["full_ids"]
- prompt_ids = data["prompt_ids"]
- want = full[len(prompt_ids):len(prompt_ids) + greedy]
-
- def collect(no_dspark: bool) -> list[int]:
- out_path = oracle_path.with_suffix(".tmp_ids.json")
- cmd = [model, prompt, "--max-tokens", str(greedy),
- "--record-oracle", str(out_path)]
- # Explicit either way: record-oracle alone must not imply --no-dspark,
- # otherwise the on/off identity check is a no-op.
- if no_dspark:
- cmd.append("--no-dspark")
- if memory_gb is not None:
- cmd.extend(["--memory-gb", str(memory_gb)])
- result = run_c(binary, cmd)
- if result.returncode != 0:
- raise SystemExit(f"DSpark compare run failed ({no_dspark=})")
- payload = json.loads(out_path.read_text(encoding="utf-8"))
- out_path.unlink(missing_ok=True)
- got = payload["full_ids"][len(payload["prompt_ids"]):]
- return got[:greedy]
-
- off = collect(True)
- on = collect(False)
- expected = want[:greedy]
- off_ok = len(off) == len(expected) and off == expected
- on_ok = len(on) == len(expected) and on == expected
- same = off == on
- all_ok = off_ok and on_ok and same
- print(
- f"[oracle] DSpark on/off identity: {'OK' if all_ok else 'FAIL'} "
- f"(no_dspark vs fixture {'OK' if off_ok else 'FAIL'}, "
- f"dspark vs fixture {'OK' if on_ok else 'FAIL'}, "
- f"on/off equality {'OK' if same else 'FAIL'})",
- file=sys.stderr,
- )
- return 0 if all_ok else 1
+ print("[oracle] target token validation OK", file=sys.stderr)
+ return 0
def main() -> int:
@@ -176,7 +131,6 @@ def main() -> int:
parser.add_argument("--validate", action="store_true")
parser.add_argument("--teacher-forcing", type=int, default=32)
parser.add_argument("--greedy", type=int, default=20)
- parser.add_argument("--check-dspark", action="store_true")
parser.add_argument(
"--prefer-transformers",
action="store_true",
@@ -220,7 +174,6 @@ def main() -> int:
args.teacher_forcing,
args.greedy,
args.memory_gb,
- args.check_dspark,
)
diff --git a/c/tools/make_deepseek_v4_tiny.py b/c/tools/make_deepseek_v4_tiny.py
index 27e6464a..75dbd0e1 100644
--- a/c/tools/make_deepseek_v4_tiny.py
+++ b/c/tools/make_deepseek_v4_tiny.py
@@ -1,10 +1,11 @@
#!/usr/bin/env python3
-"""Generate the committed tiny DeepSeek V4 + DSpark oracle fixture.
+"""Generate the deterministic tiny DeepSeek V4 target oracle fixture.
-This is a regeneration tool, not a CI dependency. It deliberately requires
-PyTorch and a Transformers release that contains the official
-DeepseekV4ForCausalLM implementation. Reference tokens always come from that
-implementation; there is no C-engine fallback.
+The dedicated V4 CI job runs this with pinned dependencies. It deliberately
+requires PyTorch and a Transformers release that contains the official
+DeepseekV4ForCausalLM implementation. Reference tokens always come from that
+implementation; there is no C-engine fallback and the generated safetensors
+file is never committed.
"""
from __future__ import annotations
@@ -37,11 +38,6 @@ INDEX_DIM = 32
SLIDING = 8
COMPRESS_RATIOS = [0, 4, 8]
MAX_POSITIONS = 128
-DSPARK_STAGES = 1
-DSPARK_BLOCK = 2
-DSPARK_MARKOV_RANK = 16
-DSPARK_TARGET_LAYERS = [1]
-DSPARK_NOISE_TOKEN = 3
E2M1 = (
0.0, 0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 6.0,
@@ -242,7 +238,7 @@ def make_hf_config(DeepseekV4Config):
)
-def make_runtime_config(transformers_version: str, dspark: bool = False) -> dict:
+def make_runtime_config(transformers_version: str) -> dict:
config = {
"architectures": ["DeepseekV4ForCausalLM"],
"model_type": "deepseek_v4",
@@ -296,13 +292,6 @@ def make_runtime_config(transformers_version: str, dspark: bool = False) -> dict
"weight_block_size": [128, 128],
},
}
- if dspark:
- config.update(
- dspark_block_size=DSPARK_BLOCK,
- dspark_noise_token_id=DSPARK_NOISE_TOKEN,
- dspark_markov_rank=DSPARK_MARKOV_RANK,
- dspark_target_layer_ids=DSPARK_TARGET_LAYERS,
- )
return config
@@ -432,80 +421,6 @@ def add_target_tensors(torch, model):
return output
-def add_dspark_tensors(torch, model):
- """Create one valid production-layout DSpark stage.
-
- The independent target oracle remains Transformers. DSpark correctness is
- asserted by lossless target verification, so the draft weights may be a
- deterministic reduced stage derived from target layer 2.
- """
- state = model.state_dict()
- output: OrderedDict[str, object] = OrderedDict()
-
- def put_bf16(name: str, value) -> None:
- output[name] = bf16_round(torch, value).to(torch.bfloat16)
-
- def put_f32(name: str, value) -> None:
- output[name] = value.detach().float().contiguous()
-
- def put_fp8(name: str, value) -> None:
- quantized, scales, _ = quantize_fp8(torch, value)
- output[name + ".weight"] = quantized
- output[name + ".scale"] = scales
-
- put_bf16("embed.weight", state["model.embed_tokens.weight"])
- source = "model.layers.2"
- c = "mtp.0"
- put_f32(f"{c}.attn.attn_sink", state[f"{source}.self_attn.sinks"])
- put_bf16(f"{c}.attn.kv_norm.weight", state[f"{source}.self_attn.kv_norm.weight"])
- put_bf16(f"{c}.attn.q_norm.weight", state[f"{source}.self_attn.q_a_norm.weight"])
- put_fp8(f"{c}.attn.wkv", state[f"{source}.self_attn.kv_proj.weight"])
- put_fp8(f"{c}.attn.wo_a", state[f"{source}.self_attn.o_a_proj.weight"])
- put_fp8(f"{c}.attn.wo_b", state[f"{source}.self_attn.o_b_proj.weight"])
- put_fp8(f"{c}.attn.wq_a", state[f"{source}.self_attn.q_a_proj.weight"])
- put_fp8(f"{c}.attn.wq_b", state[f"{source}.self_attn.q_b_proj.weight"])
- put_bf16(f"{c}.attn_norm.weight", state[f"{source}.input_layernorm.weight"])
- put_bf16(f"{c}.ffn.gate.weight", state[f"{source}.mlp.gate.weight"])
- put_f32(f"{c}.ffn.gate.bias", state[f"{source}.mlp.gate.e_score_correction_bias"])
- put_fp8(f"{c}.ffn.shared_experts.w1", state[f"{source}.mlp.shared_experts.gate_proj.weight"])
- put_fp8(f"{c}.ffn.shared_experts.w2", state[f"{source}.mlp.shared_experts.down_proj.weight"])
- put_fp8(f"{c}.ffn.shared_experts.w3", state[f"{source}.mlp.shared_experts.up_proj.weight"])
- put_bf16(f"{c}.ffn_norm.weight", state[f"{source}.post_attention_layernorm.weight"])
- put_f32(f"{c}.hc_attn_base", state[f"{source}.attn_hc.base"])
- put_f32(f"{c}.hc_attn_fn", state[f"{source}.attn_hc.fn"])
- put_f32(f"{c}.hc_attn_scale", state[f"{source}.attn_hc.scale"])
- put_f32(f"{c}.hc_ffn_base", state[f"{source}.ffn_hc.base"])
- put_f32(f"{c}.hc_ffn_fn", state[f"{source}.ffn_hc.fn"])
- put_f32(f"{c}.hc_ffn_scale", state[f"{source}.ffn_hc.scale"])
-
- gate_up = state[f"{source}.mlp.experts.gate_up_proj"]
- down = state[f"{source}.mlp.experts.down_proj"]
- for expert in range(EXPERTS):
- matrices = [gate_up[expert, :MOE], down[expert], gate_up[expert, MOE:]]
- names = ("w1", "w2", "w3")
- converted = [quantize_fp4(torch, matrix) for matrix in matrices]
- for name, (_, scales, _) in zip(names, converted):
- output[f"{c}.ffn.experts.{expert}.{name}.scale"] = scales
- for name, (packed, _, _) in zip(names, converted):
- output[f"{c}.ffn.experts.{expert}.{name}.weight"] = packed
-
- identity = torch.eye(HIDDEN, dtype=torch.float32)
- put_fp8("mtp.0.main_proj", identity)
- put_bf16("mtp.0.main_norm.weight", torch.ones(HIDDEN))
- put_bf16("mtp.0.norm.weight", state["model.norm.weight"])
- put_f32("mtp.0.hc_head_fn", state["model.hc_head.hc_fn"])
- put_f32("mtp.0.hc_head_base", state["model.hc_head.hc_base"])
- put_f32("mtp.0.hc_head_scale", state["model.hc_head.hc_scale"])
- markov = torch.zeros((VOCAB, DSPARK_MARKOV_RANK), dtype=torch.float32)
- put_bf16("mtp.0.markov_head.markov_w1.weight", markov)
- put_bf16("mtp.0.markov_head.markov_w2.weight", markov)
- put_bf16(
- "mtp.0.confidence_head.proj.weight",
- torch.zeros((1, HIDDEN + DSPARK_MARKOV_RANK), dtype=torch.float32),
- )
- return output
-
-
def make_tokenizer() -> dict:
added = [
{
@@ -636,7 +551,6 @@ def main() -> int:
initialize_router_coverage(torch, model)
target = add_target_tensors(torch, model)
- dspark = add_dspark_tensors(torch, model)
reference = make_reference(torch, transformers, model)
output = args.output.resolve()
@@ -644,26 +558,19 @@ def main() -> int:
if not args.force:
raise SystemExit(f"output exists (use --force): {output}")
shutil.rmtree(output)
- (output / "dspark").mkdir(parents=True)
+ output.mkdir(parents=True)
(output / "config.json").write_text(
json.dumps(make_runtime_config(transformers.__version__), indent=2) + "\n",
encoding="utf-8",
)
- (output / "dspark" / "config.json").write_text(
- json.dumps(make_runtime_config(transformers.__version__, dspark=True), indent=2) + "\n",
- encoding="utf-8",
- )
tokenizer = json.dumps(make_tokenizer(), separators=(",", ":")) + "\n"
(output / "tokenizer.json").write_text(tokenizer, encoding="utf-8")
- (output / "dspark" / "tokenizer.json").write_text(tokenizer, encoding="utf-8")
write_safetensors(torch, output / "model.safetensors", target)
- write_safetensors(torch, output / "dspark" / "model.safetensors", dspark)
(output / "ref.json").write_text(
json.dumps(reference, indent=2) + "\n", encoding="utf-8"
)
print_manifest("target", target)
- print_manifest("dspark", dspark)
total = sum(path.stat().st_size for path in output.rglob("*") if path.is_file())
print(f"wrote {output} ({total} bytes, transformers={transformers.__version__})")
return 0
diff --git a/c/tools/requirements-deepseek-v4-tiny.txt b/c/tools/requirements-deepseek-v4-tiny.txt
new file mode 100644
index 00000000..dbbfa9ac
--- /dev/null
+++ b/c/tools/requirements-deepseek-v4-tiny.txt
@@ -0,0 +1,4 @@
+--extra-index-url https://download.pytorch.org/whl/cpu
+torch==2.13.0+cpu
+transformers==5.14.1
+safetensors==0.8.0