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(convert): detect written options from argparse, not from argv

JustVugg0a2c807c6b59
diff --git a/c/coli b/c/coli
index 77f86a1c..ab9ee705 100755
--- a/c/coli
+++ b/c/coli
@@ -1955,11 +1955,15 @@ def cmd_bench(a):
print(f" {C.dim}decode is disk-bound: this takes HOURS on slow hardware. Raise --limit on faster machines.{C.r}\n")
sys.exit(subprocess.call(cmd, env=e))
-#: I flag di `coli convert` che scelgono la precisione, e il loro nome sulla
-#: riga di comando. Serve a sapere se l'utente li ha SCRITTI: un default non
-#: passato al convertitore non fa danno, uno scritto e ignorato si'.
+#: Le opzioni di precisione di `coli convert`: nome sulla riga di comando e
+#: default. Il parser le dichiara con default=None apposta, cosi' "l'utente
+#: l'ha scritta" e' semplicemente "non e' None" -- vale per --ebits 3,
+#: --ebits=3 e per le abbreviazioni che argparse accetta, senza frugare in
+#: sys.argv. Un default non passato al convertitore non fa danno; un valore
+#: scritto e ignorato si'.
_CONVERT_PRECISION_FLAGS = {"ebits": "--ebits", "io_bits": "--io-bits",
"xbits": "--xbits", "group_size": "--group-size"}
+_CONVERT_DEFAULTS = {"ebits": 4, "io_bits": 8, "xbits": 0, "group_size": 64}
def checkpoint_family(repo):
@@ -2010,10 +2014,15 @@ def cmd_convert(a):
# le indicazioni per famiglia, sotto test; le si lascia dire a lei
# invece di tenerne una seconda copia qui.
script = "convert_fp8_to_int4.py"
+ written_names = [name for name in _CONVERT_PRECISION_FLAGS
+ if getattr(a, name) is not None]
+ for name, value in _CONVERT_DEFAULTS.items():
+ if getattr(a, name) is None:
+ setattr(a, name, value)
if family:
print(f" {C.dim}checkpoint: {family.display_name} -> tools/{script}{C.r}")
- written = [flag for name, flag in _CONVERT_PRECISION_FLAGS.items()
- if flag in sys.argv and name not in family.converter_accepts]
+ written = [_CONVERT_PRECISION_FLAGS[name] for name in written_names
+ if name not in family.converter_accepts]
if written and family.converter:
sys.exit(f"{C.yel}{' '.join(written)}: tools/{script} does not take "
f"{'them' if len(written) > 1 else 'it'}.{C.r}\n"
@@ -2196,8 +2205,14 @@ def main():
_bench_cache = os.path.join(_cache_root, "colibri", "bench")
pb.add_argument("--data",default=_bench_cache)
pc=sub.add_parser("convert", parents=[common]); pc.add_argument("--repo",default="zai-org/GLM-5.2-FP8")
- pc.add_argument("--ebits",type=int,default=4); pc.add_argument("--io-bits",type=int,default=8); pc.add_argument("--xbits",type=int,default=0)
- pc.add_argument("--group-size",type=int,default=64,
+ # default=None e non il valore: cosi' e' argparse a dire se l'opzione e'
+ # stata SCRITTA (--ebits 3, --ebits=3, o abbreviata), e cmd_convert puo'
+ # rifiutarla su un convertitore che non la prende invece di ignorarla.
+ # I valori di default veri stanno in _CONVERT_DEFAULTS.
+ pc.add_argument("--ebits",type=int,default=None,help="routed expert bits (default 4)")
+ pc.add_argument("--io-bits",type=int,default=None,help="embedding/head bits (default 8)")
+ pc.add_argument("--xbits",type=int,default=None,help="streaming expert bits (default = ebits)")
+ pc.add_argument("--group-size",type=int,default=None,
help="int4 scale group size: 64 (default, group-scaled quality) or 0 (legacy per-row)")
pc.add_argument("--no-mtp",action="store_true",help="skip the MTP head (no speculative drafts)")
a=ap.parse_args()
diff --git a/c/tests/test_convert_routing.py b/c/tests/test_convert_routing.py
index 5231e50b..be99666b 100644
--- a/c/tests/test_convert_routing.py
+++ b/c/tests/test_convert_routing.py
@@ -55,10 +55,12 @@ class Args:
def __init__(self, out, **overrides):
self.repo = "some/checkpoint"
self.model = out
- self.ebits = 4
- self.io_bits = 8
- self.xbits = 0
- self.group_size = 64
+ # None = not written on the command line, exactly as argparse reports
+ # it (the convert parser declares default=None for these four).
+ self.ebits = None
+ self.io_bits = None
+ self.xbits = None
+ self.group_size = None
self.no_mtp = False
self.__dict__.update(overrides)
@@ -68,7 +70,7 @@ class ConvertRoutingTest(unittest.TestCase):
def setUpClass(cls):
cls.cli = load_cli()
- def run_convert(self, model_type, argv=("coli", "convert"), **overrides):
+ def run_convert(self, model_type, **overrides):
"""cmd_convert with the subprocess replaced: returns the commands it
would have run, or the SystemExit it raised instead."""
directory = tempfile.TemporaryDirectory()
@@ -86,7 +88,6 @@ class ConvertRoutingTest(unittest.TestCase):
return_value=(family_by_id(model_type)
if model_type else None)):
subprocess_module.call = fake_call
- system.argv = list(argv)
system.exit.side_effect = SystemExit # sys.exit must RAISE, not build
try:
self.cli.cmd_convert(Args(directory.name, **overrides))
@@ -136,12 +137,26 @@ class ConvertRoutingTest(unittest.TestCase):
self.assertEqual(len(calls), 1)
def test_an_option_the_target_does_not_take_is_refused_not_dropped(self):
- calls = self.run_convert(
- "glm53", argv=("coli", "convert", "--ebits", "3"), ebits=3)
+ """Detection comes from argparse (the value is not None), so it holds
+ for `--ebits 3`, `--ebits=3` and any abbreviation argparse accepts. A
+ scan of sys.argv for the literal flag missed the second form and
+ dropped the option silently, which is the bug in better manners."""
+ calls = self.run_convert("glm53", ebits=3)
self.assertEqual(calls, [],
"--ebits was silently dropped and the conversion ran "
"anyway; the user asked for a precision they did not get")
+ def test_an_accepted_option_written_explicitly_is_passed_through(self):
+ command = self.run_convert("glm53", group_size=128)[0]
+ index = command.index("--group-size")
+ self.assertEqual(command[index + 1], "128")
+
+ def test_defaults_are_applied_when_nothing_is_written(self):
+ command = self.run_convert("glm")[0]
+ for flag, value in (("--ebits", "4"), ("--io-bits", "8"), ("--group-size", "64")):
+ self.assertEqual(command[command.index(flag) + 1], value)
+ self.assertNotIn("--xbits", command, "xbits defaults to 0 and is omitted")
+
def test_an_unresolvable_family_keeps_the_old_command(self):
"""A metadata fetch that fails is not a reason to refuse a conversion
that would have worked. The converter's own guard downloads the same