From e657d310e78e805be89d0fd2155cc3544aeec4cb Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Sun, 18 Oct 2026 23:33:52 +0200 Subject: [PATCH] models import: a folder with several models says which ones it holds and asks for one file, in plain words --- strata_cli/cli.py | 19 ++++++++++++++++++- strata_control/models.py | 12 ++++++++++++ tests/terminal/test_discovery.py | 17 +++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/strata_cli/cli.py b/strata_cli/cli.py index 933e0a3c..276d1f72 100644 --- a/strata_cli/cli.py +++ b/strata_cli/cli.py @@ -512,7 +512,7 @@ def _models(a: argparse.Namespace) -> int: print(json.dumps({"schema_version": 1, "ok": False, "plan": result}, ensure_ascii=False, allow_nan=False)) else: - print(f"GGUF file set is incomplete or invalid: {', '.join(result['issues'])}", file=sys.stderr) + print(_import_problem(result), file=sys.stderr) return 5 return _success({"plan": result}, machine=a.output == "json", human=_import_words(result)) if a.models_command == "list": @@ -557,6 +557,23 @@ def _models(a: argparse.Namespace) -> int: f"issues: {len(result['components']['issues'])}") +def _import_problem(plan: dict) -> str: + """Why `models import --plan` refused, in plain words (the codes stay in --output json).""" + from strata_cli.launch.runner import plain_issue + issues = [str(x) for x in plan.get("issues") or []] + if "multiple_model_groups" in issues: # several models in one folder: "not a size Strata knows" would only confuse + issues = [x for x in issues if x != "unrecognized_or_unsupported_model_variant"] + words = "; ".join(dict.fromkeys(plain_issue(x) for x in issues)) + text = f"These files cannot be used as they are: {words}." + holds = plan.get("folder_holds") or [] + if holds: + known = [f"{h['family']} {h['model']} ({h['file']})" for h in holds if h.get("model")] + other = [h["file"] for h in holds if not h.get("model")] + text += " The folder holds " + str(len(holds)) + " models" + (": " + ", ".join(known + other) if known or other else "") + \ + ". Point at the .gguf file of the one you want." + return text + + def _import_words(plan: dict) -> str: """The plain-words result of `strata models import --plan`: what the files are, what is already set up, what changes (nothing).""" cand = plan.get("candidate_selection") or {} diff --git a/strata_control/models.py b/strata_control/models.py index a00901ea..f07dc10e 100644 --- a/strata_control/models.py +++ b/strata_control/models.py @@ -391,8 +391,19 @@ def plan_import(raw_path: str) -> dict: else: groups.setdefault((item.name, 1), set()).add(1) issues = [] + folder_holds = [] if len(groups) != 1: issues.append("multiple_model_groups") + # a folder with several models: say which ones Strata knows, so the person can point at one of them + for key in sorted(groups): + members = [item for item in shards if (SHARD.fullmatch(item.name) and (SHARD.fullmatch(item.name).group(1), + int(SHARD.fullmatch(item.name).group(3))) == key) or (not SHARD.fullmatch(item.name) and (item.name, 1) == key)] + try: + known = _candidate_selection(members) + except ProfileError: + known = None + folder_holds.append({"file": members[0].name if members else key[0], "files": len(members), + "family": known["family"] if known else None, "model": known["model"] if known else None}) if len(groups) == 1: (_, total), indices = next(iter(groups.items())) if total > MAX_IMPORT_SHARDS or indices != set(range(1, total + 1)): @@ -452,6 +463,7 @@ def plan_import(raw_path: str) -> dict: "projectors": projectors, "messages": messages, "already_set_up": _already_set_up(shards, candidate), "reads_pictures": any(p["status"] in ("ok", "other_name") for p in projectors) and not any(i.endswith("unsupported_architecture") for i in issues), + "folder_holds": folder_holds, "file_set_status": "plausible" if not issues else "invalid_or_incomplete", "issues": issues, "adoption_status": "requires_architecture_quantization_tokenizer_and_engine_checks", "execution_compatibility": "unverified", "would_write": False, diff --git a/tests/terminal/test_discovery.py b/tests/terminal/test_discovery.py index 5aff41bc..2dcdcb11 100644 --- a/tests/terminal/test_discovery.py +++ b/tests/terminal/test_discovery.py @@ -185,6 +185,23 @@ class GuiLayout(unittest.TestCase): self.assertEqual(plan["issues"], []) self.assertEqual(plan["candidate_selection"]["model"], "Gyro-M") + def test_a_folder_with_two_models_says_which_and_asks_for_one_file(self): + folder = self.base / "both" + folder.mkdir() + (folder / GYRO_S).write_bytes(gyro_s_bytes()) + (folder / GYRO_M).write_bytes(gyro_m_bytes()) + plan = models.plan_import(str(folder)) + self.assertIn("multiple_model_groups", plan["issues"]) + self.assertEqual(sorted((h["family"], h["model"]) for h in plan["folder_holds"]), [("gyro", "Gyro-M"), ("gyro", "Gyro-S")]) + from strata_cli.cli import _import_problem + text = _import_problem(plan) + self.assertIn("more than one model", text) + self.assertIn("holds 2 models", text) + self.assertIn("gyro Gyro-S", text) + self.assertIn("Point at the .gguf file of the one you want", text) + self.assertNotIn("multiple_model_groups", text) + self.assertNotIn("not a model size", text) + def test_import_still_refuses_gyro_s_with_the_wrong_expert_format(self): folder = self.base / "wrong" folder.mkdir()