mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 23:08:36 +00:00
presets effective: say where each non-automatic setting comes from (#5351, first step)
"Which file is authoritative, and why did my setting not apply?" starts with seeing the layers. `strata presets effective <config>` now adds, after its
first line, the settings that are not chosen automatically and the layer each one comes from, in the order the launch already applies them
(arg_layers: this start, your own setting, your calibration, your saved tuning): "set in this start", "your own setting", "from your calibration",
"from your saved tuning"; with none: "Every setting is chosen automatically." (words approved by the coordinator.)
The JSON gets one additive field, "sources": {flag: "launch" | "yours" | "calibrated" | "tuned"}; nothing is removed or renamed (the desktop app reads
this JSON through native-autotune.mjs and ignores unknown fields). arg_layers.sources() is read-only; no launch behaviour changes. A calibration measured for
another model, context or picture setting is not named (as for the launch itself).
Tests (tests/tuning/test_preset_persistence.py, 3 new): red on 814d1507f with the new test file (p1006-20261117-0736-cb97: 3 failed, KeyError 'sources'),
green with the change; tests/tuning + tests/terminal/test_calibration.py base and head on p1006.
This commit is contained in:
1 parent
8f5054a131
commit
efdde5c316
3 files changed
+74
-1
No files matched your search
@@ -469,14 +469,32 @@ def _effective(a: argparse.Namespace, machine: bool) -> int:
|
||||
was, now = tune_knobs._current(before, flag), tune_knobs._current(after, flag)
|
||||
if was != now:
|
||||
changed.append({"flag": flag, "was": was, "now": now})
|
||||
from strata_control import arg_layers
|
||||
where = arg_layers.sources({**cfg, "args": after}, [c["flag"] for c in changed])
|
||||
payload = {"applied": bool(info.get("applied")), "preset": info.get("preset"), "state": info.get("state"), "reasons": info.get("reasons", []),
|
||||
"why_not": info.get("why_not"), "warnings": info.get("warnings") or [], "notice": info.get("notice"),
|
||||
"args": merged.get("args"), "env": merged.get("env") or {},
|
||||
"sampling": merged.get("sampling") or {}, "changed": changed, "per_request": info.get("per_request") or {}}
|
||||
"sampling": merged.get("sampling") or {}, "changed": changed, "per_request": info.get("per_request") or {}, "sources": where}
|
||||
human = (f"Using your tuning '{info['preset']['name']}'" if info.get("applied") else "No saved tuning is applied; the standard settings run.")
|
||||
human += "\n" + _sources_words(where, after)
|
||||
return _print(payload, machine, human)
|
||||
|
||||
|
||||
#: #5351 (text approved by the coordinator): the labels of `strata presets effective`
|
||||
SOURCE_WORDS = {"launch": "set in this start", "yours": "your own setting", "calibrated": "from your calibration", "tuned": "from your saved tuning"}
|
||||
|
||||
|
||||
def _sources_words(where: dict[str, str], args: list[str]) -> str:
|
||||
from strata_control import tune_knobs
|
||||
if not where:
|
||||
return "Every setting is chosen automatically."
|
||||
lines = ["Where your settings come from (everything not listed is chosen automatically):"]
|
||||
shown = [(f"{flag} {tune_knobs._current(args, flag) or ''}".rstrip(), SOURCE_WORDS[key]) for flag, key in where.items()]
|
||||
width = max(len(s) for s, _w in shown)
|
||||
lines += [f" {s.ljust(width)} {w}" for s, w in shown]
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def _off(a: argparse.Namespace, machine: bool) -> int:
|
||||
"""Switch the saved tuning off for these choices. It is kept (and listed), so switching it back on is one step."""
|
||||
from strata_control import presets
|
||||
|
||||
@@ -108,6 +108,31 @@ def layer(cfg: dict, explicit: Mapping[str, Any] | None = None, prev: Mapping[st
|
||||
"explicit": sorted(explicit)}
|
||||
|
||||
|
||||
#: the answer of ``sources`` for a flag no layer above "Auto" holds is simply not listed
|
||||
SOURCE_LAUNCH, SOURCE_YOURS, SOURCE_CALIBRATED, SOURCE_TUNED = "launch", "yours", "calibrated", "tuned"
|
||||
|
||||
|
||||
def sources(cfg: Mapping[str, Any], tuned_flags: Any = ()) -> dict[str, str]:
|
||||
"""Where each non-automatic option of a run config's ``"args"`` comes from (#5351): ``"launch"`` (this command line's own values), ``"yours"`` (the person's
|
||||
standing options: ``"user_args"``), ``"calibrated"`` (``engine calibrate --apply-result``), ``"tuned"`` (the active saved tuning, ``tuned_flags``). The
|
||||
same order as ``layer``; an option none of them holds is the generated one and is not listed. Read-only."""
|
||||
flags = [user_args.flag_of(g) for g in user_args.groups(cfg.get("args"))]
|
||||
explicit = {str(f) for f in cfg.get(EXPLICIT_KEY) or []}
|
||||
mine = {user_args.flag_of(g) for g in user_args.groups(cfg.get(user_args.USER_KEY))}
|
||||
rec = cfg.get(CALIBRATED_KEY)
|
||||
calibrated = {str(k) for k in (rec.get("settings") or {})} if isinstance(rec, dict) and _calibration_fits(rec, cfg) else set()
|
||||
tuned = {str(f) for f in tuned_flags}
|
||||
out: dict[str, str] = {}
|
||||
for flag in flags:
|
||||
if not flag or flag in out:
|
||||
continue
|
||||
for key, held in ((SOURCE_LAUNCH, explicit), (SOURCE_YOURS, mine), (SOURCE_CALIBRATED, calibrated), (SOURCE_TUNED, tuned)):
|
||||
if flag in held:
|
||||
out[flag] = key
|
||||
break
|
||||
return out
|
||||
|
||||
|
||||
def stamp(cfg: dict) -> None:
|
||||
"""Called by the launch after its last change to ``cfg["args"]``: records them as written, so only a later hand edit differs."""
|
||||
written = [str(a) for a in cfg.get("args") or []]
|
||||
|
||||
@@ -80,6 +80,36 @@ class PersistenceTest(unittest.TestCase):
|
||||
self.assertEqual(out["changed"], [{"flag": "--kv-resident", "was": "32768", "now": "65536"}])
|
||||
self.assertEqual(out["args"][out["args"].index("--kv-resident") + 1], "65536")
|
||||
|
||||
def with_choices(self):
|
||||
"""The saved run config of a launch: this start set --max-context, the person's own --spec, the saved tuning's --kv-resident."""
|
||||
self.cfg_path.write_text(json.dumps({**self.cfg, "user_args": ["--spec", "4"], "launch_set": ["--max-context"]}))
|
||||
|
||||
def test_effective_says_where_each_setting_comes_from(self):
|
||||
self.with_choices()
|
||||
out, _ = cli(self.env, "presets", "effective", str(self.cfg_path))
|
||||
self.assertEqual(out["sources"], {"--max-context": "launch", "--spec": "yours", "--kv-resident": "tuned"})
|
||||
human = subprocess.run([sys.executable, str(ROOT / "strata.py"), "presets", "effective", str(self.cfg_path)], capture_output=True, text=True,
|
||||
env=self.env, cwd=str(ROOT), timeout=120).stdout
|
||||
self.assertIn("Where your settings come from (everything not listed is chosen automatically):", human)
|
||||
for line in ("--max-context 65536", "set in this start", "--spec 4", "your own setting", "--kv-resident 65536", "from your saved tuning"):
|
||||
self.assertIn(line, human)
|
||||
|
||||
def test_effective_without_any_own_setting_says_everything_is_automatic(self):
|
||||
cli(self.env, "presets", "off", str(self.cfg_path))
|
||||
out, _ = cli(self.env, "presets", "effective", str(self.cfg_path))
|
||||
self.assertEqual(out["sources"], {})
|
||||
human = subprocess.run([sys.executable, str(ROOT / "strata.py"), "presets", "effective", str(self.cfg_path)], capture_output=True, text=True,
|
||||
env=self.env, cwd=str(ROOT), timeout=120).stdout
|
||||
self.assertIn("Every setting is chosen automatically.", human)
|
||||
|
||||
def test_a_calibrated_value_is_named_and_yours_beats_it(self):
|
||||
from strata_control import arg_layers
|
||||
cfg = {"model_name": "m", "args": ["--max-context", "65536", "--prefill", "8192", "--spec", "6"], "user_args": ["--spec", "6"],
|
||||
"calibrated": {"settings": {"--prefill": "8192", "--spec": "5"}, "model_name": "m", "max_context": "65536", "images": False}}
|
||||
self.assertEqual(arg_layers.sources(cfg), {"--spec": "yours", "--prefill": "calibrated"})
|
||||
cfg["calibrated"]["model_name"] = "another model" # measured for another model: not this config's
|
||||
self.assertEqual(arg_layers.sources(cfg), {"--spec": "yours"})
|
||||
|
||||
def test_which_tuning_is_in_use_and_switching_it_off_and_on(self):
|
||||
st, _ = cli(self.env, "presets", "status", str(self.cfg_path))
|
||||
self.assertEqual(st["active"]["name"], "IQ3_S 64K – Work")
|
||||
|
||||
Reference in new issue
Block a user