diff --git a/docs/DEEPSEEK41.md b/docs/DEEPSEEK41.md index 212a9e2d..aba0e887 100644 --- a/docs/DEEPSEEK41.md +++ b/docs/DEEPSEEK41.md @@ -90,7 +90,7 @@ Not in this version: several requests at once (`--parallel` is ignored with a wa ## 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 whose graphics cards total 16 GiB or less: the engine decides that itself (`--experts auto`), and Strata passes `--experts` only when you choose. **Full quality** uses all 6 (`--experts 6`). +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 whose graphics cards total 16 GiB or less, and on an integrated GPU such as Strix Halo: the engine decides that itself (`--experts auto`), and Strata passes `--experts` only when you choose. **Full quality** uses all 6 (`--experts 6`). The choice needs the DeepSeek engine 0.1.50 or newer (0.1.49.2 does not take `--experts`); with an older engine the step and the plan line are left out and nothing is passed. 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. diff --git a/strata_cli/launch/runner.py b/strata_cli/launch/runner.py index 76a4a6bd..e9984cff 100644 --- a/strata_cli/launch/runner.py +++ b/strata_cli/launch/runner.py @@ -425,9 +425,8 @@ def engine_takes_experts(exe) -> bool: return dsv41_engine_version(exe) >= EXPERTS_MIN_ENGINE -def used_vram_gb(computer, s: "S.LaunchSettings") -> float: - """Graphics memory (GiB) of the cards this launch uses, summed as the engine sums it: the cards named (--gpu, the Cards step; a role other than - off), else every card that can be used.""" +def used_cards(computer, s: "S.LaunchSettings") -> list: + """The cards this launch uses: the ones named (--gpu, the Cards step; a role other than off), else every card that can be used.""" cards = list(computer.usable_gpus) chosen = None if s.gpu_roles: @@ -436,7 +435,28 @@ def used_vram_gb(computer, s: "S.LaunchSettings") -> float: chosen = {int(g) for g in s.gpus} if chosen is not None: cards = [c for c in cards if int(c.get("index", 0)) in chosen] - return sum(float(c.get("vram_gb") or 0) for c in cards) + return cards + + +def used_vram_gb(computer, s: "S.LaunchSettings") -> float: + """Graphics memory (GiB) of the cards this launch uses, summed as the engine sums it.""" + return sum(float(c.get("vram_gb") or 0) for c in used_cards(computer, s)) + + +def uses_integrated_gpu(computer, s: "S.LaunchSettings") -> bool: + """Does the launch run on an integrated / unified-memory GPU (Strix Halo, gfx1151, Radeon 8060S: the hardware probe marks it uma, integrated or + unified_memory)? A Mac is left out: DeepSeek is not on the Mac.""" + for c in used_cards(computer, s): + if str(c.get("vendor")) == "apple" or c.get("unified_gb"): + continue + if c.get("integrated") or c.get("uma") or c.get("unified_memory"): + return True + return False + + +def faster_by_default(computer, s: "S.LaunchSettings") -> bool: + """The engine's `--experts auto` rule: Faster (5 experts) on an integrated GPU, or when the cards used total 16 GiB or less.""" + return uses_integrated_gpu(computer, s) or S.faster_default(used_vram_gb(computer, s)) EXPERTS_LINE = re.compile(r"experts per word: (\d+)") @@ -1980,7 +2000,7 @@ class Runner: if not self.multi_file() or not self.speed_engine_ok(): return None try: - default = S.faster_default(used_vram_gb(self.catalog.computer(), self.s)) + default = faster_by_default(self.catalog.computer(), self.s) 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: diff --git a/strata_cli/launch/screens.py b/strata_cli/launch/screens.py index ae991734..78a524f5 100644 --- a/strata_cli/launch/screens.py +++ b/strata_cli/launch/screens.py @@ -1050,15 +1050,15 @@ class PicturesScreen(Base): 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 whose graphics cards total 16 GB or less (the engine decides the same way).") + "usually not noticeable. Full quality uses all 6. Faster is the default on a PC whose graphics cards total 16 GB or less, and on an integrated GPU such as Strix Halo (the engine decides the same way).") 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: - from strata_cli.launch.runner import used_vram_gb - return S.faster_default(used_vram_gb(self.ctx.computer, self.ctx.settings)) + from strata_cli.launch.runner import faster_by_default + return faster_by_default(self.ctx.computer, self.ctx.settings) def on_mount(self) -> None: s = self.ctx.settings @@ -1549,11 +1549,11 @@ class SaveScreen(Base): def summary_lines(self) -> list[tuple[str, str]]: s = self.ctx.settings r = next((x for x in self.ctx.rows if (x.family, x.model) == (s.family, s.model)), None) - from strata_cli.launch.runner import used_vram_gb + from strata_cli.launch.runner import faster_by_default 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(used_vram_gb(self.ctx.computer, s)) else "full"), + *([("Speed", S.speed_words(s.speed or ("faster" if faster_by_default(self.ctx.computer, s) else "full"), s.speed is None))] if s.family == "deepseek41" and speed_choice_available(self.ctx) 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" diff --git a/tests/terminal/test_launch_speed.py b/tests/terminal/test_launch_speed.py index 068ccb3e..ab53d1f0 100644 --- a/tests/terminal/test_launch_speed.py +++ b/tests/terminal/test_launch_speed.py @@ -11,7 +11,7 @@ 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, dsv41_engine_version, engine_takes_experts, experts_from_log, - used_vram_gb) + faster_by_default, used_vram_gb, uses_integrated_gpu) 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 @@ -131,6 +131,36 @@ class Resolve(unittest.TestCase): self.assertEqual(used_vram_gb(comp, S.LaunchSettings(gpus=[0])), 12) self.assertEqual(used_vram_gb(comp, S.LaunchSettings(gpu_roles={"0": "main", "1": "off"})), 12) + def test_an_integrated_gpu_is_faster_by_default_whatever_its_memory(self): # Strix Halo: 96 GB of shared memory, the engine says 5 + halo = {"index": 0, "vram_gb": 96, "vendor": "amd", "uma": True, "name": "AMD Radeon 8060S (gfx1151)"} + comp = mock.Mock(usable_gpus=[halo]) + s = S.LaunchSettings() + self.assertTrue(uses_integrated_gpu(comp, s)) + self.assertTrue(faster_by_default(comp, s)) + for key in ("integrated", "unified_memory"): + other = {"index": 0, "vram_gb": 64, "vendor": "amd", key: True} + self.assertTrue(faster_by_default(mock.Mock(usable_gpus=[other]), s), key) + big = {"index": 0, "vram_gb": 96, "vendor": "amd"} # a 96 GB discrete card is still Full quality + self.assertFalse(faster_by_default(mock.Mock(usable_gpus=[big]), s)) + mac = {"index": 0, "vram_gb": 0, "vendor": "apple", "unified_gb": 64} + self.assertFalse(uses_integrated_gpu(mock.Mock(usable_gpus=[mac]), s)) # DeepSeek is not on the Mac + two = mock.Mock(usable_gpus=[{"index": 0, "vram_gb": 24, "vendor": "nvidia"}, {"index": 1, "vram_gb": 32, "vendor": "amd", "uma": True}]) + self.assertFalse(uses_integrated_gpu(two, S.LaunchSettings(gpus=[0]))) # only the cards this launch uses count + self.assertTrue(uses_integrated_gpu(two, S.LaunchSettings(gpus=[1]))) + + def test_the_label_and_the_plan_say_faster_on_strix_halo_and_the_guard_still_holds(self): + cat = mock.Mock() + cat.strata.multi_family.return_value = True + cat.computer.return_value = mock.Mock(usable_gpus=[{"index": 0, "vram_gb": 96, "vendor": "amd", "uma": True}]) + r = Runner(S.LaunchSettings(family="deepseek41", model="IST-DAS-2.00bpw"), catalog=cat, emit=lambda e: None) + r.dsv41_engine_found = lambda: (Path(self.engine), True) + self.assertEqual(r.resolved_speed(), ("faster", True)) + self.assertIn("Faster (default on this PC)", r.speed_line()) + self.assertIsNone(r.experts_flag()) # not chosen: the engine's auto rule decides + r.dsv41_engine_found = lambda: (Path("/x/engine-dsv41/0.1.49.2-a/strata-dsv41"), True) + self.assertIsNone(r.resolved_speed()) # engine below 0.1.50: no line, no flag + self.assertEqual(r.speed_line(), "") + def test_the_engines_own_line_wins_in_the_summary(self): r = self.runner(12) self.assertIn("Faster (default on this PC)", r.speed_line(5)) @@ -245,7 +275,7 @@ class Screen(unittest.TestCase): 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" - faster_here = S.faster_default(used_vram_gb(ctx.computer, ctx.settings)) + faster_here = faster_by_default(ctx.computer, ctx.settings) ctx._speed_ok = True app = LaunchApp(ctx)