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

fix(oracle): reconcile validation with current dev

Blake4fb195c29865
diff --cc CONTRIBUTING.md
index 2fcc4432,28cebe5d..687351c7
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@@ -13,37 -13,9 +13,37 @@@ Keep changes focused and preserve Colib
it into `main`. This keeps `main` clean instead of taking every PR one at a time.
Every PR β€” on either branch β€” is reviewed for a clean build (0 warnings), the oracle
-(~30-32/32 TF depending on floating-point near-ties + 20/20 greedy), and its own
+(30–32/32 TF depending on floating-point near ties + 20/20 greedy), and its own
targeted validation before merge.
+After generating the fixture, run both enforced comparisons from `c/`:
+
+```sh
+SNAP=./glm_tiny TF=1 COLI_TEMP=0 ORACLE_STRICT=1 ORACLE_TF_MAX_MISMATCHES=2 ./colibri 64 16 16
+SNAP=./glm_tiny COLI_TEMP=0 ORACLE_STRICT=1 ./colibri 64 16 16
+python3 tests/test_glm_oracle.py
+```
+
+`ORACLE_STRICT=1` makes a failed comparison exit with status 1. Strict mode is
+token-exact by default. The teacher-forcing command above explicitly allows at
+most two mismatches, preserving the 30–32/32 acceptance range for this fixture;
+greedy comparison always requires every continuation token to match. Non-finite
+output and incomplete generation fail regardless of the mismatch allowance.
+Invalid reference arrays/JSON fail in either mode.
+Without strict mode (or with `ORACLE_STRICT=0`), a completed comparison remains
+report-only for diagnostic/benchmark callers; its exit status is not a correctness
- gate. Strict mode rejects `REPLAY`, serving, text generation, and other execution
++gate. Strict mode rejects `REPLAY`, `CONSIST`, serving, text generation, and other execution
+modes that would bypass the comparison.
+
+`ORACLE_TF_MAX_MISMATCHES` is a nonnegative integer smaller than the number of
+TF positions; it is used only for strict teacher-forcing comparisons. Unset or
+`0` requires exact TF agreement. Generate the reference on the test host and
+inspect near ties with `TF=1 DEBUG_LOGITS=1`; an allowed mismatch is still printed
+and does not establish token-exact agreement. The regression script checks the
+two-mismatch boundary, optional exact mode, and rejection of a single greedy
+mismatch. It validates the original TF fixture within the same allowance. Routine
+`make check` covers reference validation without needing torch or a generated model.
+
## Local checks
Run the lightweight checks locally:
diff --cc c/Makefile
index a10ff16d,55a8bfeb..e1f5976a
--- a/c/Makefile
+++ b/c/Makefile
@@@ -733,7 -765,7 +765,7 @@@ $(file >.build-config,$(BUILD_CONFIG)
endif
.build-config: ;
- colibri$(EXE): colibri.c cli_args.h oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h quant.h sample.h kv_persist.h telemetry.h route_trace.h omp_tune.h kv_fp8.h kv_tq.h abl.h backend_cuda.h backend_metal.h backend_vulkan.h decode_batch.h edge_adapters.h edge_runtime.h edge_tok_internal.h schema_gbnf.h segment_adapter_internal.h segment_adapters.h segment_runtime.h tier.h $(CUDA_OBJ) $(METAL_OBJ) $(VK_OBJ) $(VK_SPV) .build-config
-colibri$(EXE): colibri.c pin_pool.h cli_args.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h omp_tune.h kv_fp8.h kv_tq.h abl.h backend_cuda.h backend_metal.h backend_vulkan.h decode_batch.h edge_adapters.h edge_runtime.h edge_tok_internal.h schema_gbnf.h segment_adapter_internal.h segment_adapters.h segment_runtime.h tier.h $(CUDA_OBJ) $(METAL_OBJ) $(VK_OBJ) $(VK_SPV) .build-config
++colibri$(EXE): colibri.c oracle.h pin_pool.h cli_args.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h omp_tune.h kv_fp8.h kv_tq.h abl.h backend_cuda.h backend_metal.h backend_vulkan.h decode_batch.h edge_adapters.h edge_runtime.h edge_tok_internal.h schema_gbnf.h segment_adapter_internal.h segment_adapters.h segment_runtime.h tier.h $(CUDA_OBJ) $(METAL_OBJ) $(VK_OBJ) $(VK_SPV) .build-config
$(CC) $(CFLAGS) colibri.c $(CUDA_OBJ) $(METAL_OBJ) $(VK_OBJ) -o colibri$(EXE) $(LDFLAGS)
# Vulkan backend object (plain C + vulkan headers) and its SPIR-V shaders.
@@@ -1207,7 -1260,7 +1260,7 @@@ iobench$(EXE): iobench.c compat.
tests/test_serve_sentinel$(EXE): tests/test_serve_sentinel.c compat.h serve_codec.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
- tests/test_cluster_protocol$(EXE): tests/test_cluster_protocol.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h route_trace.h
-tests/test_cluster_protocol$(EXE): tests/test_cluster_protocol.c colibri.c st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
++tests/test_cluster_protocol$(EXE): tests/test_cluster_protocol.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
tests/test_ue8m0$(EXE): tests/test_ue8m0.c st.h json.h compat.h
@@@ -1313,12 -1369,12 +1369,12 @@@ tests/test_grammar$(EXE): tests/test_gr
# equivalence under the shipping flags is covered by the differential dump
# (old vs new rope_interleave are byte-identical); this test guards the
# source-level formula equivalence and must not depend on contraction luck.
- tests/test_rope_invfreq$(EXE): tests/test_rope_invfreq.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h route_trace.h
-tests/test_rope_invfreq$(EXE): tests/test_rope_invfreq.c colibri.c st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
++tests/test_rope_invfreq$(EXE): tests/test_rope_invfreq.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
$(CC) $(CFLAGS) -ffp-contract=off $< -o $@ $(LDFLAGS)
# schema->GBNF compile cache (#7): grammar_reset must equal a fresh setup, and
# the GrDraft.src ownership must not leak/double-free. Includes colibri.c.
- tests/test_grammar_cache$(EXE): tests/test_grammar_cache.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h route_trace.h
-tests/test_grammar_cache$(EXE): tests/test_grammar_cache.c colibri.c st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
++tests/test_grammar_cache$(EXE): tests/test_grammar_cache.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
# Standalone: drives a faithful miniature of moe()'s routing+accumulate and links
@@@ -1329,7 -1390,7 +1390,7 @@@ tests/test_degrade_zero$(EXE): tests/te
tests/test_schema_gbnf$(EXE): tests/test_schema_gbnf.c schema_gbnf.h grammar.h json.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
- tests/test_spec_decode_state$(EXE): tests/test_spec_decode_state.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h route_trace.h
-tests/test_spec_decode_state$(EXE): tests/test_spec_decode_state.c colibri.c st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
++tests/test_spec_decode_state$(EXE): tests/test_spec_decode_state.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
tests/test_decode_batch$(EXE): tests/test_decode_batch.c decode_batch.h
@@@ -1382,33 -1446,33 +1446,33 @@@ tests/test_olmoe_cache_index$(EXE): tes
tests/test_qwen36_cache_index$(EXE): tests/test_qwen36_cache_index.c qwen36.c expert_ffn.h st.h json.h compat.h sample.h tok.h tok_unicode.h tok_unicode_o200k.h omp_tune.h route_trace.h serve_codec.h qwen36_tier.h $(QWEN36_TIER_SRC) $(CUDA_OBJ)
$(CC) $(QWEN36_CFLAGS) $< $(QWEN36_TIER_SRC) $(CUDA_OBJ) -o $@ $(QWEN36_LDFLAGS)
- tests/test_idot$(EXE): tests/test_idot.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h route_trace.h
-tests/test_idot$(EXE): tests/test_idot.c colibri.c st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
++tests/test_idot$(EXE): tests/test_idot.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
- tests/test_i4_grouped$(EXE): tests/test_i4_grouped.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h route_trace.h
-tests/test_i4_grouped$(EXE): tests/test_i4_grouped.c colibri.c st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
++tests/test_i4_grouped$(EXE): tests/test_i4_grouped.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
- tests/test_stops$(EXE): tests/test_stops.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h route_trace.h
-tests/test_stops$(EXE): tests/test_stops.c colibri.c st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
++tests/test_stops$(EXE): tests/test_stops.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
- tests/test_cfg_topk$(EXE): tests/test_cfg_topk.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h route_trace.h
-tests/test_cfg_topk$(EXE): tests/test_cfg_topk.c colibri.c st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
++tests/test_cfg_topk$(EXE): tests/test_cfg_topk.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
- tests/test_topp$(EXE): tests/test_topp.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h route_trace.h
-tests/test_topp$(EXE): tests/test_topp.c colibri.c st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
++tests/test_topp$(EXE): tests/test_topp.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
# bench_topp is a microbenchmark (old qsort vs new heap partial-select, #335), NOT a test
# gate -- intentionally absent from TEST_BINS. Build on demand: make tests/bench_topp
- tests/bench_topp$(EXE): tests/bench_topp.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h route_trace.h
-tests/bench_topp$(EXE): tests/bench_topp.c colibri.c st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
++tests/bench_topp$(EXE): tests/bench_topp.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
- tests/test_sample_nan$(EXE): tests/test_sample_nan.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h route_trace.h
-tests/test_sample_nan$(EXE): tests/test_sample_nan.c colibri.c st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
++tests/test_sample_nan$(EXE): tests/test_sample_nan.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
- tests/test_temp_env$(EXE): tests/test_temp_env.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h route_trace.h
-tests/test_temp_env$(EXE): tests/test_temp_env.c colibri.c st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
++tests/test_temp_env$(EXE): tests/test_temp_env.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
- tests/test_kv_alloc$(EXE): tests/test_kv_alloc.c colibri.c oracle.h st.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h route_trace.h kv_fp8.h kv_tq.h
-tests/test_kv_alloc$(EXE): tests/test_kv_alloc.c colibri.c st.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h kv_fp8.h kv_tq.h
++tests/test_kv_alloc$(EXE): tests/test_kv_alloc.c colibri.c oracle.h st.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h kv_fp8.h kv_tq.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
tests/test_kv_fp8$(EXE): tests/test_kv_fp8.c kv_fp8.h decode_batch.h
@@@ -1417,7 -1481,7 +1481,7 @@@
tests/test_kv_tq$(EXE): tests/test_kv_tq.c kv_tq.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
- tests/test_kv_disk$(EXE): tests/test_kv_disk.c colibri.c oracle.h st.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h route_trace.h kv_fp8.h kv_tq.h
-tests/test_kv_disk$(EXE): tests/test_kv_disk.c colibri.c st.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h kv_fp8.h kv_tq.h
++tests/test_kv_disk$(EXE): tests/test_kv_disk.c colibri.c oracle.h st.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h kv_fp8.h kv_tq.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
# fmt=6 kernel oracle: needs the generated grid table, and its fixture comes from
@@@ -1452,13 -1516,13 +1516,13 @@@ fuzz-rans: tests/fuzz_rans.c rans.
tests/fuzz_rans.c -o tests/fuzz_rans -lm
./tests/fuzz_rans
- tests/test_int3$(EXE): tests/test_int3.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h route_trace.h
-tests/test_int3$(EXE): tests/test_int3.c colibri.c st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
++tests/test_int3$(EXE): tests/test_int3.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
- tests/test_int3_load$(EXE): tests/test_int3_load.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h route_trace.h
-tests/test_int3_load$(EXE): tests/test_int3_load.c colibri.c st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
++tests/test_int3_load$(EXE): tests/test_int3_load.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
- tests/test_fp8_passthrough$(EXE): tests/test_fp8_passthrough.c quant.h
+ tests/test_fp8_passthrough$(EXE): tests/test_fp8_passthrough.c quant.h idot.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
# Host-only: backend_cuda.h's format predicate is plain C, so its truth table is
@@@ -1467,16 -1531,16 +1531,16 @@@
tests/test_cuda_fmt_guard$(EXE): tests/test_cuda_fmt_guard.c backend_cuda.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
- tests/test_fp8_load$(EXE): tests/test_fp8_load.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h
-tests/test_fp8_load$(EXE): tests/test_fp8_load.c colibri.c st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h
++tests/test_fp8_load$(EXE): tests/test_fp8_load.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
- tests/test_qt_addrow$(EXE): tests/test_qt_addrow.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h
-tests/test_qt_addrow$(EXE): tests/test_qt_addrow.c colibri.c st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h
++tests/test_qt_addrow$(EXE): tests/test_qt_addrow.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
-tests/test_logit_nan$(EXE): tests/test_logit_nan.c colibri.c st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h
+tests/test_logit_nan$(EXE): tests/test_logit_nan.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
-tests/test_router_nan$(EXE): tests/test_router_nan.c colibri.c st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h
+tests/test_router_nan$(EXE): tests/test_router_nan.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
tests/test_i4_acc512$(EXE): tests/test_i4_acc512.c
@@@ -1841,15 -1910,15 +1913,15 @@@ tests/test_mem_available$(EXE): tests/t
tests/test_798_guards$(EXE): tests/test_798_guards.c st.h json.h compat.h route_trace.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
- tests/test_dsa_select$(EXE): tests/test_dsa_select.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h route_trace.h
-tests/test_dsa_select$(EXE): tests/test_dsa_select.c colibri.c st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
++tests/test_dsa_select$(EXE): tests/test_dsa_select.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
- tests/test_corpus_draft$(EXE): tests/test_corpus_draft.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h route_trace.h
-tests/test_corpus_draft$(EXE): tests/test_corpus_draft.c colibri.c st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
++tests/test_corpus_draft$(EXE): tests/test_corpus_draft.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
- tests/test_cap_precedence$(EXE): tests/test_cap_precedence.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h
-tests/test_cap_precedence$(EXE): tests/test_cap_precedence.c colibri.c st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h
++tests/test_cap_precedence$(EXE): tests/test_cap_precedence.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
- tests/test_mirror_stripe_split$(EXE): tests/test_mirror_stripe_split.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h
-tests/test_mirror_stripe_split$(EXE): tests/test_mirror_stripe_split.c colibri.c st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h
++tests/test_mirror_stripe_split$(EXE): tests/test_mirror_stripe_split.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
tests/test_v4_hybrid_policy$(EXE): tests/test_v4_hybrid_policy.c deepseek_v4_hybrid.h hybrid_split.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
@@@ -1860,29 -1929,29 +1932,29 @@@ tests/test_k3_fill_budget$(EXE): tests/
tests/test_v4_bank_pair$(EXE): tests/test_v4_bank_pair.c deepseek_v4_bank_pair.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
- tests/test_ram_clamp$(EXE): tests/test_ram_clamp.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h
-tests/test_ram_clamp$(EXE): tests/test_ram_clamp.c colibri.c st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h
++tests/test_ram_clamp$(EXE): tests/test_ram_clamp.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
- tests/test_cap_mixed_width$(EXE): tests/test_cap_mixed_width.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h route_trace.h
-tests/test_cap_mixed_width$(EXE): tests/test_cap_mixed_width.c colibri.c st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
++tests/test_cap_mixed_width$(EXE): tests/test_cap_mixed_width.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
- tests/test_eslot_inflight$(EXE): tests/test_eslot_inflight.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h route_trace.h
-tests/test_eslot_inflight$(EXE): tests/test_eslot_inflight.c colibri.c st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
++tests/test_eslot_inflight$(EXE): tests/test_eslot_inflight.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
- tests/test_glm_cache_index$(EXE): tests/test_glm_cache_index.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h route_trace.h
-tests/test_glm_cache_index$(EXE): tests/test_glm_cache_index.c colibri.c st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
++tests/test_glm_cache_index$(EXE): tests/test_glm_cache_index.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
- tests/test_ssd_probe$(EXE): tests/test_ssd_probe.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h
-tests/test_ssd_probe$(EXE): tests/test_ssd_probe.c colibri.c st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h
++tests/test_ssd_probe$(EXE): tests/test_ssd_probe.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
# bench_dsa_select is a microbenchmark (old qsort vs new quickselect partial-select, #356),
# NOT a test gate -- intentionally absent from TEST_BINS. Build on demand: make tests/bench_dsa_select
- tests/bench_dsa_select$(EXE): tests/bench_dsa_select.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h route_trace.h
-tests/bench_dsa_select$(EXE): tests/bench_dsa_select.c colibri.c st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
++tests/bench_dsa_select$(EXE): tests/bench_dsa_select.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
# bench_router_select is a microbenchmark (duplicate-prefix scan vs marked-score scan),
# not a test gate. Build on demand: make tests/bench_router_select.
- tests/bench_router_select$(EXE): tests/bench_router_select.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h route_trace.h
-tests/bench_router_select$(EXE): tests/bench_router_select.c colibri.c st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
++tests/bench_router_select$(EXE): tests/bench_router_select.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
# bench_indexer_allocations: microbenchmark (DeepSeek V4 indexer malloc vs persistent arena scratch), NOT a test gate.
@@@ -1892,29 -1961,34 +1964,34 @@@ tests/bench_indexer_allocations$(EXE):
# bench_idot: microbenchmark (single-acc vs independent-acc AVX-VNNI idot), NOT a test gate.
# Build on demand on an AVX-VNNI CPU: make tests/bench_idot ARCH=native
- tests/bench_idot$(EXE): tests/bench_idot.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h route_trace.h
-tests/bench_idot$(EXE): tests/bench_idot.c colibri.c st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
++tests/bench_idot$(EXE): tests/bench_idot.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
+ $(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
+
+ # bench_i4p_gidot: microbenchmark (per-row vs multi-row/AMX K1b grouped planar IDOT), NOT a test gate.
+ # Build on demand: make tests/bench_i4p_gidot ARCH=native
-tests/bench_i4p_gidot$(EXE): tests/bench_i4p_gidot.c colibri.c st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
++tests/bench_i4p_gidot$(EXE): tests/bench_i4p_gidot.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
# bench_gemv_stream: microbenchmark (decode-regime GEMV bandwidth vs the read ceiling;
# frozen-baseline + deinterleaved-x candidate A/B), NOT a test gate.
# Build on demand: make tests/bench_gemv_stream ARCH=native
- tests/bench_gemv_stream$(EXE): tests/bench_gemv_stream.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h route_trace.h
-tests/bench_gemv_stream$(EXE): tests/bench_gemv_stream.c colibri.c st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
++tests/bench_gemv_stream$(EXE): tests/bench_gemv_stream.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
# bench_mla_simd: microbenchmark (scalar vs AVX2/NEON MLA-absorb reductions, #442),
# NOT a test gate. Build on demand: make tests/bench_mla_simd
- tests/bench_mla_simd$(EXE): tests/bench_mla_simd.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h route_trace.h
-tests/bench_mla_simd$(EXE): tests/bench_mla_simd.c colibri.c st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
++tests/bench_mla_simd$(EXE): tests/bench_mla_simd.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
- tests/test_uring$(EXE): tests/test_uring.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h route_trace.h
-tests/test_uring$(EXE): tests/test_uring.c colibri.c st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
++tests/test_uring$(EXE): tests/test_uring.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h route_trace.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
-tests/test_pipe_block$(EXE): tests/test_pipe_block.c colibri.c st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h
+tests/test_pipe_block$(EXE): tests/test_pipe_block.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
- tests/test_pilot_ring$(EXE): tests/test_pilot_ring.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h
-tests/test_pilot_ring$(EXE): tests/test_pilot_ring.c colibri.c st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h
++tests/test_pilot_ring$(EXE): tests/test_pilot_ring.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
- tests/test_moe_gs_guard$(EXE): tests/test_moe_gs_guard.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h
-tests/test_moe_gs_guard$(EXE): tests/test_moe_gs_guard.c colibri.c st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h
++tests/test_moe_gs_guard$(EXE): tests/test_moe_gs_guard.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
tests/test_omp_tune$(EXE): tests/test_omp_tune.c omp_tune.h compat.h
@@@ -1923,9 -1997,45 +2000,45 @@@
tests/test_compat_env$(EXE): tests/test_compat_env.c compat.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
- tests/test_kvb_notice$(EXE): tests/test_kvb_notice.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h
-tests/test_kvb_notice$(EXE): tests/test_kvb_notice.c colibri.c st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h
++tests/test_kvb_notice$(EXE): tests/test_kvb_notice.c colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h idot.h sample.h kv_persist.h telemetry.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
+ # Standalone: proves the group-scaled int8 GEMV keeps every row's float
+ # operations in their original order -- the assumption qwen36's byte-identical
+ # output rests on. Links the SAME gsgemv.h the engine links.
+ tests/test_gsgemv$(EXE): tests/test_gsgemv.c gsgemv.h sse41_kernels.h
+ $(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
+
+ # Same gate, forced onto the SSE4.1 tier: overrides the host's default -march
+ # so the SSE4.1 body in gsgemv.h is actually exercised even on a devbox that
+ # would otherwise always pick the AVX2 tier.
+ tests/test_gsgemv_sse41$(EXE): tests/test_gsgemv.c gsgemv.h sse41_kernels.h
+ $(CC) $(CFLAGS) -msse4.1 -mno-avx2 -mno-fma $< -o $@ $(LDFLAGS)
+
+ # Standalone: proves the plain (non-group-scaled) int8 GEMV keeps its exact
+ # sequence of float operations -- the assumption qwen36's byte-identical
+ # output rests on. Links the SAME qgemv.h the engine links.
+ tests/test_qgemv$(EXE): tests/test_qgemv.c qgemv.h sse41_kernels.h
+ $(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
+
+ # Same gate, forced onto the SSE4.1 tier: overrides the host's default -march
+ # so the SSE4.1 body in qgemv.h is actually exercised even on a devbox that
+ # would otherwise always pick the AVX2 tier.
+ tests/test_qgemv_sse41$(EXE): tests/test_qgemv.c qgemv.h sse41_kernels.h
+ $(CC) $(CFLAGS) -msse4.1 -mno-avx2 -mno-fma $< -o $@ $(LDFLAGS)
+
+ # olmoe's dot_i8_16 (ARM NEON/AVX2/SSE4.1 variants): must be bit-exact against
+ # a scalar int8 reference -- pure integer arithmetic, no tolerance needed.
+ # NOCUDA_* for the same reason the other olmoe.c-including test rules use it.
+ tests/test_olmoe_dot_i8_16$(EXE): tests/test_olmoe_dot_i8_16.c olmoe.c sse41_kernels.h st.h json.h compat.h sample.h tok.h tok_unicode.h tok_unicode_o200k.h omp_tune.h route_trace.h serve_codec.h
+ $(CC) $(NOCUDA_CFLAGS) $< -o $@ $(NOCUDA_LDFLAGS)
+
+ # Same gate, forced onto the SSE4.1 tier: overrides the host's default -march
+ # so the SSE4.1 body in olmoe.c's dot_i8_16 is actually exercised even on a
+ # devbox that would otherwise always pick the AVX2 tier.
+ tests/test_olmoe_dot_i8_16_sse41$(EXE): tests/test_olmoe_dot_i8_16.c olmoe.c sse41_kernels.h st.h json.h compat.h sample.h tok.h tok_unicode.h tok_unicode_o200k.h omp_tune.h route_trace.h serve_codec.h
+ $(CC) $(NOCUDA_CFLAGS) -msse4.1 -mno-avx2 -mno-fma $< -o $@ $(NOCUDA_LDFLAGS)
+
test-c: $(TEST_BINS)
$(PYTHON) tools/run_tests.py $(TEST_BINS)
diff --cc c/colibri.c
index 5358c236,28ea0c07..e62df4ec
--- a/c/colibri.c
+++ b/c/colibri.c
@@@ -10765,19 -11017,6 +11029,19 @@@ static int coli_env_on(const char *name
#ifndef COLIBRI_NO_MAIN
int main(int argc, char **argv){
+ int strict=coli_env_on("ORACLE_STRICT");
+ if(strict){
- const char *modes[]={"REPLAY","SERVE","SCORE","ABLATE_SCORE","EXPERT_WORKER",
++ const char *modes[]={"REPLAY","CONSIST","SERVE","SCORE","ABLATE_SCORE","EXPERT_WORKER",
+ "I4_ACC512_TEST","I3_AVX512_TEST"};
+ for(size_t i=0;i<sizeof(modes)/sizeof(modes[0]);i++) if(getenv(modes[i])){
+ fprintf(stderr,"[ORACLE] ORACLE_STRICT cannot be combined with %s\n",modes[i]);
+ return 1;
+ }
+ if(coli_user_prompt() || (getenv("COLI_ANS_PACK") && atoi(getenv("COLI_ANS_PACK")))){
+ fprintf(stderr,"[ORACLE] ORACLE_STRICT requires oracle comparison mode\n");
+ return 1;
+ }
+ }
/* ---- Permanent OpenMP hot-thread tuning. The per-expert matmul regions are
* tiny and back-to-back; with the default passive wait policy libgomp parks
* the worker team between regions and the re-wake latency dominates. Keeping
@@@ -11546,22 -11798,13 +11823,23 @@@
}
/* altrimenti: validazione contro l'oracolo (ref_glm.json) */
- int teacher_forcing=getenv("TF")!=NULL;
++ /* Diagnostic modes take precedence over TF and do not read predictions. */
++ int teacher_forcing=getenv("TF")!=NULL && !getenv("REPLAY") && !getenv("CONSIST");
const char *refpath=getenv("REF")?getenv("REF"):"ref_glm.json";
char *b=cfg_slurp(refpath);
- if(!b){ fprintf(stderr,"%s: cannot read oracle file (missing, unreadable, short, or > %lld bytes)\n",refpath,(long long)CFG_MAX_BYTES); return 1; }
- char *ar=NULL; jval *ref=json_parse(b,&ar);
- int np=0,nfull=0; int *prompt=read_arr(ref,"prompt_ids",&np); int *full=read_arr(ref,"full_ids",&nfull);
- if(!prompt||!full||np<1||nfull<np){ fprintf(stderr,"ref file missing prompt_ids/full_ids or empty\n"); return 1; }
+ if(!b){ fprintf(stderr,"%s: cannot read oracle file (missing, unreadable, short, contains NUL, or > %lld bytes)\n",refpath,(long long)CFG_MAX_BYTES); return 1; }
+ OracleRef ref;
+ int valid=oracle_ref_parse(b,m.c.vocab,teacher_forcing,&ref);
+ free(b);
+ if(!valid) return 1;
+ int np=ref.np,nfull=ref.nfull; int *prompt=ref.prompt,*full=ref.full;
int n_new=nfull-np;
+ int tf_allowed=0;
+ if(strict && teacher_forcing &&
+ !oracle_tf_allowance(getenv("ORACLE_TF_MAX_MISMATCHES"),nfull,&tf_allowed)){
+ fprintf(stderr,"[ORACLE] ORACLE_TF_MAX_MISMATCHES must be an integer in [0,%d)\n",nfull);
+ oracle_ref_free(&ref); return 1;
+ }
/* L'oracolo (ref_glm.json in repo) e' del modello TINY: contro il 744B da' 0/20
* garantito su OGNI piattaforma (prompt-token tiny = spazzatura per il modello vero).
* Non e' un bug del motore β€” vedi #76. */
@@@ -11588,12 -11830,16 +11866,19 @@@
return 0;
}
+ if(getenv("CONSIST")){
+ run_consist(&m,full,nfull,np);
+ if(stats) stats_dump(&m,stats);
++ oracle_ref_free(&ref);
+ return 0;
+ }
+
- if(getenv("TF")){
- int *tf=read_arr(ref,"tf_pred",&(int){0});
- int *pred=malloc(nfull*sizeof(int)); double tt=now_s();
- forward_all(&m, full, nfull, pred, tf); double tdt=now_s()-tt;
+ if(teacher_forcing){
+ int *tf=ref.tf;
+ int *pred=malloc((size_t)nfull*sizeof(int));
+ if(!pred){ oracle_ref_free(&ref); return 1; }
+ double tt=now_s();
+ int finite=forward_all(&m, full, nfull, pred, tf); double tdt=now_s()-tt;
int ok=0; for(int i=0;i<nfull;i++){
if(pred[i]==tf[i]) ok++;
else fprintf(stderr,"[ORACLE] mismatch pos=%d expected=%d got=%d\n",i,tf[i],pred[i]);
diff --cc c/tests/test_glm_oracle.py
index 14003ec6,00000000..90c8325f
mode 100644,000000..100644
--- a/c/tests/test_glm_oracle.py
+++ b/c/tests/test_glm_oracle.py
@@@ -1,271 -1,0 +1,287 @@@
+"""Real-process GLM oracle exit-status regression; stdlib only.
+
+Discovery skips when the generated fixture is absent. Direct execution (as in
+CI) requires it, so a missing engine/fixture cannot silently pass the gate.
+"""
+import argparse
+import copy
+import json
+import os
+from pathlib import Path
+import re
+import shutil
+import struct
+import subprocess
+import tempfile
+import unittest
+
+C_DIR = Path(__file__).resolve().parents[1]
+ENGINE = C_DIR / ("colibri.exe" if os.name == "nt" else "colibri")
+SNAP = C_DIR / "glm_tiny"
+REFERENCE = C_DIR / "ref_glm.json"
+
+
+class GlmOracleTest(unittest.TestCase):
+ @classmethod
+ def setUpClass(cls):
+ if not (ENGINE.is_file() and (SNAP / "model.safetensors").is_file()
+ and REFERENCE.is_file()):
+ raise unittest.SkipTest("build colibri and generate the GLM tiny oracle first")
+ cls.reference = json.loads(REFERENCE.read_text(encoding="utf-8"))
+ cls.vocab = json.loads((SNAP / "config.json").read_text(encoding="utf-8"))["vocab_size"]
+ # Keep the independent fixture for the numerical gate. Use observed TF
+ # predictions only to place exit-status tests at exact mismatch counts,
+ # even on a host with one or two floating-point near ties.
+ cls.tf_reference = cls.observed_tf_reference(cls.reference)
+
+ @classmethod
+ def run_oracle(cls, reference=None, *, tf=True, strict="1", raw=None,
+ snapshot=None, extra_env=None):
+ # Do not inherit serving/sampling/offload knobs from an interactive shell.
+ keep = {"PATH", "SYSTEMROOT", "WINDIR", "TEMP", "TMP", "HOME", "USERPROFILE",
+ "LD_LIBRARY_PATH", "DYLD_LIBRARY_PATH", "ASAN_OPTIONS", "UBSAN_OPTIONS"}
+ env = {k: v for k, v in os.environ.items() if k in keep}
+ env.update(SNAP=str(SNAP if snapshot is None else snapshot), COLI_TEMP="0", OMP_NUM_THREADS="4")
+ if tf:
+ env["TF"] = "1"
+ if strict is not None:
+ env["ORACLE_STRICT"] = strict
+ env.update(extra_env or {})
+ with tempfile.TemporaryDirectory(prefix="colibri-oracle-") as tmp:
+ path = Path(tmp) / "ref.json"
+ path.write_text(raw if raw is not None else json.dumps(
+ cls.reference if reference is None else reference), encoding="utf-8")
+ env["REF"] = str(path)
+ return subprocess.run([str(ENGINE), "64", "16", "16"], cwd=C_DIR,
+ env=env, capture_output=True, text=True,
+ encoding="utf-8", errors="replace", timeout=60)
+
+ @classmethod
+ def observed_tf_reference(cls, reference):
+ result = cls.run_oracle(reference, strict="0")
+ if result.returncode:
+ raise AssertionError(result.stdout + result.stderr)
+ score = re.search(r"C vs oracle: (\d+)/(\d+) positions", result.stdout)
+ if score is None or int(score[2]) != len(reference["tf_pred"]):
+ raise AssertionError("missing TF score: " + result.stdout + result.stderr)
+ ref = copy.deepcopy(reference)
+ mismatches = re.findall(r"\[ORACLE\] mismatch pos=(\d+) expected=(\d+) got=(-?\d+)", result.stderr)
+ if len(mismatches) != int(score[2]) - int(score[1]):
+ raise AssertionError("incomplete TF diagnostics: " + result.stderr)
+ for pos, expected, got in mismatches:
+ pos, expected, got = int(pos), int(expected), int(got)
+ if not (0 <= pos < len(ref["tf_pred"]) and 0 <= got < cls.vocab
+ and ref["tf_pred"][pos] == expected):
+ raise AssertionError("invalid TF prediction: " + result.stderr)
+ ref["tf_pred"][pos] = got
+ return ref
+
+ def assert_failed(self, result):
+ self.assertEqual(result.returncode, 1, result.stdout + result.stderr)
+
+ def corrupted(self, tf, count=1):
+ ref = copy.deepcopy(self.tf_reference if tf else self.reference)
+ if tf:
+ for i in range(count):
+ ref["tf_pred"][i] = (ref["tf_pred"][i] + 1) % self.vocab
+ else:
+ ref["full_ids"][-1] = (ref["full_ids"][-1] + 1) % self.vocab
+ return ref
+
+ def test_valid_reference_passes_both_modes(self):
+ for tf in (True, False):
+ with self.subTest(tf=tf):
+ result = self.run_oracle(tf=tf, extra_env={"ORACLE_TF_MAX_MISMATCHES": "2"})
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ total = len(self.reference["full_ids"])
+ new = total - len(self.reference["prompt_ids"])
+ if tf:
+ score = re.search(r"C vs oracle: (\d+)/(\d+) positions", result.stdout)
+ self.assertIsNotNone(score, result.stdout)
+ self.assertEqual(int(score[2]), total)
+ self.assertGreaterEqual(int(score[1]), total - 2)
+ else:
+ self.assertIn(f"Matching tokens: {new}/{new}", result.stdout)
+
+ def test_exact_mode_rejects_one_wrong_prediction(self):
+ for tf in (True, False):
+ with self.subTest(tf=tf):
+ self.assert_failed(self.run_oracle(self.corrupted(tf), tf=tf))
+
+ def test_teacher_forcing_allowance_boundary(self):
+ total = len(self.reference["tf_pred"])
+ for wrong in (0, 1, 2, 3):
+ with self.subTest(wrong=wrong):
+ result = self.run_oracle(self.corrupted(True, wrong),
+ extra_env={"ORACLE_TF_MAX_MISMATCHES": "2"})
+ self.assertEqual(result.returncode, int(wrong > 2), result.stdout + result.stderr)
+ self.assertIn(f"{total - wrong}/{total} positions", result.stdout)
+
+ def test_explicit_zero_allowance_is_exact(self):
+ for wrong in (0, 1):
+ with self.subTest(wrong=wrong):
+ result = self.run_oracle(self.corrupted(True, wrong),
+ extra_env={"ORACLE_TF_MAX_MISMATCHES": "0"})
+ self.assertEqual(result.returncode, wrong, result.stdout + result.stderr)
+
+ def test_teacher_forcing_allowance_does_not_relax_greedy(self):
+ self.assert_failed(self.run_oracle(self.corrupted(False), tf=False,
+ extra_env={"ORACLE_TF_MAX_MISMATCHES": "2"}))
+
+ def test_invalid_allowance_fails_before_comparison(self):
+ total = len(self.reference["tf_pred"])
+ for value in ("", "-1", "+2", " 2", "2 ", "2x", "2.0", str(total), str(total + 1), "9" * 40):
+ with self.subTest(value=value):
+ result = self.run_oracle(extra_env={"ORACLE_TF_MAX_MISMATCHES": value})
+ self.assert_failed(result)
+ self.assertIn("ORACLE_TF_MAX_MISMATCHES", result.stderr)
+ self.assertNotIn("C vs oracle:", result.stdout)
+
+ def test_diagnostic_mode_keeps_report_only_exit_status(self):
+ for tf in (True, False):
+ for strict in (None, "0"):
+ with self.subTest(tf=tf, strict=strict):
+ result = self.run_oracle(self.corrupted(tf, 3), tf=tf, strict=strict,
+ extra_env={"ORACLE_TF_MAX_MISMATCHES": "2"})
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+
+ def test_missing_short_and_long_tf_predictions_fail_cleanly(self):
+ for value in (None, [], self.reference["tf_pred"][:-1],
+ self.reference["tf_pred"] + [0], "not an array"):
+ with self.subTest(value=value):
+ ref = copy.deepcopy(self.reference)
+ if value is None:
+ del ref["tf_pred"]
+ else:
+ ref["tf_pred"] = value
+ self.assert_failed(self.run_oracle(ref, extra_env={"ORACLE_TF_MAX_MISMATCHES": "2"}))
+
+ def test_invalid_token_ids_fail_before_inference(self):
+ for field in ("prompt_ids", "full_ids", "tf_pred"):
+ for value in (-1, self.vocab, 1.5, True, "1", None, 1e100):
+ with self.subTest(field=field, value=value):
+ ref = copy.deepcopy(self.reference)
+ ref[field][0] = value
+ result = self.run_oracle(ref)
+ self.assert_failed(result)
+ self.assertIn("[ORACLE]", result.stderr)
+
+ def test_truncated_json_and_mismatched_prompt_fail(self):
+ raw = json.dumps(self.reference)
+ for invalid in (raw[:-1], raw[:-2], raw + " garbage", raw + "\0garbage"):
+ with self.subTest(raw=invalid[-30:]):
+ self.assert_failed(self.run_oracle(raw=invalid))
+ ref = copy.deepcopy(self.reference)
+ ref["prompt_ids"][0] = (ref["prompt_ids"][0] + 1) % self.vocab
+ self.assert_failed(self.run_oracle(ref, tf=False))
+
+ def test_empty_continuation_fails(self):
+ ref = copy.deepcopy(self.reference)
+ ref["full_ids"] = ref["prompt_ids"][:]
+ self.assert_failed(self.run_oracle(ref, tf=False))
+
+ def test_escaped_nul_cannot_alias_reference_keys(self):
+ for field in ("prompt_ids", "full_ids", "tf_pred"):
+ ref = copy.deepcopy(self.reference)
+ ref[field + "\0ignored"] = ref.pop(field)
+ for tf in (True, False):
+ for strict in ("1", None):
+ with self.subTest(field=field, tf=tf, strict=strict):
+ self.assert_failed(self.run_oracle(ref, tf=tf, strict=strict))
+
+ def test_non_json_whitespace_fails(self):
+ raw = json.dumps(self.reference)
+ for whitespace in ("\f", "\v"):
+ for invalid in (whitespace + raw, raw.replace(":", ":" + whitespace, 1),
+ raw.replace("[", "[" + whitespace, 1), raw + whitespace):
+ for tf in (True, False):
+ for strict in ("1", None):
+ with self.subTest(raw=invalid, tf=tf, strict=strict):
+ self.assert_failed(self.run_oracle(raw=invalid, tf=tf, strict=strict))
+
+ def test_other_modes_cannot_bypass_strict_comparison(self):
- for mode in ("REPLAY", "SERVE", "SCORE", "ABLATE_SCORE", "EXPERT_WORKER",
++ for mode in ("REPLAY", "CONSIST", "SERVE", "SCORE", "ABLATE_SCORE", "EXPERT_WORKER",
+ "I4_ACC512_TEST", "I3_AVX512_TEST", "COLI_ANS_PACK", "COLI_PROMPT"):
+ with self.subTest(mode=mode):
+ result = self.run_oracle(extra_env={mode: "1"})
+ self.assert_failed(result)
+ self.assertIn("ORACLE_STRICT", result.stderr)
+
++ def test_reference_diagnostics_remain_available_without_strict(self):
++ # REPLAY and CONSIST use the reference token sequence, not predictions,
++ # and retain their upstream precedence over TF when both are selected.
++ ref = copy.deepcopy(self.reference)
++ del ref["tf_pred"]
++ for mode, marker in (("REPLAY", "REPLAY decode:"), ("CONSIST", "CONSIST OK")):
++ for strict in (None, "0"):
++ for tf in (False, True):
++ with self.subTest(mode=mode, strict=strict, tf=tf):
++ result = self.run_oracle(ref, tf=tf, strict=strict,
++ extra_env={mode: "1"})
++ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
++ self.assertIn(marker, result.stdout)
++ self.assertNotIn("C vs oracle:", result.stdout)
++ self.assertNotIn("Matching tokens:", result.stdout)
++
+ def test_nonfinite_model_logits_fail_both_modes(self):
+ # The tiny generator stores an F32 lm_head in one safetensors shard.
+ # Poison a single output row, including when it would not win argmax.
+ with tempfile.TemporaryDirectory(prefix="colibri-oracle-weights-") as tmp:
+ snapshot = Path(tmp)
+ shutil.copy2(SNAP / "config.json", snapshot / "config.json")
+ weights = (SNAP / "model.safetensors").read_bytes()
+ header_size = struct.unpack_from("<Q", weights)[0]
+ header = json.loads(weights[8:8 + header_size])
+ tensor = header["lm_head.weight"]
+ self.assertEqual(tensor["dtype"], "F32")
+ start = 8 + header_size + tensor["data_offsets"][0]
+ row_bytes = tensor["shape"][1] * 4
+ for value in (float("nan"), float("inf"), -float("inf")):
+ poisoned = bytearray(weights)
+ poisoned[start:start + row_bytes] = struct.pack("<f", value) * tensor["shape"][1]
+ (snapshot / "model.safetensors").write_bytes(poisoned)
+ for tf in (True, False):
+ with self.subTest(value=value, tf=tf):
+ result = self.run_oracle(tf=tf, snapshot=snapshot,
+ extra_env={"ORACLE_TF_MAX_MISMATCHES": "2"})
+ self.assert_failed(result)
+ self.assertIn("non-finite logits", result.stderr)
+
+ def test_one_nonfinite_position_is_not_an_allowed_mismatch(self):
+ # Poison only the last position of a short causal sequence. Its single
+ # mismatch fits within the budget, but non-finite output must still fail.
+ ref = copy.deepcopy(self.reference)
+ ref["prompt_ids"] = ref["full_ids"][:2]
+ last = next(token for token in range(self.vocab) if token not in ref["prompt_ids"])
+ ref["full_ids"] = ref["prompt_ids"] + [last]
+ ref["tf_pred"] = ref["tf_pred"][:3]
+ ref = self.observed_tf_reference(ref)
+ with tempfile.TemporaryDirectory(prefix="colibri-oracle-position-") as tmp:
+ snapshot = Path(tmp)
+ shutil.copy2(SNAP / "config.json", snapshot / "config.json")
+ weights = bytearray((SNAP / "model.safetensors").read_bytes())
+ header_size = struct.unpack_from("<Q", weights)[0]
+ header = json.loads(weights[8:8 + header_size])
+ tensor = header["model.embed_tokens.weight"]
+ self.assertEqual(tensor["dtype"], "F32")
+ row_bytes = tensor["shape"][1] * 4
+ start = 8 + header_size + tensor["data_offsets"][0] + last * row_bytes
+ weights[start:start + row_bytes] = struct.pack("<f", float("nan")) * tensor["shape"][1]
+ (snapshot / "model.safetensors").write_bytes(weights)
+ result = self.run_oracle(ref, snapshot=snapshot,
+ extra_env={"ORACLE_TF_MAX_MISMATCHES": "2"})
+ self.assert_failed(result)
+ self.assertIn("2/3 positions", result.stdout)
+ self.assertIn("non-finite logits at teacher-forcing position 2", result.stderr)
+
+
+if __name__ == "__main__":
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument("--engine", type=Path, default=ENGINE)
+ parser.add_argument("--snapshot", type=Path, default=SNAP)
+ parser.add_argument("--reference", type=Path, default=REFERENCE)
+ args = parser.parse_args()
+ ENGINE, SNAP, REFERENCE = (p.resolve() for p in (args.engine, args.snapshot, args.reference))
+ if not (ENGINE.is_file() and (SNAP / "model.safetensors").is_file() and REFERENCE.is_file()):
+ parser.error("build colibri and generate the GLM tiny oracle first")
+ unittest.main(argv=[__file__, "-v"])