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

ci(qwen36-tiny-check): make the gate deterministic and actually exact

kreuzzelge84005e01fb2
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 805bd5b4..6bea2c37 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -346,9 +346,13 @@ jobs:
# untested.
python3 tools/make_qwen36_tiny.py --out qwen36_tiny --ref-mode full \
--emit-ref qwen36_tiny/ref_full.json
- # ebits=8 keeps the expert quantization error far below anything that
- # could flip a greedy argmax, so a mismatch means the engine changed,
- # not the container.
+ # ebits=8 keeps the expert quantization error below anything that could
+ # flip a greedy argmax here -- measured. The DENSE weights are the ones
+ # that matter: the engine quantizes them to int8 by default, the torch
+ # reference does not, and that alone cost 7 of 16 tokens. The runs below
+ # therefore set COLI_DENSE_I8=0, which is what the accuracy A/B in
+ # 07_Tests uses for the same reason. Without it this gate compares two
+ # different models and reddens on the luck of the draw.
python3 tools/convert_qwen36.py --model qwen36_tiny --out qwen36_tiny_c --ebits 8
- name: Token-exact against the oracle, at several cache capacities
run: |
@@ -361,7 +365,8 @@ jobs:
# in flight. The engine exits non-zero on any token mismatch.
for cap in 1 2 8; do
echo "::group::cap=$cap"
- SNAP=qwen36_tiny_c ./qwen36 "$cap" 8 qwen36_tiny/ref_full.json
+ COLI_DENSE_I8=0 SNAP=qwen36_tiny_c \
+ ./qwen36 "$cap" 8 qwen36_tiny/ref_full.json
echo "::endgroup::"
done
- name: Same run under ASan + UBSan
@@ -375,7 +380,7 @@ jobs:
make clean >/dev/null 2>&1 || true
make qwen36 EXTRA_CFLAGS="-fsanitize=address,undefined -fno-omit-frame-pointer -g"
ASAN_OPTIONS=detect_leaks=0 UBSAN_OPTIONS=halt_on_error=1 \
- SNAP=qwen36_tiny_c PILOT=1 WIDE=2 \
+ COLI_DENSE_I8=0 SNAP=qwen36_tiny_c PILOT=1 WIDE=2 \
./qwen36 1 8 qwen36_tiny/ref_full.json
# TODO once A1/A2 land: add a malformed-container case here (config.json
# and qwen36_meta.json disagreeing on the layer count) and assert the
diff --git a/c/tools/make_qwen36_tiny.py b/c/tools/make_qwen36_tiny.py
index 6167fca9..d9009e4e 100644
--- a/c/tools/make_qwen36_tiny.py
+++ b/c/tools/make_qwen36_tiny.py
@@ -71,7 +71,11 @@ class Zero(nn.Module):
def build(out: Path, hidden=64, n_layers=8, q_heads=4, kv_heads=2,
head_dim=16, rope_dim=8, n_experts=8, topk=2, inter=32,
vocab=320, max_new=16, prompt_ids=None, emit_ref=None,
- ref_mode="attention_only"):
+ ref_mode="attention_only", seed=20260817):
+ # Fixed by default: an unseeded draw makes the gate flaky. Measured --
+ # three local draws passed, one CI draw failed at 11/16, with identical
+ # code. A gate that reddens at random gets muted within a week.
+ torch.manual_seed(seed)
ModelCls, ConfigCls = get_classes()
layer_types = ["full_attention" if i % 4 == 3 else "linear_attention"
for i in range(n_layers)]
@@ -154,6 +158,9 @@ def main():
ap.add_argument("--out", required=True, help="Output model dir")
ap.add_argument("--emit-ref", default="ref_qwen36.json",
help="Also emit this ref.json (attention_only). Set '' to skip.")
+ ap.add_argument("--seed", type=int, default=20260817,
+ help="RNG seed for the random init; fixed so the gate is "
+ "reproducible")
ap.add_argument("--ref-mode", choices=["attention_only", "full"],
default="attention_only",
help="full keeps both layer kinds (Phase-2 engine); "
@@ -169,7 +176,7 @@ def main():
emit = args.emit_ref if args.emit_ref else None
build(Path(args.out), max_new=args.max_new, prompt_ids=prompt_ids, emit_ref=emit,
- ref_mode=args.ref_mode)
+ ref_mode=args.ref_mode, seed=args.seed)
if __name__ == "__main__":