From bc1a3ba2ed14715330cc24de02f26ed9d5ce553c Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Sat, 24 Oct 2026 16:33:51 +0200 Subject: [PATCH] launch: DeepSeek Speed choice, Faster (--experts 5, the default on a PC with 16 GB of graphics memory or less) or Full quality (--experts 6): a Speed step in the guided screens, --speed and --full-quality, plain words in --plan and the summary, the quality note; tests, docs --- docs/DEEPSEEK41.md | 6 + strata_cli/launch/app.py | 4 +- strata_cli/launch/catalog.py | 5 + strata_cli/launch/cmd.py | 22 +++- strata_cli/launch/runner.py | 53 ++++++++- strata_cli/launch/screens.py | 48 +++++++- strata_cli/launch/settings.py | 20 ++++ tests/terminal/test_launch_speed.py | 163 ++++++++++++++++++++++++++++ 8 files changed, 313 insertions(+), 8 deletions(-) create mode 100644 tests/terminal/test_launch_speed.py diff --git a/docs/DEEPSEEK41.md b/docs/DEEPSEEK41.md index 14099136..a6041d6a 100644 --- a/docs/DEEPSEEK41.md +++ b/docs/DEEPSEEK41.md @@ -88,6 +88,12 @@ The server speaks to the engine as it does for the other models, so `/v1/chat/co Not in this version: several requests at once (`--parallel` is ignored with a warning) and pictures (`--vision` is ignored with a warning). +## Speed: Faster or Full quality + +DeepSeek picks 6 experts for every word it writes. **Faster** uses 5 of them (engine flag `--experts 5`): a small quality change, usually not noticeable, and answers come sooner. It is the default on a PC with 16 GB of graphics memory or less. **Full quality** uses all 6 (`--experts 6`). + +In `strata launch` the guided screens have a Speed step for DeepSeek; with flags use `--speed faster|full`, or `--full-quality` in scripts. `strata launch --plan` shows which one this PC gets. + ## Tuning `strata launch --tune quick` (or `thorough`, or the Tuning screen) works for DeepSeek with its own short tuner, `tools/dsv41/tune.py`. It starts diff --git a/strata_cli/launch/app.py b/strata_cli/launch/app.py index 058239ed..f27dab0e 100644 --- a/strata_cli/launch/app.py +++ b/strata_cli/launch/app.py @@ -24,11 +24,11 @@ from strata_cli.launch import store from strata_cli.launch.catalog import Catalog from strata_cli.launch.runner import Cancelled, Event, LaunchError, Result, Runner, read_config from strata_cli.launch.screens import (AccessScreen, AdvancedScreen, CardsScreen, ConfirmScreen, ContextScreen, FolderScreen, - ModelScreen, ParallelScreen, PicturesScreen, RunScreen, SaveScreen, StartScreen, + ModelScreen, ParallelScreen, PicturesScreen, RunScreen, SaveScreen, SpeedScreen, StartScreen, TuningScreen, flow_for) from strata_cli.launch.widgets import CSS, Glyphs -SCREENS = {"model": ModelScreen, "cards": CardsScreen, "folder": FolderScreen, "context": ContextScreen, "pictures": PicturesScreen, +SCREENS = {"model": ModelScreen, "cards": CardsScreen, "folder": FolderScreen, "context": ContextScreen, "pictures": PicturesScreen, "speed": SpeedScreen, "parallel": ParallelScreen, "tuning": TuningScreen, "advanced": AdvancedScreen, "access": AccessScreen, "save": SaveScreen} diff --git a/strata_cli/launch/catalog.py b/strata_cli/launch/catalog.py index 9f8e9359..ef943d2c 100644 --- a/strata_cli/launch/catalog.py +++ b/strata_cli/launch/catalog.py @@ -151,6 +151,11 @@ class Computer: "If something fails, start again with --vision off to turn pictures off, and tell us at https://github.com/Niko1221/Strata/issues (say it is a B-series card and attach the engine log).") return None + @property + def total_vram_gb(self) -> float: + """The graphics memory of all the cards that can be used together.""" + return sum(float(g.get("vram_gb") or 0) for g in self.usable_gpus) + @property def main_vram_gb(self) -> float: return max((float(g.get("vram_gb") or 0) for g in self.usable_gpus), default=0.0) diff --git a/strata_cli/launch/cmd.py b/strata_cli/launch/cmd.py index 8df981b9..97834ddc 100644 --- a/strata_cli/launch/cmd.py +++ b/strata_cli/launch/cmd.py @@ -105,6 +105,10 @@ def add_parsers(sp: argparse._SubParsersAction) -> list[argparse.ArgumentParser] help="which drafter guesses words ahead to make answers faster: auto (recommended: Strata picks from what it measured on cards like yours; " "that is the MTP today), mtp, dflash2 (Qwen3.8-Flash-Next only; downloads a 1.2 GB drafter once) or off. If DFlash2 cannot run " "(not enough graphics memory, or a model it is not for) the MTP is used and the start says why") + g.add_argument("--speed", type=_choice("a speed", S.SPEED_MODES), metavar="faster|full", + help="DeepSeek: faster uses 5 of 6 experts per word (a small quality change, usually not noticeable; the default on a PC with 16 GB " + "of graphics memory or less), full uses all 6") + g.add_argument("--full-quality", action="store_true", help="DeepSeek: all 6 experts per word (the same as --speed full), for scripts") g.add_argument("--gpu", metavar="LIST", help="graphics card numbers to use, e.g. 0 or 0,1 (default: the engine's choice)") g.add_argument("--gpu-roles", metavar="LIST", help="a role for each graphics card: main, helper or off, e.g. 1=main,0=helper (cards you do not name are off). " "Main does the last steps of every answer; a helper holds part of the model") @@ -233,6 +237,12 @@ def settings_from_args(a: argparse.Namespace, catalog=None) -> tuple[S.LaunchSet s.mtp = a.mtp if a.drafting: s.drafting = a.drafting + if getattr(a, "full_quality", False): + if getattr(a, "speed", None) == "faster": + notices.append(S.Notice("warn", "--full-quality and --speed faster were both given; full quality is used.", "")) + s.speed = "full" + elif getattr(a, "speed", None): + s.speed = a.speed if a.gpu and getattr(a, "gpu_roles", None): raise ValueError("Use --gpu (which cards) or --gpu-roles (a role for each card), not both.") if a.gpu: @@ -337,6 +347,9 @@ def apply_defaults(s: S.LaunchSettings, catalog) -> tuple[S.LaunchSettings, list if s.vision not in (None, "off"): notices.append(S.Notice("warn", "DeepSeek-V4.1-Flash cannot read pictures in this Strata version, so pictures are off.", "")) s.vision = "off" # (tuning is DeepSeek's own short tune: tools/dsv41/tune.py, run by the launch) + elif s.speed: + notices.append(S.Notice("warn", "--speed and --full-quality are for DeepSeek; this model uses all its experts, so they are not used.", "")) + s.speed = None notices += S.check_context(s, max_fit_tokens=None) if s.access != "local" and not s.api_key and not s.no_key: from strata_cli.launch import access @@ -694,7 +707,7 @@ def run_launch(a: argparse.Namespace) -> int: s, notices = settings_from_args(a, catalog) if not machine: _interrupted_move_notice() - have_choices = bool(a.preset or a.model or a.model_path or a.context or a.vision or a.parallel or a.access or a.tune or a.drafting) + have_choices = bool(a.preset or a.model or a.model_path or a.context or a.vision or a.parallel or a.access or a.tune or a.drafting or getattr(a, "speed", None) or getattr(a, "full_quality", False)) interactive = sys.stdin.isatty() and sys.stdout.isatty() and not a.no_tui and not machine and not a.plan plain_questions = False no_screens_package = None @@ -756,6 +769,8 @@ def run_launch(a: argparse.Namespace) -> int: _say(f" download {(plan.get('download') or {}).get('text', '')}") if plan.get("drafting"): _say(f" drafting {plan['drafting'].replace('Drafting: ', '', 1)}") + if plan.get("speed"): + _say(f" speed {plan['speed'].replace('Speed: ', '', 1)}") _placement_lines(plan.get("placement")) _say(f" tuning {s.tune} access {S.ACCESS_WORDS[s.access]}, port {s.port}" + (" API key on" if s.api_key else "")) @@ -824,6 +839,11 @@ def run_launch(a: argparse.Namespace) -> int: from strata_cli.launch import access _say(f" {'API key':<14} {access.mask_key(result.key)} (show it: strata launch --show-key" + (f" --preset \"{s.name}\")" if (a.preset or a.save_preset) else ")")) + speed_line = runner.speed_line() if hasattr(runner, "speed_line") else "" + if speed_line and not isinstance(speed_line, str): + speed_line = "" + if speed_line: + _say(f" {'Speed':<14} {speed_line.replace('Speed: ', '', 1)}") engine_log = _engine_log_of(result.config) if engine_log: _say(f" {'Engine log':<14} {engine_log} (follow it: strata logs --follow)") diff --git a/strata_cli/launch/runner.py b/strata_cli/launch/runner.py index 73f4d180..11ccfa7c 100644 --- a/strata_cli/launch/runner.py +++ b/strata_cli/launch/runner.py @@ -398,7 +398,25 @@ def cards_for_launch(s: S.LaunchSettings, catalog, ram_gb: float | None = None, return None -def derive_config(base: dict, s: S.LaunchSettings, *, bool_flags: frozenset[str], log: str | None = None, gpus: "list[int] | dict | None" = None) -> dict: +def apply_experts(cfg: dict, experts: int | None) -> None: + """DeepSeek's speed choice as the engine flag: --experts 5 (Faster) or --experts 6 (Full quality), replacing one already in the saved args.""" + if experts is None or not isinstance(cfg.get("args"), list): + return + args, out, i = [str(x) for x in cfg["args"]], [], 0 + while i < len(args): + if args[i] == "--experts": + i += 2 + continue + if args[i].startswith("--experts="): + i += 1 + continue + out.append(args[i]) + i += 1 + cfg["args"] = out + ["--experts", str(int(experts))] + + +def derive_config(base: dict, s: S.LaunchSettings, *, bool_flags: frozenset[str], log: str | None = None, gpus: "list[int] | dict | None" = None, + experts: int | None = None) -> dict: """The private run config of this launch: the installed one plus the choices that are not setup's (host, port, key, cards, advanced).""" from strata_control import tune_knobs cfg = json.loads(json.dumps(base)) @@ -434,6 +452,7 @@ def derive_config(base: dict, s: S.LaunchSettings, *, bool_flags: frozenset[str] cfg["env"] = tune_knobs.apply_to_env(dict(cfg.get("env") or {}), e_changes) from strata_control import draft_layer draft_layer.apply(cfg) # "mtp": false (from the installed config too) never sits beside --mtp in the saved args (B10) + apply_experts(cfg, experts) return cfg @@ -1284,7 +1303,8 @@ class Runner: from strata_control import tune_knobs base = read_config(base_path) cfg = derive_config(base, self.s, bool_flags=tune_knobs.BOOL_FLAGS, - log=str(launch_dir() / f"{self.name}.engine.log"), gpus=cards_for_launch(self.s, self.catalog, base=base)) + log=str(launch_dir() / f"{self.name}.engine.log"), gpus=cards_for_launch(self.s, self.catalog, base=base), + experts=self.experts_flag()) self.use_own_dsv41_engine(cfg) wait = self.start_wait() if wait > 600 and not cfg.get("engine_ready_s"): # the server's own wait for the engine (900 s) must not end before the start's @@ -1894,11 +1914,38 @@ class Runner: model = {"title": title, "family": s.family, "model": s.model, "model_gb": row.download_gb if row is not None else None, "own_files": bool(s.model_path), "folder": s.model_path} out = {"profile": self.profile, "settings": s.to_dict(with_key=False), "warnings": warns, - "flags": S.flags_text(s), "steps": list(STAGES), "model": model, "download": download, "drafting": self.drafting_plan_line()} + "flags": S.flags_text(s), "steps": list(STAGES), "model": model, "download": download, "drafting": self.drafting_plan_line(), + "speed": self.speed_line()} if self.multi_file(): out["placement"] = self.placement() return out + def resolved_speed(self) -> tuple[str, bool] | None: + """DeepSeek's speed: ("faster" | "full", whether it is the default for this PC); None for any other model. Faster is the default on a PC + with 16 GB of graphics memory or less.""" + if not self.multi_file(): + return None + try: + default = S.faster_default(self.catalog.computer().total_vram_gb) + except Exception: # noqa: BLE001 - when the cards cannot be read, the engine's own default stands + default = False + if self.s.speed in S.SPEED_MODES: + return self.s.speed, (self.s.speed == "faster") == default + return ("faster" if default else "full"), True + + def experts_flag(self) -> int | None: + """The value of the engine's --experts for this launch (5 or 6), None for a model that has no such choice.""" + speed = self.resolved_speed() + return None if speed is None else (5 if speed[0] == "faster" else 6) + + def speed_line(self) -> str: + """The speed line of --plan and of the summary, in plain words, with the quality note when it is Faster.""" + speed = self.resolved_speed() + if speed is None: + return "" + text = "Speed: " + S.speed_words(speed[0], speed[1]) + return text + (". " + S.FASTER_NOTE if speed[0] == "faster" else "") + def drafting_plan_line(self) -> str: """The drafting line of --plan: what drafts, or why not what was asked for. Nothing is changed or downloaded.""" from strata_control import drafting diff --git a/strata_cli/launch/screens.py b/strata_cli/launch/screens.py index a17bbd54..c2bfa413 100644 --- a/strata_cli/launch/screens.py +++ b/strata_cli/launch/screens.py @@ -30,11 +30,16 @@ STEPS = (("model", "Model"), ("cards", "Cards"), ("folder", "Folder"), ("context ("parallel", "Parallel"), ("tuning", "Tuning"), ("advanced", "Advanced"), ("access", "Access"), ("save", "Save")) +STEP_LABELS = {**dict(STEPS), "speed": "Speed"} + + def flow_for(ctx) -> list[str]: - """The steps of this computer: the Cards step exists only when two or more graphics cards can be used.""" + """The steps of this computer: the Cards step exists only when two or more graphics cards can be used; the Speed step only for DeepSeek.""" ids = [sid for sid, _ in STEPS] if len(ctx.computer.usable_gpus) < 2: ids.remove("cards") + if getattr(ctx.settings, "family", None) == "deepseek41": + ids.insert(ids.index("context") + 1, "speed") return ids @@ -111,7 +116,7 @@ class Base(Screen): out.append("STRATA ", style=f"bold {ACCENT}") out.append(f"{self.title_line}", style=f"bold {ACCENT}") if self.step_id in flow: - labels = dict(STEPS) + labels = STEP_LABELS n = flow.index(self.step_id) if self.width() >= 118: out.append(" ") @@ -1023,6 +1028,43 @@ class PicturesScreen(Base): self.ctx.settings.vision = key +# ------------------------------------------------------------------------------------------------ DeepSeek: speed + +class SpeedScreen(Base): + step_id = "speed" + help_text = ("DeepSeek picks 6 experts for every word it writes. Faster uses 5 of them: answers come sooner, with a small quality change that is " + "usually not noticeable. Full quality uses all 6. Faster is the default on a PC with 16 GB of graphics memory or less.") + + def body(self) -> ComposeResult: + yield Static(Text("Speed or full quality?", style=f"bold {ACCENT}"), markup=False) + yield Menu(id="menu") + + def default_faster(self) -> bool: + return S.faster_default(self.ctx.computer.total_vram_gb) + + def on_mount(self) -> None: + s = self.ctx.settings + faster_default = self.default_faster() + here = Cell("default on this PC", "") + items = [Item(["Faster", here if faster_default else Cell("", "")], key="faster"), + Item(["Full quality", here if not faster_default else Cell("", "")], key="full")] + sel = 0 if (s.speed or ("faster" if faster_default else "full")) == "faster" else 1 + self.query_one(Menu).columns = [("", 24), ("", 0)] + self.query_one(Menu).set_items(items, sel) + self.paint() + + def explain(self) -> Text: + key = self.menu().current.key if self.menu() and self.menu().current else "faster" + if key == "faster": + return Text(S.FASTER_NOTE + " It is the default on a PC with 16 GB of graphics memory or less.", style=MUTE) + return Text("Full quality uses all 6 experts per word. Answers are a little slower; pick it when the last bit of quality matters more.", style=MUTE) + + def commit(self) -> None: + key = self.menu().current.key + default = "faster" if self.default_faster() else "full" + self.ctx.settings.speed = None if key == default else key # the default stays "the default for this PC" in a saved preset + + # ------------------------------------------------------------------------------------------------ 6 parallel class ParallelScreen(Base): @@ -1492,6 +1534,8 @@ class SaveScreen(Base): lines = [("Model", (r.title if r else (s.model or "?")) + (" (your files)" if s.model_path else "")), ("Context", S.context_label(s.context) + f", memory {s.kv or 'int8'}"), ("Pictures", "on" if s.vision != "off" else "off"), + *([("Speed", S.speed_words(s.speed or ("faster" if S.faster_default(self.ctx.computer.total_vram_gb) else "full"), + s.speed is None))] if s.family == "deepseek41" else []), ("Parallel", f"{s.parallel} at a time" if s.parallel else f"fit to your card ({S.fit_parallel(self.ctx.computer.main_vram_gb)})"), ("Tuning", ({"quick": "quick (about 5-10 min)", "thorough": "thorough (about 10-15 min)", "skip": "skipped"} if s.family == "deepseek41" else {"quick": "quick (about 20 min)", "thorough": "thorough (up to 2 h)", "skip": "skipped"})[s.tune]), diff --git a/strata_cli/launch/settings.py b/strata_cli/launch/settings.py index dd175f28..92b088df 100644 --- a/strata_cli/launch/settings.py +++ b/strata_cli/launch/settings.py @@ -28,6 +28,21 @@ VISION_MODES = ("off", "on", "gpu", "cpu") MTP_MODES = ("on", "off") #: strata_control/drafting.py MODES (tests/terminal/test_drafting.py keeps the two the same) DRAFTING_MODES = ("auto", "mtp", "dflash2", "off") +SPEED_MODES = ("faster", "full") # DeepSeek: 5 experts per word (Faster) or all 6 (Full quality) +FASTER_VRAM_GB = 16.5 # Faster is the default on a PC with this much graphics memory or less (the owner's 0.2.4.3 decision) +FASTER_NOTE = "Faster uses 5 of 6 experts per word: a small quality change, usually not noticeable." + + +def faster_default(total_vram_gb: float | None) -> bool: + """Faster is the default on a PC with 16 GB of graphics memory or less, in all (the cards that can be used together).""" + return bool(total_vram_gb) and float(total_vram_gb) <= FASTER_VRAM_GB + + +def speed_words(speed: str, default: bool) -> str: + """The plain words for the chosen speed, for --plan and the summary.""" + if speed == "faster": + return "Faster" + (" (default on this PC)" if default else "") + return "Full quality" + (" (default on this PC)" if default else "") + ": all 6 experts per word" KV_MODES = ("int8", "q4_0", "k8v4", "fp16") DEFAULT_PORT = 8080 @@ -90,6 +105,7 @@ class LaunchSettings: kv: str | None = None # None = int8 above 8K, as setup vision: str | None = None # None = the default (on when the model can read pictures and the engine has the reader), off | on | gpu | cpu parallel: int | None = None # None = fit to the card + speed: str | None = None # DeepSeek only: None = the default for this PC (faster up to 16 GB of graphics memory); faster | full drafting: str | None = None # None = Auto (recommended): the table in strata_control/drafting.py; mtp | dflash2 | off choose one. Saved in the launch config mtp: str | None = None # None = as installed (draft layer on); "off" starts without it (less graphics memory and RAM, slower); "on" overrides an installed "off" tune: str = "skip" # quick | thorough | skip @@ -293,6 +309,10 @@ def flags_text(s: LaunchSettings, *, preset: str | None = None) -> str: parts.append(f"--mtp {s.mtp}") if s.drafting: parts.append(f"--drafting {s.drafting}") + if s.speed == "full": + parts.append("--full-quality") + elif s.speed == "faster": + parts.append("--speed faster") parts.append(f"--tune {s.tune}") if s.tune_allow_small: parts.append("--tune-allow-small") diff --git a/tests/terminal/test_launch_speed.py b/tests/terminal/test_launch_speed.py new file mode 100644 index 00000000..557f8d6b --- /dev/null +++ b/tests/terminal/test_launch_speed.py @@ -0,0 +1,163 @@ +"""DeepSeek's speed choice (0.2.4.3): Faster (--experts 5, the default on a PC with 16 GB of graphics memory or less) or Full quality (--experts 6).""" + +from __future__ import annotations + +import asyncio +import json +import unittest +from unittest import mock + +from strata_cli.launch import settings as S +from strata_cli.launch.app import LaunchApp +from strata_cli.launch.runner import Runner, apply_experts, derive_config +from strata_cli.launch.screens import SpeedScreen, flow_for +from tests.terminal import test_launch as TL +from tests.terminal.launch_support import Home, text_of +from tests.terminal.test_launch_tui import SIZE, make_ctx, press + +run_cli = TL.run_cli + + +class Words(unittest.TestCase): + def test_the_default_is_faster_up_to_16_gb_of_graphics_memory(self): + for gb in (8, 12, 15.9, 16, 16.4): + self.assertTrue(S.faster_default(gb), gb) + for gb in (20, 24, 48, 0, None): + self.assertFalse(S.faster_default(gb), gb) + + def test_plain_words_and_the_quality_note(self): + self.assertEqual(S.speed_words("faster", True), "Faster (default on this PC)") + self.assertEqual(S.speed_words("faster", False), "Faster") + self.assertEqual(S.speed_words("full", False), "Full quality: all 6 experts per word") + self.assertEqual(S.FASTER_NOTE, "Faster uses 5 of 6 experts per word: a small quality change, usually not noticeable.") + + def test_the_flags_text_says_the_same(self): + self.assertNotIn("--speed", S.flags_text(S.LaunchSettings(family="deepseek41", model="IST-DAS-2.00bpw"))) + self.assertIn("--full-quality", S.flags_text(S.LaunchSettings(family="deepseek41", model="IST-DAS-2.00bpw", speed="full"))) + self.assertIn("--speed faster", S.flags_text(S.LaunchSettings(family="deepseek41", model="IST-DAS-2.00bpw", speed="faster"))) + + +class EngineFlag(unittest.TestCase): + def test_experts_replaces_the_saved_value_and_goes_last(self): + cfg = {"args": ["--pack", "p", "--experts", "6", "--dspark", "auto"]} + apply_experts(cfg, 5) + self.assertEqual(cfg["args"], ["--pack", "p", "--dspark", "auto", "--experts", "5"]) + cfg = {"args": ["--experts=5", "--pack", "p"]} + apply_experts(cfg, 6) + self.assertEqual(cfg["args"], ["--pack", "p", "--experts", "6"]) + cfg = {"args": ["--pack", "p"]} + apply_experts(cfg, None) + self.assertEqual(cfg["args"], ["--pack", "p"]) + + def test_derive_config_passes_it(self): + base = {"exe": "x", "args": ["--pack", "p"]} + cfg = derive_config(base, S.LaunchSettings(), bool_flags=frozenset(), experts=5) + self.assertEqual(cfg["args"][-2:], ["--experts", "5"]) + self.assertEqual(derive_config(base, S.LaunchSettings(), bool_flags=frozenset())["args"], ["--pack", "p"]) + + +class Resolve(unittest.TestCase): + def runner(self, vram_gb, **kw): + cat = mock.Mock() + cat.strata.multi_family.return_value = True + cat.computer.return_value = mock.Mock(total_vram_gb=vram_gb) + return Runner(S.LaunchSettings(family="deepseek41", model="IST-DAS-2.00bpw", **kw), catalog=cat, emit=lambda e: None) + + def test_a_12_gb_pc_gets_faster_and_a_big_one_full_quality_by_default(self): + self.assertEqual(self.runner(12).resolved_speed(), ("faster", True)) + self.assertEqual(self.runner(12).experts_flag(), 5) + self.assertEqual(self.runner(96).resolved_speed(), ("full", True)) + self.assertEqual(self.runner(96).experts_flag(), 6) + + def test_a_choice_wins_over_the_default(self): + self.assertEqual(self.runner(12, speed="full").resolved_speed(), ("full", False)) + self.assertEqual(self.runner(12, speed="full").experts_flag(), 6) + self.assertEqual(self.runner(96, speed="faster").experts_flag(), 5) + + def test_the_line_has_the_note_only_for_faster(self): + self.assertIn(S.FASTER_NOTE, self.runner(12).speed_line()) + self.assertIn("Faster (default on this PC)", self.runner(12).speed_line()) + self.assertEqual(self.runner(12, speed="full").speed_line(), "Speed: Full quality: all 6 experts per word") + + def test_another_model_has_no_speed(self): + cat = mock.Mock() + cat.strata.multi_family.return_value = False + r = Runner(S.LaunchSettings(family="qwen", model="IQ3_S"), catalog=cat, emit=lambda e: None) + self.assertIsNone(r.resolved_speed()) + self.assertIsNone(r.experts_flag()) + self.assertEqual(r.speed_line(), "") + + +class Flags(unittest.TestCase): + def plan(self, *args): + code, out, err = run_cli(["launch", "--plan", "--output", "json", "--model", "ist-das-2.00bpw", "--family", "deepseek41", *args]) + self.assertEqual(code, 0, err + out) + return json.loads(out)["plan"] + + def test_plan_names_the_speed_in_plain_words(self): + with mock.patch.object(Runner, "resolved_speed", return_value=("faster", True)): + p = self.plan() + self.assertIn("Faster (default on this PC)", p["speed"]) + self.assertIn(S.FASTER_NOTE, p["speed"]) + + def test_full_quality_flag_and_speed_flag(self): + self.assertEqual(self.plan("--full-quality")["settings"]["speed"], "full") + self.assertEqual(self.plan("--speed", "full")["settings"]["speed"], "full") + self.assertEqual(self.plan("--speed", "faster")["settings"]["speed"], "faster") + self.assertIn("--full-quality", self.plan("--full-quality")["flags"]) + + def test_both_flags_say_so_and_full_quality_wins(self): + p = self.plan("--full-quality", "--speed", "faster") + self.assertEqual(p["settings"]["speed"], "full") + self.assertTrue(any("full quality is used" in w for w in p["warnings"])) + + def test_another_model_warns_and_drops_it(self): + code, out, err = run_cli(["launch", "--plan", "--output", "json", "--model", "q2_0", "--full-quality"]) + p = json.loads(out)["plan"] + self.assertIsNone(p["settings"]["speed"]) + self.assertTrue(any("for DeepSeek" in w for w in p["warnings"])) + + def test_human_plan_prints_a_speed_line(self): + with mock.patch.object(Runner, "resolved_speed", return_value=("faster", True)): + code, out, err = run_cli(["launch", "--plan", "--model", "ist-das-2.00bpw", "--family", "deepseek41"]) + self.assertIn(" speed Faster (default on this PC)", out) + + +class Screen(unittest.TestCase): + def setUp(self): + self.home = Home().__enter__() + self.addCleanup(self.home.__exit__, None, None, None) + + def test_the_step_exists_only_for_deepseek(self): + ctx = make_ctx() + self.assertNotIn("speed", flow_for(ctx)) + ctx.settings.family = "deepseek41" + flow = flow_for(ctx) + self.assertEqual(flow[flow.index("context") + 1], "speed") + + def test_the_screen_offers_two_choices_and_remembers_only_a_change(self): + ctx = make_ctx() + ctx.settings.family, ctx.settings.model = "deepseek41", "IST-DAS-2.00bpw" + app = LaunchApp(ctx) + + async def go(): + async with app.run_test(size=SIZE) as pilot: + await pilot.pause(0.2) + app.goto("speed") + await pilot.pause(0.3) + t = text_of(app) + self.assertIn("Faster", t) + self.assertIn("Full quality", t) + self.assertIn(S.FASTER_NOTE, t) + screen = app.screen + self.assertIsInstance(screen, SpeedScreen) + screen.commit() + self.assertEqual(ctx.settings.speed, None if S.faster_default(ctx.computer.total_vram_gb) else "faster") + await press(pilot, "down") + screen.commit() + self.assertIn(ctx.settings.speed, (None, "full")) + asyncio.run(go()) + + +if __name__ == "__main__": + unittest.main()