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

tests: inkling's and olmoe's dense chain on Lavapipe, and under ASan and UBSan

JustVugg84b89345b3e4
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 005cf6aa..aaff7037 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -179,6 +179,12 @@ jobs:
# the routed-expert tier of inkling and olmoe under ASan and UBSan
- family: inkling-olmoe-sanitize
req: c/tools/oracle-requirements.txt
+ # the dense chain (COLI_VK_CHAIN=1) of inkling and olmoe, and the same under
+ # ASan and UBSan
+ - family: inkling-olmoe-chain
+ req: c/tools/oracle-requirements.txt
+ - family: inkling-olmoe-chain-sanitize
+ req: c/tools/oracle-requirements.txt
- family: mimo-qwenimage
req: c/tools/requirements-qwenimage-tiny.txt
- family: deepseek
diff --git a/c/tests/vulkan_engines.sh b/c/tests/vulkan_engines.sh
index ab4f9ff7..5334b72f 100755
--- a/c/tests/vulkan_engines.sh
+++ b/c/tests/vulkan_engines.sh
@@ -7,6 +7,7 @@
# bash tests/vulkan_engines.sh glm | glm-sanitize # GLM-5.2 (colibri) and GLM-5.3 Flash (glm53)
# bash tests/vulkan_engines.sh shader # the qmatmul formats, the expert batch and the tier, no engine
# bash tests/vulkan_engines.sh qwen-chain | qwen-chain-sanitize # the dense chain (COLI_VK_CHAIN=1)
+# bash tests/vulkan_engines.sh inkling-olmoe-chain | inkling-olmoe-chain-sanitize
#
# Needs libvulkan-dev, glslc and mesa-vulkan-drivers, plus the Python packages of
# the family's tiny fixtures (see the vulkan-engines job in .github/workflows/ci.yml).
@@ -1340,6 +1341,202 @@ family_qwen_chain_sanitize() {
make clean >/dev/null 2>&1 || true
}
+# inkling's and olmoe's fixtures for their dense chain: the family inkling-olmoe's (the
+# bf16 copy of the f32 snapshot, the dense-int4g64 container, the expert containers and
+# the tokenizers), and Inkling at its real width (--wide: D = 6144, head dim 128).
+inkling_olmoe_chain_fixtures() {
+ $PY tools/make_tiny_inkling.py tiny_inkling
+ $PY tools/make_tiny_inkling.py tiny_inkling_wide --wide
+ mkdir -p tiny_inkling_bf16
+ cp tiny_inkling/config.json tiny_inkling/generation_config.json tiny_inkling_bf16/
+ $PY - <<'EOF'
+import json, struct, numpy as np
+src, dst = "tiny_inkling/model.safetensors", "tiny_inkling_bf16/model.safetensors"
+raw = open(src, "rb").read(); n = struct.unpack("<Q", raw[:8])[0]; hdr = json.loads(raw[8:8 + n])
+out, blobs, off = {}, [], 0
+for k, v in hdr.items():
+ if k == "__metadata__": out[k] = v; continue
+ a = np.frombuffer(raw[8 + n + v["data_offsets"][0]: 8 + n + v["data_offsets"][1]], np.float32)
+ u = a.view(np.uint32).astype(np.uint64)
+ b = ((u + 0x7FFF + ((u >> 16) & 1)) >> 16).astype(np.uint16).tobytes()
+ out[k] = {"dtype": "BF16", "shape": v["shape"], "data_offsets": [off, off + len(b)]}
+ blobs.append(b); off += len(b)
+h = json.dumps(out).encode(); h += b" " * (-len(h) % 8)
+with open(dst, "wb") as f:
+ f.write(struct.pack("<Q", len(h))); f.write(h); [f.write(b) for b in blobs]
+EOF
+ rm -rf tiny_inkling_q && cp -r tiny_inkling tiny_inkling_q
+ $PY - tools/convert_inkling_dense_int4.py tiny_inkling_q <<'EOF'
+import importlib.util, sys
+spec = importlib.util.spec_from_file_location("conv", sys.argv[1])
+conv = importlib.util.module_from_spec(spec); spec.loader.exec_module(conv)
+conv.MIN_ELEMS = 0
+conv.ATTN_BITS = 4
+base = conv.classify
+conv.classify = lambda n, s, d: "int8" if n.endswith(".mlp.down_proj.weight") else base(n, s, d)
+sys.argv = ["convert_inkling_dense_int4.py", "--dir", sys.argv[2]]
+conv.main()
+EOF
+ mkdir -p tiny_inkling_q/dense-int4g64
+ mv tiny_inkling_q/dense-int4g64.safetensors tiny_inkling_q/dense-int4g64/dense.safetensors
+ $PY tools/make_olmoe_tiny.py --output olmoe_tiny --force
+ $PY tools/convert_olmoe_merged.py --model olmoe_tiny --out olmoe_tiny_c
+ inkling_olmoe_tier_fixtures
+}
+
+# chain_gate for a bf16 snapshot: where this CPU's bf16 dot rounds the activations
+# (AVX512-BF16), the per-matrix path keeps bf16 on the CPU and so does the chain, which
+# must then decline cleanly ("bf16 stays on the CPU") with the CPU's tokens.
+chain_gate_bf16() { # <engine> <tag> <env...> -- <argv...>
+ local eng=$1 tag=$2; shift 2
+ local envs=(); while [ "$1" != "--" ]; do envs+=("$1"); shift; done; shift
+ env "${envs[@]}" COLI_VK_TIER_SYNC=1 COLI_VULKAN=1 COLI_VK_CHAIN=1 ./"$eng" "$@" > vk.log 2>&1 || true
+ if grep -qa 'bf16 stays on the CPU' vk.log; then
+ env "${envs[@]}" ./"$eng" "$@" > cpu.log 2>&1 || true
+ same_tokens cpu.log vk.log "$tag"
+ echo "OK $tag: tokens = CPU, the chain declined (this CPU's bf16 dot keeps bf16 on the CPU)"
+ else
+ chain_gate "$eng" "$tag" 1 "${envs[@]}" -- "$@"
+ fi
+}
+
+# lost_gate for olmoe: attention only, so nothing to rebuild; the CPU redoes the step
+# the device was lost in from its first position and runs from there.
+lost_gate_redo() { # <engine> <tag> <frame> <env...> -- <argv...>
+ local eng=$1 tag=$2 k=$3; shift 3
+ local envs=(); while [ "$1" != "--" ]; do envs+=("$1"); shift; done; shift
+ rm -f chain.usage
+ env "${envs[@]}" ./"$eng" "$@" > cpu.log 2>&1 || true
+ env "${envs[@]}" COLI_VK_CHAIN_FAULT=$k COLI_USAGE=chain.usage COLI_VK_TIER_SYNC=1 COLI_VULKAN=1 COLI_VK_CHAIN=1 \
+ ./"$eng" "$@" > vk.log 2>&1 || true
+ same_tokens cpu.log vk.log "$tag"
+ grep -q "the CPU redoes the step from position [1-9]" vk.log || { cat vk.log; fail "$tag: no step was redone"; }
+ echo "OK $tag: tokens = CPU, $(grep -o 'redoes the step from position [0-9]*' vk.log)"
+}
+
+# The device lost `back` frames before the end of a run (a probe run counts the frames,
+# so the fault lands mid-decode on any device, whatever its setup submits): lost_gate
+# (the state rebuilt on the CPU) or lost_gate_redo (the step redone there).
+lost_late() { # <engine> <tag> <frames back> rebuild|redo <env...> -- <argv...>
+ local eng=$1 tag=$2 back=$3 kind=$4; shift 4
+ local envs=(); while [ "$1" != "--" ]; do envs+=("$1"); shift; done; shift
+ env "${envs[@]}" COLI_VK_TIER_SYNC=1 COLI_VULKAN=1 COLI_VK_CHAIN=1 ./"$eng" "$@" > vk.log 2>&1 || true
+ local f; f=$(sed -n "s/^\[VK\] $eng chain: [0-9]* forwards, \([0-9]*\) frames.*/\1/p" vk.log | tail -1)
+ { [ -n "$f" ] && [ "$f" -gt "$back" ]; } || { cat vk.log; fail "$tag: the probe run reports no frames"; }
+ if [ "$kind" = rebuild ]; then lost_gate "$eng" "$tag" $((f - back)) "${envs[@]}" -- "$@"
+ else lost_gate_redo "$eng" "$tag" $((f - back)) "${envs[@]}" -- "$@"; fi
+}
+
+# The dense chain (COLI_VK_CHAIN=1) of inkling and olmoe on Lavapipe, each configuration
+# against the CPU run's tokens and logits (chain_gate: every forward's logits within 1e-4
+# of the largest): inkling's resident forms (f32, bf16, the dense-int4g64 container's
+# int8 and int4-g64), its expert containers and runtime quantizations, TOPP, the tier
+# off, the trunk's device copies shared with the per-matrix path (COLI_VK_DENSE=1),
+# prefill in chunks of 3, the tiled GEMM and the per-row GEMV inside the chain, its real
+# width (D = 6144, beside the tier's expert batch at that width); olmoe's caps, PILOT's
+# prefetch from the chain's residual rows (cap 1: the slot the forward pass reads is
+# never the prefetcher's victim), an eviction budget and the same chain settings; both
+# with prompts only (COLI_VK_CHAIN=2), the device lost mid-run, and the serve, prefix
+# and dashboard tests with the chain on.
+family_inkling_olmoe_chain() {
+ export OMP_NUM_THREADS=2 # tiny models: a wide team only waits for itself (and for Lavapipe's)
+ make inkling olmoe tests/test_vk_chain VK=1
+ ./tests/test_vk_chain shaders/qmatmul.spv | tee vk_chain.log
+ tail -1 vk_chain.log | grep -qx PASS || fail "the chain's ops"
+ inkling_olmoe_chain_fixtures
+ local fx cap bits R=tiny_inkling/ref_inkling.json OR=olmoe_tiny/ref_olmoe.json
+ for fx in tiny_inkling tiny_inkling_q tiny_inkling_x-i4 tiny_inkling_x-i8; do
+ for cap in 1 8; do chain_gate inkling "chain inkling $fx cap=$cap" 1 SNAP=$fx -- $cap 0 $R; done
+ done
+ chain_gate_bf16 inkling "chain inkling bf16" SNAP=tiny_inkling_bf16 -- 8 0 $R
+ for bits in 4 8; do chain_gate inkling "chain inkling runtime int$bits" 1 SNAP=tiny_inkling -- 2 $bits $R; done
+ chain_gate inkling "chain inkling TOPP" 1 TOPP=0.3 SNAP=tiny_inkling_x-i4 -- 2 0 $R
+ chain_gate inkling "chain inkling tier off" 1 COLI_VK_TIER=0 SNAP=tiny_inkling -- 8 0 $R
+ chain_gate inkling "chain inkling trunk shared with the per-matrix path" 1 COLI_VK_DENSE=1 SNAP=tiny_inkling_q -- 8 0 $R
+ chain_gate inkling "chain inkling prefill in chunks of 3" 1 COLI_VK_CHAIN_ROWS=3 SNAP=tiny_inkling -- 8 0 $R
+ chain_gate inkling "chain inkling tiled GEMM" 1 COLI_VK_GEMM_MIN_S=2 SNAP=tiny_inkling -- 8 0 $R
+ chain_gate inkling "chain inkling the per-row GEMV" 1 COLI_VK_CHAIN_GEMV=0 SNAP=tiny_inkling -- 8 0 $R
+ CHAINMODE=2 chain_gate inkling "chain inkling prompts only" 1 SNAP=tiny_inkling -- 8 0 $R
+ # D = 6144: the CPU's tokens through the chain, and through the tier's expert batch
+ # (its gate/up shader stages x up to 6144 floats) with the chain off
+ chain_gate inkling "chain inkling D=6144" 1 SNAP=tiny_inkling_wide -- 8 0 tiny_inkling_wide/ref_inkling.json
+ tier_gate inkling "inkling tier D=6144" COLI_VK_CHAIN=0 SNAP=tiny_inkling_wide -- 8 0 tiny_inkling_wide/ref_inkling.json
+ # the device lost mid-decode, in the last step but one: in a shared-expert frame
+ # nobody waits for (20 frames before the end) and at a layer's router (19): the
+ # state rebuilt on the CPU from the prefix record, the run finished there
+ lost_late inkling "chain inkling device lost in a shared-expert frame" 20 rebuild SNAP=tiny_inkling -- 8 0 $R
+ lost_late inkling "chain inkling device lost at a router" 19 rebuild SNAP=tiny_inkling -- 8 0 $R
+
+ for cap in 1 8; do chain_gate olmoe "chain olmoe cap=$cap" 1 SNAP=olmoe_tiny_c -- $cap 8 $OR; done
+ chain_gate olmoe "chain olmoe 4-bit experts" 1 SNAP=olmoe_tiny_c -- 8 4 $OR
+ for cap in 1 2; do chain_gate olmoe "chain olmoe PILOT cap=$cap" 1 PILOT=1 WIDE=2 SNAP=olmoe_tiny_c -- $cap 8 $OR; done
+ chain_gate olmoe "chain olmoe PILOT=3" 1 PILOT=3 SNAP=olmoe_tiny_c -- 8 8 $OR
+ chain_gate olmoe "chain olmoe tier off" 1 COLI_VK_TIER=0 SNAP=olmoe_tiny_c -- 8 8 $OR
+ chain_gate olmoe "chain olmoe trunk shared with the per-matrix path" 1 COLI_VK_DENSE=1 SNAP=olmoe_tiny_c -- 8 8 $OR
+ chain_gate olmoe "chain olmoe a budget of three experts" 1 COLI_VK_TIER_GB=0.000025 SNAP=olmoe_tiny_c -- 8 8 $OR
+ chain_gate olmoe "chain olmoe prefill in chunks of 3" 1 COLI_VK_CHAIN_ROWS=3 SNAP=olmoe_tiny_c -- 8 8 $OR
+ chain_gate olmoe "chain olmoe tiled GEMM" 1 COLI_VK_GEMM_MIN_S=2 SNAP=olmoe_tiny_c -- 8 8 $OR
+ chain_gate olmoe "chain olmoe the per-row GEMV" 1 COLI_VK_CHAIN_GEMV=0 SNAP=olmoe_tiny_c -- 8 8 $OR
+ CHAINMODE=2 chain_gate olmoe "chain olmoe prompts only" 1 SNAP=olmoe_tiny_c -- 8 8 $OR
+ lost_late olmoe "chain olmoe device lost mid-decode" 7 redo SNAP=olmoe_tiny_c -- 8 8 $OR
+
+ # serve: a session of pins, prompt-cache extensions, a divergent prompt and logprobs
+ # against the CPU's, frame by frame (and with prompts only); the prefix-reuse and
+ # dashboard contracts with the chain on
+ $PY tests/vulkan_chain_serve.py ./inkling tiny_inkling INK_PREFIX_LOG=1
+ COLI_VK_CHAIN=2 $PY tests/vulkan_chain_serve.py ./inkling tiny_inkling INK_PREFIX_LOG=1
+ $PY tests/vulkan_chain_serve.py ./olmoe olmoe_tiny_c
+ $PY tests/vulkan_chain_serve.py ./olmoe olmoe_tiny_c PILOT=1 WIDE=2
+ COLI_VK_CHAIN=2 $PY tests/vulkan_chain_serve.py ./olmoe olmoe_tiny_c
+ # (these compare a warm session's logprobs with a cold one's to the last printed
+ # digit: no history file and COLI_VK_TIER_BALANCE=0, so both sessions split their
+ # experts between the device and the CPU alike)
+ COLI_VULKAN=1 COLI_VK_CHAIN=1 COLI_VK_TIER_SYNC=1 COLI_VK_TIER_BALANCE=0 INKLING_TINY=tiny_inkling \
+ $PY -m unittest tests.test_inkling_prefix_serve tests.test_inkling_dashboard_hits
+ COLI_VULKAN=1 COLI_VK_CHAIN=1 COLI_VK_TIER_SYNC=1 COLI_VK_TIER_BALANCE=0 OLMOE_TINY=olmoe_tiny_c \
+ $PY -m unittest tests.test_olmoe_prefix_serve tests.test_olmoe_dashboard_hits tests.test_brio_serve
+}
+
+# inkling's and olmoe's chain under ASan and UBSan: memory safety is the gate (a
+# sanitized build vectorizes differently, so tokens are not compared); each run must
+# have run the chain. detect_stack_use_after_return=0: ASan's fake stack does not keep
+# the 64-byte alignment an AVX-512 build gives its locals.
+family_inkling_olmoe_chain_sanitize() {
+ make clean >/dev/null 2>&1 || true
+ make inkling olmoe tests/test_vk_chain VK=1 EXTRA_CFLAGS="-fsanitize=address,undefined -fno-omit-frame-pointer -g"
+ export ASAN_OPTIONS=detect_leaks=0:detect_stack_use_after_return=0 UBSAN_OPTIONS=print_stacktrace=1
+ ./tests/test_vk_chain shaders/qmatmul.spv > san.log 2>&1 || true
+ if grep -qE "ERROR: AddressSanitizer|runtime error:" san.log || ! tail -1 san.log | grep -qx PASS; then cat san.log; fail "asan: the chain's ops"; fi
+ echo "OK asan: the chain's ops"
+ inkling_olmoe_chain_fixtures
+ csan() { # <engine> <tag> <env and argv...>
+ local eng=$1 tag=$2; shift 2
+ rm -f chain.usage
+ env OMP_NUM_THREADS=2 COLI_USAGE=chain.usage COLI_VK_TIER_SYNC=1 COLI_VULKAN=1 COLI_VK_CHAIN=${CHAINMODE:-1} "$@" > san.log 2>&1 || true
+ if grep -qE "ERROR: AddressSanitizer|runtime error:" san.log; then cat san.log; fail "$tag: sanitizer diagnostic"; fi
+ [ "$(chain_count "$eng" san.log)" -gt 0 ] || { cat san.log; fail "$tag: the chain never ran"; }
+ echo "OK $tag: sanitizers clean, $(chain_count "$eng" san.log) chain forwards"
+ }
+ local R=tiny_inkling/ref_inkling.json OR=olmoe_tiny/ref_olmoe.json
+ csan inkling "asan chain inkling f32 cap=1" SNAP=tiny_inkling ./inkling 1 0 $R
+ csan inkling "asan chain inkling dense-int4g64, the trunk shared" COLI_VK_DENSE=1 SNAP=tiny_inkling_q ./inkling 8 0 $R
+ csan inkling "asan chain inkling TOPP, chunks of 3" TOPP=0.3 COLI_VK_CHAIN_ROWS=3 SNAP=tiny_inkling_x-i4 ./inkling 2 0 $R
+ csan inkling "asan chain inkling D=6144" SNAP=tiny_inkling_wide ./inkling 8 0 tiny_inkling_wide/ref_inkling.json
+ CHAINMODE=2 csan inkling "asan chain inkling prompts only" SNAP=tiny_inkling ./inkling 8 0 $R
+ csan inkling "asan chain inkling device lost" COLI_VK_CHAIN_FAULT=60 SNAP=tiny_inkling ./inkling 8 0 $R
+ csan olmoe "asan chain olmoe PILOT cap=1" PILOT=1 WIDE=2 SNAP=olmoe_tiny_c ./olmoe 1 8 $OR
+ csan olmoe "asan chain olmoe eviction, chunks of 3" COLI_VK_TIER_GB=0.000025 COLI_VK_CHAIN_ROWS=3 SNAP=olmoe_tiny_c ./olmoe 8 8 $OR
+ csan olmoe "asan chain olmoe device lost" COLI_VK_CHAIN_FAULT=20 SNAP=olmoe_tiny_c ./olmoe 8 8 $OR
+ local eng
+ for eng in inkling olmoe; do
+ local snap=tiny_inkling; [ $eng = olmoe ] && snap=olmoe_tiny_c
+ $PY tests/vulkan_chain_serve.py ./$eng $snap OMP_NUM_THREADS=2 INK_PREFIX_LOG=1 > san.log 2>&1 || { cat san.log; fail "asan chain $eng serve"; }
+ if grep -qE "ERROR: AddressSanitizer|runtime error:" san.log; then cat san.log; fail "asan chain $eng serve: sanitizer diagnostic"; fi
+ echo "OK asan chain $eng serve: $(tail -1 san.log)"
+ done
+ make clean >/dev/null 2>&1 || true
+}
+
case "${1:-}" in
shader) shader_formats ;;
qwen) family_qwen ;;
@@ -1355,5 +1552,7 @@ case "${1:-}" in
glm-sanitize) family_glm_sanitize ;;
qwen-chain) family_qwen_chain ;;
qwen-chain-sanitize) family_qwen_chain_sanitize ;;
- *) echo "usage: $0 shader|qwen|qwen-sanitize|inkling-olmoe|inkling-olmoe-sanitize|mimo-qwenimage|deepseek|deepseek-sanitize|kimi|kimi-mimo-sanitize|glm|glm-sanitize|qwen-chain|qwen-chain-sanitize" >&2; exit 2 ;;
+ inkling-olmoe-chain) family_inkling_olmoe_chain ;;
+ inkling-olmoe-chain-sanitize) family_inkling_olmoe_chain_sanitize ;;
+ *) echo "usage: $0 shader|qwen|qwen-sanitize|inkling-olmoe|inkling-olmoe-sanitize|mimo-qwenimage|deepseek|deepseek-sanitize|kimi|kimi-mimo-sanitize|glm|glm-sanitize|qwen-chain|qwen-chain-sanitize|inkling-olmoe-chain|inkling-olmoe-chain-sanitize" >&2; exit 2 ;;
esac