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

fp8: repack tool refuses loudly on zero repack-target tensors

monotophic18fe6d1dafe7
diff --git a/c/tests/test_fp8_repack.py b/c/tests/test_fp8_repack.py
index 64bb3dc3..e06b60ed 100644
--- a/c/tests/test_fp8_repack.py
+++ b/c/tests/test_fp8_repack.py
@@ -18,9 +18,14 @@ shape (nblkO*nblkI==O, where this tensor's block-scale byte count would
coincide with a per-row int8 scale byte count) must ALSO be refused
(maintainer review, #528: this is not hypothetical, GLM-5.2's own
self_attn.o_proj.weight is a real instance) -- --dry-run writing nothing, and
-the #383-class resume/params-guard behavior.
+the #383-class resume/params-guard behavior. FIX ROUND 2 (clean-room
+conformance trial, spec I6): a real (non-dry-run) run that selects ZERO
+repack-target tensors across --indir must refuse loudly (nonzero exit,
+stderr naming the condition), not exit 0 having emitted nothing -- an empty
+"container" nobody asked for; --dry-run's own "0 selected" report is
+unaffected (that IS the loud, honest answer dry-run exists to give).
"""
-import glob, json, os, struct, sys, tempfile, unittest
+import glob, json, os, struct, subprocess, sys, tempfile, unittest
try:
import torch
@@ -238,5 +243,58 @@ class ResumeAndParamsGuardTest(unittest.TestCase):
self.assertEqual(len(outs), 1)
+def _make_zero_target_fixture(path, D=256, I_=384):
+ """A shard with real FP8 tensors, but NONE matching a repack-target kind --
+ mirrors the trial's own scenario (a non-resident-named FP8 tensor selects
+ nothing): one routed expert (kind "x", explicitly excluded) and one f32
+ norm (never a repack candidate at all)."""
+ torch.manual_seed(2)
+ sd = {
+ "model.layers.0.mlp.experts.0.gate_proj.weight": torch.randn(I_, D) * 0.02, # routed: EXCLUDE
+ "model.layers.0.input_layernorm.weight": torch.randn(D), # f32: EXCLUDE
+ }
+ save_fp8_safetensors(sd, path)
+
+
+class ZeroTargetRefusalTest(unittest.TestCase):
+ """FIX ROUND 2, item 3 (clean-room conformance trial, spec I6): a real
+ (non-dry-run) run whose --indir has FP8 tensors but none matching a
+ repack-target kind must refuse loudly, not exit 0 having written nothing."""
+
+ def setUp(self):
+ self.tmp = tempfile.TemporaryDirectory()
+ self.indir = os.path.join(self.tmp.name, "fp8src")
+ os.makedirs(self.indir)
+ self.shard = os.path.join(self.indir, "model-00001-of-00001.safetensors")
+ _make_zero_target_fixture(self.shard)
+ self.outdir = os.path.join(self.tmp.name, "out")
+ self.tool = os.path.join(os.path.dirname(__file__), "..", "tools", "repack_fp8_passthrough.py")
+
+ def tearDown(self):
+ self.tmp.cleanup()
+
+ def _run(self, extra_args=()):
+ return subprocess.run(
+ [sys.executable, self.tool, "--indir", self.indir, "--outdir", self.outdir,
+ "--n-layers", "5", *extra_args],
+ capture_output=True, text=True)
+
+ def test_zero_targets_refuses_loudly(self):
+ proc = self._run()
+ self.assertNotEqual(proc.returncode, 0, "zero repack-target tensors must refuse, not exit 0")
+ self.assertIn("no repack-target tensors", proc.stderr)
+ self.assertIn(self.indir, proc.stderr, "the refusal must name the --indir condition")
+ # confirmed empty: no output container was (or should be) produced
+ self.assertEqual(glob.glob(os.path.join(self.outdir, "out-fp8pass-*.safetensors")), [])
+
+ def test_zero_targets_dry_run_unaffected(self):
+ """--dry-run's own "0 tensor(s) selected" report is the loud, honest
+ answer dry-run exists to give -- not a silent no-op -- so it must NOT
+ be turned into a refusal by this fix."""
+ proc = self._run(["--dry-run"])
+ self.assertEqual(proc.returncode, 0)
+ self.assertIn("0 tensor(s) selected", proc.stdout)
+
+
if __name__ == "__main__":
unittest.main()
diff --git a/c/tools/repack_fp8_passthrough.py b/c/tools/repack_fp8_passthrough.py
index 704703af..d292270f 100644
--- a/c/tools/repack_fp8_passthrough.py
+++ b/c/tools/repack_fp8_passthrough.py
@@ -58,11 +58,20 @@ kv_b_proj (kind "kvb") is ALSO deliberately excluded, despite being a resident
tensor classify() would otherwise select: colibri.c's MLA-absorption CPU path
(qt_addrow/qt_matvec_rows, called only on l->kv_b -- the always-available
fallback whenever the Metal fused decode kernel isn't used) has no fmt==7
-case and would silently misread fp8 bytes as int2-packed data; the CUDA
-absorb kernels (coli_cuda_attention_absorb/_kvdev in backend_cuda.cu) are
-similarly int4-specific. Repacking kv_b_proj to fmt=7 needs that CPU+CUDA
-absorb-path work first -- out of scope for this build, so this tool refuses
-to produce a container the engine cannot safely read.
+support. FIX ROUND 2 update: an fmt=7 (or fmt=6) tensor reaching either
+function now refuses loudly (exit(1), naming the function and the fmt) --
+before that fix it was worse than "misread as int2": qt_addrow SIGSEGV'd
+outright (t->q4 is NULL for fmt=7; the untouched int2 fall-through
+dereferenced it), and only fmt=6 (t->q4 non-NULL, wrong per-row scale
+geometry) actually produced silently-wrong values. Either way, this tool
+still does not select kv_b_proj: refusing loudly at the absorb call site is
+not the same as SUPPORTING fmt=7 there (no dequant path exists, whether it
+now trips a controlled refusal or, before the fix, undefined behavior). The
+CUDA absorb kernels (coli_cuda_attention_absorb/_kvdev in backend_cuda.cu)
+are similarly int4-specific and unaffected by that fix. Repacking kv_b_proj
+to fmt=7 needs real fmt=7 CPU+CUDA absorb-path support first -- out of scope
+for this build, so this tool refuses to produce a container the engine
+cannot safely read.
This tool does NOT write a container metadata stamp: __metadata__-based
self-description (writer + qt_verify_fmt_stamp reader + docs/FORMATS.md
@@ -295,6 +304,21 @@ def main():
print(f"[RESUME] {skipped} shard(s) already done in {a.outdir}, skipped")
print(f"[REPACK] {fresh} new output shard(s) written")
_print_inventory_summary(all_inv, dry_run=False)
+ # FIX ROUND 2 (clean-room conformance trial, spec I6 -- loud failure, every
+ # refusal names its condition): a run that selects ZERO repack-target tensors
+ # across every shard under --indir (present run AND any prior resumed run --
+ # `done` has one entry per shard, "" meaning that shard has NEVER produced an
+ # output) used to exit 0 having emitted nothing -- a silent trap: an empty
+ # "container" (just the resume/params sidecars, no actual .safetensors output)
+ # that nobody asked for and no caller-side check would catch. Refuse loudly
+ # instead. --dry-run is NOT covered here: reporting "0 tensors selected" IS
+ # the loud, honest answer dry-run exists to give, not a silent no-op -- see
+ # the early `return` above, before any of this resume/write bookkeeping.
+ if all(v == "" for v in done.values()):
+ print(f"ERROR: no repack-target tensors found under {a.indir} (checked "
+ f"{len(shards)} shard(s), 0 selected) -- nothing emitted; refusing "
+ f"to exit 0 for an empty container nobody asked for", file=sys.stderr)
+ sys.exit(1)
if __name__ == "__main__":