Skip to content

Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.

C++

setup: --calibrate with --model/--family tunes that installed model, an uninstalled one is an error, --calibrate with --setup/--check or nothing installed says it does nothing (#2036)

Niko12216956f6052cb8
diff --git a/setup.py b/setup.py
index e50829894..7d291e1c6 100644
--- a/setup.py
+++ b/setup.py
@@ -4039,6 +4039,18 @@ def choices_from_config(cfg_path: Path) -> dict:
vis is None or int(val("--vram-reserve-mib")) != VISION["gpu"]["reserve_mib"]) else None}
+def calibration_targets(have: list, model: str | None, family: str | None) -> list:
+ """#2036: the installed configs `--calibrate --model X` (and/or --family) means; every config with neither."""
+ if not (model or family):
+ return list(have)
+ out = []
+ for c in have:
+ ch = choices_from_config(c)
+ if (not model or ch["model"] == model) and (not family or ch["family"] == family):
+ out.append(c)
+ return out
+
+
def find_in(roots: list, rel: str):
"""The first of roots/rel that exists."""
for r in roots:
@@ -4981,7 +4993,17 @@ def main() -> int:
# choice, and asked once when the PC has cards that could share the model
run_gpu = start_gpus(a.gpus) or a.gpu
port = a.port or 8080 # a new install's port (issue #32: --port for an existing one)
- if have and a.calibrate and not (a.setup or a.model or a.family or a.check):
+ if a.calibrate and (a.setup or a.check or not have): # #2036: said, not dropped
+ why = ("--setup" if a.setup else "--check" if a.check else "no model is installed yet")
+ warn(f"--calibrate does nothing with {why}: it tunes a model that is already installed. Run setup first, "
+ "then " + ("START-HERE.bat" if WIN else "./setup.sh") + " --calibrate [--model NAME]")
+ if have and a.calibrate and not (a.setup or a.check):
+ targets = calibration_targets(have, a.model, a.family)
+ if not targets: # #2036: --model names a model that is not installed
+ names = ", ".join(sorted({choices_from_config(c)["model"] or c.stem for c in have}))
+ fail(f"--calibrate: {a.model or a.family} is not installed (installed: {names})",
+ "calibrate an installed model, or set this one up first without --calibrate")
+ have = targets
if not a.build:
update_installed_engine(a.prebuilt)
pick_cfg = have[0]
diff --git a/tools/test_setup_choices.py b/tools/test_setup_choices.py
index 124b7853f..1d1fd992b 100644
--- a/tools/test_setup_choices.py
+++ b/tools/test_setup_choices.py
@@ -614,3 +614,50 @@ class HostCompilers(unittest.TestCase):
if __name__ == "__main__":
unittest.main()
+
+
+class CalibrateWithModel(unittest.TestCase):
+ """#2036: --calibrate --model X tunes model X (it used to fall through to a plain re-setup); a model that is not
+ installed is an error that says so; --calibrate with --setup or --check says it does nothing."""
+
+ def run_main(self, *argv, installed=("iq3_xxs", "q2_0")):
+ tmp = tempfile.TemporaryDirectory()
+ self.addCleanup(tmp.cleanup)
+ cfgs = []
+ for tag in installed:
+ p = Path(tmp.name) / f"strata-{tag}.json"
+ p.write_text(json.dumps({"exe": "x", "args": ["--max-context", "8192"], "model_name": tag}))
+ cfgs.append(p)
+ tuned = []
+ with mock.patch.object(sys, "argv", ["setup.py", *argv]), \
+ mock.patch.object(setup, "installed_configs", lambda: cfgs), \
+ mock.patch.object(setup, "update_installed_engine", lambda *a, **k: None), \
+ mock.patch.object(setup, "calibrate_config", lambda c: tuned.append(c.name) or True), \
+ mock.patch.object(setup, "start", lambda *a, **k: 0), \
+ mock.patch.object(setup, "data_folder", lambda d: (Path(tmp.name), [])), \
+ mock.patch.object(setup, "step", side_effect=SystemExit("reached the plain setup")):
+ try:
+ code, out = quiet(setup.main)
+ except SystemExit as e:
+ code, out = e.code, ""
+ return code, tuned
+
+ def test_model_is_the_target(self):
+ code, tuned = self.run_main("--calibrate", "--model", "IQ3_XXS", "--yes", "--no-start")
+ self.assertEqual((code, tuned), (0, ["strata-iq3_xxs.json"]))
+
+ def test_a_model_not_installed_is_an_error(self):
+ code, tuned = self.run_main("--calibrate", "--model", "IQ3_S", "--yes", "--no-start")
+ self.assertEqual((code, tuned), (1, []))
+
+ def test_targets(self):
+ with tempfile.TemporaryDirectory() as d:
+ ps = []
+ for tag in ("iq3_xxs", "q2_0"):
+ p = Path(d) / f"strata-{tag}.json"
+ p.write_text(json.dumps({"args": []}))
+ ps.append(p)
+ self.assertEqual(setup.calibration_targets(ps, None, None), ps)
+ self.assertEqual(setup.calibration_targets(ps, "Q2_0", None), [ps[1]])
+ self.assertEqual(setup.calibration_targets(ps, "Q2_0", "qwen"), [ps[1]])
+ self.assertEqual(setup.calibration_targets(ps, "Q4_K_M", None), [])