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++
Presets: a value outside the range the tuner tries is kept with a warning, not dropped (#3844)
Niko1221e0d47034df1e
diff --git a/serve/server.py b/serve/server.pyindex 76b5a2c79..ddbc435dc 100644--- a/serve/server.py+++ b/serve/server.py@@ -7883,6 +7883,8 @@ def apply_saved_tuning(cfg: dict, *, say=None) -> dict:say(f"[strata] saved tuning '{applied['preset']['name']}' applied: "f"{' '.join(f'{k} {v}' for k, v in changes.items()) or 'the standard settings (nothing to change)'}"f"{'; ' + note if note and 'identical' not in note else ''}")+ for warning in applied.get("warnings") or []: # #3844: outside the range the tuner tries, kept+ say(f"[strata] warning: {warning}")if applied.get("state") == "soft":say("[strata] this PC or engine changed since it was saved (" + "; ".join(applied["reasons"]) +"): a short re-check is available (strata presets recheck)")diff --git a/strata_cli/tune_commands.py b/strata_cli/tune_commands.pyindex 83f95e5af..758badef5 100644--- a/strata_cli/tune_commands.py+++ b/strata_cli/tune_commands.py@@ -372,7 +372,8 @@ def _effective(a: argparse.Namespace, machine: bool) -> int:if was != now:changed.append({"flag": flag, "was": was, "now": now})payload = {"applied": bool(info.get("applied")), "preset": info.get("preset"), "state": info.get("state"), "reasons": info.get("reasons", []),- "why_not": info.get("why_not"), "notice": info.get("notice"), "args": merged.get("args"), "env": merged.get("env") or {},+ "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 {}}human = (f"Using your tuning '{info['preset']['name']}'" if info.get("applied") else "No saved tuning is applied; the standard settings run.")return _print(payload, machine, human)diff --git a/strata_control/presets.py b/strata_control/presets.pyindex 2ab4f0016..27446803a 100644--- a/strata_control/presets.py+++ b/strata_control/presets.py@@ -269,9 +269,10 @@ def create(result: dict[str, Any], *, choices: dict[str, Any], identity: dict[stmode: str = "quick", activate: bool = True, base_args: dict[str, Any] | None = None) -> dict[str, Any]:"""Save a tune result as a named preset (active at once unless ``activate`` is False)."""settings = result.get("settings") or {"args": {}, "env": {}, "per_request": {}}- problems = tune_knobs.check_setting(settings.get("args") or {}, settings.get("env") or {},- tune_knobs.Context(context_tokens=choices.get("context") or 32768,- family=choices.get("family") or "flash-next"))+ # (a value only outside the tuner's tested range is kept, #3844; the never list still refuses)+ problems, _outside = tune_knobs.check_setting_parts(settings.get("args") or {}, settings.get("env") or {},+ tune_knobs.Context(context_tokens=choices.get("context") or 32768,+ family=choices.get("family") or "flash-next"))if problems:raise PresetError("these settings are outside the safe rules and cannot be saved: " + "; ".join(problems))base = result.get("base") or {}@@ -396,8 +397,10 @@ def export_preset(ref: str) -> dict[str, Any]:def import_preset(data: dict[str, Any]) -> dict[str, Any]:if not isinstance(data, dict) or data.get("schema") != SCHEMA:raise PresetError("that file is not a Strata preset")- problems = tune_knobs.check_setting((data.get("settings") or {}).get("args") or {}, (data.get("settings") or {}).get("env") or {},- tune_knobs.Context(context_tokens=(data.get("choices") or {}).get("context") or 32768))+ # (a value only outside the tuner's tested range is kept, #3844; the never list still refuses)+ problems, _outside = tune_knobs.check_setting_parts((data.get("settings") or {}).get("args") or {},+ (data.get("settings") or {}).get("env") or {},+ tune_knobs.Context(context_tokens=(data.get("choices") or {}).get("context") or 32768))if problems:raise PresetError("the preset has settings outside the safe rules: " + "; ".join(problems))data = dict(data)@@ -442,7 +445,8 @@ def overlay(cfg: dict[str, Any], *, now: dict[str, Any] | None = None, use: str"""The run configuration with the active preset for its choices put on top, and what was done.No measurement happens here. A preset whose identity changed in a *hard* way is not applied (it says why); a *soft* change- applies it and marks it for a re-check. A setting that is outside the safe rules is left out, never applied. Never raises:+ applies it and marks it for a re-check. A setting on the never list (measured harmful) is left out, never applied; one+ that is only outside the range the tuner tries is kept and listed in ``info["warnings"]``. Never raises:a store that cannot be read means "no preset", and the engine starts with the configuration as it is."""info: dict[str, Any] = {"applied": False}try:@@ -462,10 +466,12 @@ def overlay(cfg: dict[str, Any], *, now: dict[str, Any] | None = None, use: strreturn cfg, infos = preset.get("settings") or {}ctx = tune_knobs.Context(context_tokens=choices.get("context") or 32768, family=choices.get("family") or "flash-next")- problems = tune_knobs.check_setting(s.get("args") or {}, s.get("env") or {}, ctx)+ problems, outside = tune_knobs.check_setting_parts(s.get("args") or {}, s.get("env") or {}, ctx)if problems:info["why_not"] = "not applied: " + "; ".join(problems)return cfg, info+ if outside: # #3844: a value outside the range the tuner tries was chosen by the user: kept, with a warning+ info["warnings"] = tune_knobs.keep_warnings(outside)out = json.loads(json.dumps(cfg))out["args"] = tune_knobs.apply_to_argv([str(a) for a in out.get("args") or []], s.get("args") or {})if s.get("env"):diff --git a/strata_control/tune_knobs.py b/strata_control/tune_knobs.pyindex 54f27f723..93530ddf9 100644--- a/strata_control/tune_knobs.py+++ b/strata_control/tune_knobs.py@@ -260,7 +260,17 @@ def _prefill_below_auto(value: Any) -> bool:def check_setting(args: dict[str, Any], env: dict[str, str | None], ctx: Context) -> list[str]:"""Reasons (plain words) a setting must not be applied; an empty list means it is inside the rules.- ``args`` maps flag -> value (True for a present boolean flag); ``env`` maps name -> value."""+ ``args`` maps flag -> value (True for a present boolean flag); ``env`` maps name -> value. The tuner uses this whole+ list for what it tries; a saved or imported preset uses `check_setting_parts` (see there)."""+ never, bounds = check_setting_parts(args, env, ctx)+ return never + bounds+++def check_setting_parts(args: dict[str, Any], env: dict[str, str | None], ctx: Context) -> tuple[list[str], list[str]]:+ """(never, bounds): `never` are the settings measured to be harmful (the never list: slower, unsafe, or changing the+ numbers); `bounds` are values outside the range the tuner tried (``--spec 5``, ``--pcie-frac 0.6``), which nobody+ measured as bad. A preset keeps a user's setting that is only outside the tested range, with a warning (#3844); the+ tuner itself never tries one."""problems: list[str] = []ctx_tokens = ctx.context_tokensdefault_workers = ctx.facts.get("workers")@@ -314,6 +324,7 @@ def check_setting(args: dict[str, Any], env: dict[str, str | None], ctx: Contexthit = n is not None and (n == 0 or n >= 4)if hit:problems.append(f"{flag} {value}: {rule['reason']}")+ bound_problems: list[str] = []for flag, value in args.items():bound = BOUNDS.get(flag)if not bound or value is None or value is True:@@ -321,13 +332,18 @@ def check_setting(args: dict[str, Any], env: dict[str, str | None], ctx: Contextif bound.get("numeric_only") and _as_number(value) is None:continueif "choices" in bound and value not in bound["choices"] and str(value) not in [str(c) for c in bound["choices"]]:- problems.append(f"{flag} {value}: outside the safe values {list(bound['choices'])}")+ bound_problems.append(f"{flag} {value}: outside the safe values {list(bound['choices'])}")n = _as_number(value)if n is not None and "min" in bound and n < bound["min"]:- problems.append(f"{flag} {value}: below the safe minimum {bound['min']}")+ bound_problems.append(f"{flag} {value}: below the safe minimum {bound['min']}")if n is not None and "max" in bound and n > bound["max"]:- problems.append(f"{flag} {value}: above the safe maximum {bound['max']}")- return problems+ bound_problems.append(f"{flag} {value}: above the safe maximum {bound['max']}")+ return problems, bound_problems+++def keep_warnings(bound_problems: Sequence[str]) -> list[str]:+ """The short warning for each setting that is outside the tested range and is kept (#3844): said, never dropped."""+ return [f"{p.split(': ', 1)[0]}: not tried by the tuner, kept because it is your setting" for p in bound_problems]def _flags_of(argv: Sequence[str]) -> set[str]:diff --git a/tests/tuning/test_autotune.py b/tests/tuning/test_autotune.pyindex 2efd9556e..533c8bc84 100644--- a/tests/tuning/test_autotune.py+++ b/tests/tuning/test_autotune.py@@ -60,6 +60,7 @@ class RulesTest(unittest.TestCase):ctx = make_ctx(arch="gfx1201")bad = [({"--expert-cache": 0}, {}), ({"--kv-resident": 20480}, {}), ({"--pcie-frac": 0.75}, {}),({"--spec": 6}, {}), ({"--spec": 2}, {}), ({"--lookup-chain": 4}, {}), ({"--adapt-every": 100000}, {}),+ ({"--spec": 5}, {}), # outside the tuner's values: still not tried (a saved preset may keep it, #3844)({"--prefill": 512}, {}), ({"--ple-io": "ram"}, {}), ({}, {"STRATA_SH_STREAM": "1"}),({}, {"STRATA_RDNA2_SGEMM": "all"}), ({}, {"STRATA_HIP_WMMA": "1"}), ({"--pool-workers": 8}, {})]for args, env in bad:diff --git a/tests/tuning/test_presets.py b/tests/tuning/test_presets.pyindex 98b6db06a..9bdbebaf5 100644--- a/tests/tuning/test_presets.py+++ b/tests/tuning/test_presets.py@@ -10,7 +10,7 @@ import timeimport unittestfrom pathlib import Path-from strata_control import presets+from strata_control import presets, tune_knobsCFG = {"exe": "strata", "model_name": "swift-iq2_xs", "ui_resource_profile": "work", "vram_reserve_mib": 1536,"args": ["--pack", "P", "--native", "Swift-IQ3_S-00001-of-00002.gguf", "--expert-cache", "auto", "--prefill", "auto",@@ -83,6 +83,39 @@ class StoreTest(unittest.TestCase):with self.assertRaises(presets.PresetError):self.make(result=bad)+ def test_a_value_outside_the_tested_range_is_kept_with_a_warning(self):+ # #3844: --spec 5 is not a value the tuner tries (its safe values are 3 and 4), but nobody measured it as bad on every+ # card; a user who chose it keeps it, and is told once. The never list (--spec 6, --expert-cache 0 ...) still refuses.+ res = copy.deepcopy(RESULT)+ res["settings"]["args"] = {"--spec": 5}+ self.make(result=res) # saved, not refused+ out, info = presets.overlay(CFG, now=identity())+ self.assertTrue(info["applied"], info)+ self.assertEqual(tune_knobs._current(out["args"], "--spec"), "5")+ self.assertEqual(info["warnings"], ["--spec 5: not tried by the tuner, kept because it is your setting"])+ self.assertNotIn("why_not", info)+ self.assertEqual(tune_knobs._current(CFG["args"], "--spec"), "4") # the input is not modified+ # an in-range preset has no warnings+ presets.delete(presets.list_presets()[0]["id"])+ self.make()+ _, info2 = presets.overlay(CFG, now=identity())+ self.assertTrue(info2["applied"])+ self.assertNotIn("warnings", info2)++ def test_the_never_list_still_refuses_but_a_range_does_not(self):+ ctx = tune_knobs.Context()+ never, bounds = tune_knobs.check_setting_parts({"--spec": 5, "--pcie-frac": 0.6}, {}, ctx)+ self.assertEqual(never, [])+ self.assertEqual(len(bounds), 2)+ never, bounds = tune_knobs.check_setting_parts({"--spec": 6}, {}, ctx)+ self.assertTrue(never and bounds) # slower (never list) and outside the values+ # the tuner's own check is the two lists together, in the same order as before+ self.assertEqual(tune_knobs.check_setting({"--spec": 6}, {}, ctx), never + bounds)+ bad = copy.deepcopy(RESULT)+ bad["settings"]["args"] = {"--spec": 6}+ with self.assertRaises(presets.PresetError):+ self.make(result=bad)+def test_overlay_applies_the_active_preset_without_measuring(self):self.make()out, info = presets.overlay(CFG, now=identity())@@ -154,6 +187,8 @@ class StoreTest(unittest.TestCase):data["settings"]["args"] = {"--spec": 6}with self.assertRaises(presets.PresetError):presets.import_preset(data)+ data["settings"]["args"] = {"--spec": 5} # #3844: only outside the tuner's range: kept+ self.assertEqual(presets.import_preset(data)["settings"]["args"], {"--spec": 5})def test_recheck_keep_refreshes_the_identity(self):p = self.make()