From 436fabc46689ff869f5f38c30b161afa0c19f098 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Sat, 17 Oct 2026 03:39:30 +0200 Subject: [PATCH] launch: ask before downloading a model that is not here; tuning table labels --- strata_cli/launch/app.py | 19 ++++++++++++++++++- strata_cli/launch/runner.py | 14 ++++++++++++++ strata_cli/launch/screens.py | 3 ++- tests/terminal/test_launch_tui.py | 25 +++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 2 deletions(-) diff --git a/strata_cli/launch/app.py b/strata_cli/launch/app.py index 1afca319..e8d4154b 100644 --- a/strata_cli/launch/app.py +++ b/strata_cli/launch/app.py @@ -221,10 +221,27 @@ class LaunchApp(App): self.ctx.settings = s self.run_launch() - def run_launch(self) -> None: + def run_launch(self, confirmed: bool = False) -> None: s = self.ctx.settings self.cancel = threading.Event() self.runner = Runner(s, catalog=self.ctx.catalog, emit=self._emit, cancel=self.cancel, feed=self.ctx.feed) + gb = getattr(self.runner, "download_gb", lambda: 0.0)() if not confirmed else 0.0 + if gb >= 1.0: + free = self.ctx.catalog.disk_free(s.data_dir or self.ctx.catalog.data_dir()) + room = (f" There is {free:,.0f} GB free in the folder." if free is not None else "") + warn = (" That is less than the download needs; it will probably stop part way." if free is not None and free < gb + 8 else "") + + def done(choice: str | None) -> None: + if choice == "go": + self.run_launch(confirmed=True) + elif self.current == "start": + pass + + self.push_screen(ConfirmScreen(f"Download about {gb:.0f} GB?", + f"This model is not on this computer yet. Strata will download about {gb:.0f} GB now; an interrupted download continues where it stopped." + + room + warn, + [("go", "Download and start"), ("no", "Not now")]), done) + return screen = RunScreen() self.run_screen = screen self.current = "run" diff --git a/strata_cli/launch/runner.py b/strata_cli/launch/runner.py index 6a427ac6..8e4b1438 100644 --- a/strata_cli/launch/runner.py +++ b/strata_cli/launch/runner.py @@ -344,6 +344,20 @@ class Runner: desc = self.catalog.strata.describe_config(path) return path, desc + def download_gb(self) -> float: + """How much would be downloaded for this launch right now: 0 when the model is installed with these choices (or is the person's own files).""" + s = self.s + if s.model_path or not (s.family and s.model): + return 0.0 + try: + path, desc = self.installed_state() + if path is not None and desc is not None and desc_matches(desc, s) and not files_present(read_config(path)): + return 0.0 + row = next((r for r in self.catalog.rows() if r.family == s.family and r.model == s.model), None) + return float(row.download_gb) if row else 0.0 + except Exception: # noqa: BLE001 + return 0.0 + def ensure_model(self) -> Path: s, cat = self.s, self.catalog if s.model_path and not (s.family and s.model): diff --git a/strata_cli/launch/screens.py b/strata_cli/launch/screens.py index eed75467..464f0fbc 100644 --- a/strata_cli/launch/screens.py +++ b/strata_cli/launch/screens.py @@ -1338,7 +1338,8 @@ class RunScreen(Base): t.append(f" about {info['minutes_left']} min left") t.append("\n") for sp in (info.get("speeds") or [])[-6:]: - label = sp.get("label") or sp.get("id") or "?" + label = {"base": "Default settings", "base_aa": "Default settings, measured again"}.get(sp.get("label") or sp.get("id"), + sp.get("label") or sp.get("id") or "?") val = sp.get("decode_tok_s") or sp.get("value") or sp.get("tok_s") t.append(f" {str(label)[:34]:<36}{val if val is not None else '-'}" + (" tokens/s" if val is not None else "") + "\n") t.append(" Close other heavy programs while it measures. You can stop it any time: nothing changes until it is done.\n", style=MUTE) diff --git a/tests/terminal/test_launch_tui.py b/tests/terminal/test_launch_tui.py index c1b0cb1e..0fa40ea5 100644 --- a/tests/terminal/test_launch_tui.py +++ b/tests/terminal/test_launch_tui.py @@ -36,11 +36,15 @@ class FakeRunner: instances: list = [] behaviour = "ok" hold = 0 + download = 0.0 def __init__(self, s, *, catalog=None, emit=None, cancel=None, feed=None, **kw): self.s, self.emit_cb, self.cancel, self.feed = s, emit, cancel, feed FakeRunner.instances.append(self) + def download_gb(self): + return FakeRunner.download + def run(self, start=True): e = self.emit_cb e(Event("engine", "Engine 0.1.45 (cuda) is installed.", 100)) @@ -85,6 +89,7 @@ class Base(unittest.TestCase): self.addCleanup(self.home.__exit__, None, None, None) FakeRunner.instances.clear() FakeRunner.behaviour = "ok" + FakeRunner.download = 0.0 p = mock.patch("strata_cli.launch.app.Runner", FakeRunner) p.start() self.addCleanup(p.stop) @@ -141,6 +146,26 @@ class StartScreenTests(Base): self.assertEqual(app.result.profile, "launch-x") self.run_app(case) + def test_a_model_that_is_not_here_asks_before_downloading(self): + store.save(S.LaunchSettings(name="Big", family="qwen", model="IQ3_XXS", context=65536)) + FakeRunner.download = 75.8 + + async def case(app, pilot, ctx): + await press(pilot, "enter") + t = flat(app) + self.assertIn("Download about 76 GB?", t) + self.assertIn("not on this computer yet", t) + self.assertIn("Download and start", t) + self.assertEqual(FakeRunner.instances[-1].behaviour, "ok") + await press(pilot, "down", "enter") # Not now + await pilot.pause(0.3) + self.assertIsNone(app.result) + await press(pilot, "enter") + await press(pilot, "enter") # Download and start + await pilot.pause(0.8) + self.assertIsNotNone(app.result) + self.run_app(case) + def test_delete_asks_then_removes_only_the_preset(self): store.save(S.LaunchSettings(name="Old", family="qwen", model="Q2_0", context=32768))