AMD cards fix, review round: setup's pinned one-card pick is still written (with gpus_by), only DeepSeek on AMD is judged when a copy adopts an earlier card, the launcher uses the plan's card rule and remembers a named card, Windows uses setup's amd_rank and no Linux arch list, message names strata launch --gpu
This commit is contained in:
1 parent
dec8f1366c
commit
e4031fc4d0
5 files changed
+255
-44
No files matched your search
@@ -7096,7 +7096,7 @@ def widen_setups_one_card(cfg_path: Path, cfg: dict, amd: list) -> dict:
|
||||
new = gpu_pick.widened(cfg, cards)
|
||||
write_config(cfg_path, new)
|
||||
ok(f"DeepSeek now uses all {len(cards)} of your AMD cards (it was set up on GPU {was} alone by an earlier Strata). Nothing is rebuilt. "
|
||||
f"To keep it on one card: ./setup.sh --gpu {was}")
|
||||
f"To keep it on one card: strata launch --gpu {was} (it is remembered from then on)")
|
||||
return new
|
||||
except Exception as e: # noqa: BLE001 - never stop a start over this
|
||||
warn(f"could not check which cards this model should use ({e})")
|
||||
@@ -7164,6 +7164,12 @@ def _start(cfg_path: Path, port: int | None, gpu: int | list | None = None, open
|
||||
gpu = None
|
||||
elif gpu is not None:
|
||||
cmd += ["--gpu", str(gpu)]
|
||||
if not isinstance(gpu, list): # a DeepSeek model on AMD keeps a card the person names (the others: this start only)
|
||||
from strata_control import gpu_pick
|
||||
saved = gpu_pick.remember(cfg_path, [gpu])
|
||||
if saved is not None:
|
||||
cfg = saved
|
||||
ok(f"saved for this model: it runs on GPU {gpu} from now on")
|
||||
else:
|
||||
cfg = widen_setups_one_card(cfg_path, cfg, amd) # a DeepSeek config from setup 0.2.8 and earlier: setup's own one-card pick
|
||||
found = []
|
||||
@@ -8413,6 +8419,20 @@ def dsv41_smoke(exe: Path, pack: Path, lib_dirs, gpus=None, timeout: int = 5400)
|
||||
return r.returncode == 0, text[-1500:].encode(enc, "replace").decode(enc, "replace")
|
||||
|
||||
|
||||
def earlier_card_kept(prev: Path) -> bool:
|
||||
"""A new copy of Strata set up like an earlier install carries over the card that install was set to. A card setup picked itself on a
|
||||
DeepSeek model on AMD (strata_control/gpu_pick.py) is not a choice to carry over; every other config keeps its card exactly as before
|
||||
(no AMD listing is read for them, and nothing here can stop a setup)."""
|
||||
try:
|
||||
earlier = json.loads(Path(prev).read_text(encoding="utf-8-sig"))
|
||||
from strata_control import gpu_pick
|
||||
if WIN or not gpu_pick.is_deepseek_amd(earlier):
|
||||
return True
|
||||
return gpu_pick.chosen_by_person(earlier, amd_usable_cards(amd_gpus()))
|
||||
except Exception: # noqa: BLE001 - an unreadable file or listing: keep the card, as before
|
||||
return True
|
||||
|
||||
|
||||
def cards_named(a, hip: bool = False) -> bool:
|
||||
"""Did the person name the cards (--gpu / --gpus)? On AMD setup's own pick is written into a.gpu further on (other steps rely on it), so
|
||||
the AMD branch records the answer first (a._cards_named); NVIDIA keeps its way (choose_gpus sets a.gpu to the cards in use)."""
|
||||
@@ -8426,9 +8446,9 @@ def amd_usable_cards(amd) -> list:
|
||||
return gpu_fit.usable_cards([{**g, "vendor": "amd", "usable": amd_problem(g) is None} for g in amd])[0]
|
||||
|
||||
|
||||
def dsv41_covered_archs(eng) -> tuple:
|
||||
"""The AMD architectures the installed DeepSeek engine package holds code for (its manifest), else what the release's package is built for."""
|
||||
from strata_control import dsv41_fit
|
||||
def dsv41_covered_archs(eng):
|
||||
"""The AMD architectures the installed DeepSeek engine package holds code for (its manifest); None when it names none (no package yet, or one
|
||||
without a list): the caller then uses the release's own rule (dsv41_fit.run_cards) and says nothing about a card it cannot know."""
|
||||
try:
|
||||
from strata_control import engine_component as ec
|
||||
exe = dsv41_exe(Path(eng))
|
||||
@@ -8436,9 +8456,9 @@ def dsv41_covered_archs(eng) -> tuple:
|
||||
archs = ec.read_manifest(exe.parent).hip_archs
|
||||
if archs:
|
||||
return tuple(archs)
|
||||
except Exception: # noqa: BLE001 - the release's list is the fallback
|
||||
except Exception: # noqa: BLE001 - no list: None
|
||||
pass
|
||||
return tuple(dsv41_fit.DSV41_HIP_ARCHS)
|
||||
return None
|
||||
|
||||
|
||||
def dsv41_auto_cards(amd, eng) -> list:
|
||||
@@ -8609,7 +8629,7 @@ def install_dsv41(a, family, gpu, hip, amd, cuda_tk, multi, port, ram, adopted,
|
||||
lib_dirs = [*lib_dirs, *dsv41_engine.lib_dirs(exe)] # its own package, and the rocm/bin an AMD package keeps the ROCm DLLs in
|
||||
if hip and exe is not None and named: # cards the person named that this package holds no code for: said, never refused
|
||||
covered = dsv41_covered_archs(eng)
|
||||
for c in cards:
|
||||
for c in cards if covered else []:
|
||||
if c.get("arch") and c["arch"] not in covered:
|
||||
warn(f"GPU {c['index']} ({c['name']}, {c['arch']}): this DeepSeek engine package holds code for {', '.join(covered)} only, so it may "
|
||||
"not start on that card. Leave it out (--gpus ...) to be sure.")
|
||||
@@ -8694,7 +8714,7 @@ def install_dsv41(a, family, gpu, hip, amd, cuda_tk, multi, port, ram, adopted,
|
||||
warn("the 16-word test run was skipped (STRATA_DSV41_NO_SMOKE=1)")
|
||||
else:
|
||||
say(" Testing the model with a short question (a few minutes: the engine reads the first experts from the disk) ...")
|
||||
good, why = dsv41_smoke(exe, pack, lib_dirs, [c["index"] for c in cards] if (named or (hip and len(cards) > 1)) else None)
|
||||
good, why = dsv41_smoke(exe, pack, lib_dirs, [c["index"] for c in cards] if (a.gpu is not None or a.gpus or (hip and len(cards) > 1)) else None)
|
||||
if not good:
|
||||
fail("the model does not answer sensibly after the preparation: " + (why.splitlines()[-1] if why else "no answer"),
|
||||
f"delete {pack} and run setup again so the pack is built fresh; if the test fails again, "
|
||||
@@ -8731,14 +8751,11 @@ def install_dsv41(a, family, gpu, hip, amd, cuda_tk, multi, port, ram, adopted,
|
||||
if mac:
|
||||
cfg["backend"] = "metal"
|
||||
idx = [c["index"] for c in cards]
|
||||
if len(idx) > 1 or named:
|
||||
if len(idx) > 1 or a.gpu is not None or a.gpus: # (a.gpu is also setup's own pick: one card pinned when several devices are in the PC)
|
||||
cfg["gpu"] = idx if len(idx) > 1 else idx[0]
|
||||
if hip: # who chose them (strata_control/gpu_pick.py): setup's own pick is not "asked"
|
||||
cfg["gpus_asked"] = True
|
||||
if hip: # who chose them (strata_control/gpu_pick.py): the person, or setup itself
|
||||
cfg["gpus_by"] = "person" if named else "setup"
|
||||
if named:
|
||||
cfg["gpus_asked"] = True
|
||||
else:
|
||||
cfg["gpus_asked"] = True
|
||||
if a.host:
|
||||
cfg["host"] = a.host
|
||||
if a.api_key:
|
||||
@@ -9281,13 +9298,7 @@ def main() -> int:
|
||||
a.gpus = a.gpus or ",".join(str(g) for g in ch["gpu"])
|
||||
a.layer_split = a.layer_split or ch.get("layer_split")
|
||||
else:
|
||||
try: # a card setup picked itself is not a choice to carry over (strata_control/gpu_pick.py)
|
||||
from strata_control import gpu_pick
|
||||
earlier = json.loads(prev.read_text(encoding="utf-8-sig"))
|
||||
keep_card = gpu_pick.chosen_by_person(earlier, amd_usable_cards(amd_gpus()))
|
||||
except (OSError, ValueError):
|
||||
keep_card = True
|
||||
if keep_card:
|
||||
if earlier_card_kept(prev):
|
||||
a.gpu = a.gpu if a.gpu is not None else ch.get("gpu")
|
||||
a.yes = True
|
||||
global GPU_PICK, OLD_GPUS
|
||||
|
||||
@@ -403,6 +403,15 @@ def cards_for_launch(s: S.LaunchSettings, catalog, ram_gb: float | None = None,
|
||||
if len(comp.usable_gpus) < 2:
|
||||
return None
|
||||
cards = gpu_roles.rows(comp.gpus, comp.engine_vendor)
|
||||
if comp.engine_vendor == "amd" and ((isinstance(base, dict) and base.get("arch") == "deepseek41")
|
||||
or getattr(s, "family", None) == "deepseek41"):
|
||||
# DeepSeek on AMD: the cards setup and `--plan` use (strata_control/dsv41_fit.run_cards): one card on Windows, only cards the engine
|
||||
# package runs, no integrated chip beside a card with memory of its own
|
||||
from strata_control import dsv41_fit
|
||||
ids = [int(c["index"]) for c in dsv41_fit.run_cards(comp.usable_gpus, comp.engine_vendor)[0]]
|
||||
if len(ids) < 2:
|
||||
return ids or None # pinned to that card, exactly as setup pins it
|
||||
cards = [c for c in cards if int(c.get("index", 0)) in ids]
|
||||
rec = gpu_roles.recommend(cards, comp.engine_vendor)["roles"]
|
||||
return gpu_roles.order(rec, cards) or None
|
||||
except Exception: # noqa: BLE001 - never block a launch over the choice of cards
|
||||
@@ -1431,6 +1440,9 @@ class Runner:
|
||||
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))
|
||||
if self.s.gpus and not self.s.gpu_roles: # a DeepSeek model on AMD keeps the card the person names from now on (strata_control/gpu_pick.py)
|
||||
from strata_control import gpu_pick
|
||||
gpu_pick.remember(base_path, [int(g) for g in self.s.gpus])
|
||||
self.apply_four_card(cfg)
|
||||
self.use_own_dsv41_engine(cfg)
|
||||
apply_experts(cfg, self.experts_flag(cfg.get("exe"))) # after the engine is settled: only a 0.1.50+ engine is given --experts
|
||||
|
||||
+15
-11
@@ -19,12 +19,11 @@ setup.py, tools/strata_mcp.py and strata_cli/launch import it. Recommend, never
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import platform
|
||||
import sys
|
||||
from typing import Any
|
||||
|
||||
import os
|
||||
|
||||
from strata_control import gpu_fit
|
||||
|
||||
GB = 1e9
|
||||
@@ -133,15 +132,20 @@ def run_cards(cards: list[dict] | None, vendor: str | None = None, *, windows: b
|
||||
ignored = list(ignored) + [{**c, "why_ignored": f"only {float(c.get('vram_gb') or 0):.0f} GB of graphics memory"} for c in small]
|
||||
amd = not named and bool(keep) and all(str(c.get("vendor") or vendor or "").lower() == "amd" for c in keep)
|
||||
if amd:
|
||||
archs = tuple(covered if covered is not None else DSV41_HIP_ARCHS)
|
||||
known = [c for c in keep if c.get("arch")]
|
||||
ok = [c for c in keep if not c.get("arch") or c["arch"] in archs]
|
||||
if known and ok and len(ok) < len(keep):
|
||||
ignored += [{**c, "why_ignored": f"the DeepSeek engine has no code for {c['arch']} (it runs on {', '.join(archs)})"}
|
||||
for c in keep if c not in ok]
|
||||
keep = ok
|
||||
if (_on_windows() if windows is None else windows) and len(keep) > 1:
|
||||
first = min(keep, key=lambda c: (-round(float(c.get("vram_gb") or 0)), c.get("index", 0)))
|
||||
win = _on_windows() if windows is None else windows
|
||||
# the list of architectures: the package's own (`covered`), else the Linux package's (gfx1200, gfx1201). Windows ships a different
|
||||
# DeepSeek package (hip-rdna3), so without a list of its own nothing is filtered there.
|
||||
archs = tuple(covered) if covered else (() if win else DSV41_HIP_ARCHS)
|
||||
if archs:
|
||||
known = [c for c in keep if c.get("arch")]
|
||||
ok = [c for c in keep if not c.get("arch") or c["arch"] in archs]
|
||||
if known and ok and len(ok) < len(keep):
|
||||
ignored += [{**c, "why_ignored": f"the DeepSeek engine has no code for {c['arch']} (it runs on {', '.join(archs)})"}
|
||||
for c in keep if c not in ok]
|
||||
keep = ok
|
||||
if win and len(keep) > 1:
|
||||
# the card setup takes (setup.py amd_rank): a card with memory of its own before an APU, then the most memory, then the lower number
|
||||
first = min(keep, key=lambda c: (bool(c.get("uma") or c.get("integrated")), -round(float(c.get("vram_gb") or 0)), c.get("index", 0)))
|
||||
ignored += [{**c, "why_ignored": "on Windows a model runs on one AMD card"} for c in keep if c is not first]
|
||||
keep = [first]
|
||||
keep = sorted(keep, key=lambda c: c.get("index", 0))
|
||||
|
||||
@@ -12,8 +12,6 @@ on one). New configs say who chose in "gpus_by" ("person" or "setup"). A confi
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
ASKED_BY_PERSON = "person"
|
||||
PICKED_BY_SETUP = "setup"
|
||||
|
||||
@@ -65,14 +63,37 @@ def looks_like_setups_pick(cfg: dict, usable: list[dict] | None) -> bool:
|
||||
|
||||
|
||||
def widened(cfg: dict, cards: list[int]) -> dict:
|
||||
"""`cfg` with setup's own pick of `cards` (two or more): card list, no 'asked' mark, and the marker that setup chose them."""
|
||||
"""`cfg` with setup's own pick of `cards` (two or more): the card list and the marker that setup chose them; nothing else changes."""
|
||||
out = dict(cfg)
|
||||
out["gpu"] = list(cards) if len(cards) > 1 else cards[0]
|
||||
out.pop("gpus_asked", None)
|
||||
out["gpus_asked"] = True # as setup writes it for every card list; "gpus_by" says who chose
|
||||
out["gpus_by"] = PICKED_BY_SETUP
|
||||
out.pop("hip_ordinal", None)
|
||||
return out
|
||||
|
||||
|
||||
def describe(cfg: dict, usable: list[dict] | None) -> dict[str, Any]:
|
||||
return {"by_person": chosen_by_person(cfg, usable), "legacy": not cfg.get("gpus_by") and bool(cfg.get("gpus_asked"))}
|
||||
def is_deepseek_amd(cfg: dict | None) -> bool:
|
||||
return isinstance(cfg, dict) and _is_deepseek_amd(cfg)
|
||||
|
||||
|
||||
def remember(path, cards: list[int]) -> dict | None:
|
||||
"""The person named `cards` for a DeepSeek model on AMD (`strata launch --gpu N`, `--gpus ...`, `setup --gpu N`): saved in the installed
|
||||
config as theirs, so no later start widens or moves it. Returns the new config, or None when the file is not a DeepSeek AMD config
|
||||
(everything else keeps its own rules) or cannot be written. Nothing else in the file changes."""
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
p = Path(path)
|
||||
try:
|
||||
cfg = json.loads(p.read_text(encoding="utf-8-sig"))
|
||||
if not _is_deepseek_amd(cfg) or not cards:
|
||||
return None
|
||||
cfg["gpu"] = list(cards) if len(cards) > 1 else int(cards[0])
|
||||
cfg["gpus_asked"] = True
|
||||
cfg["gpus_by"] = ASKED_BY_PERSON
|
||||
tmp = p.with_name(p.name + ".tmp")
|
||||
tmp.write_text(json.dumps(cfg, indent=1), encoding="utf-8")
|
||||
os.replace(tmp, p)
|
||||
return cfg
|
||||
except (OSError, ValueError, TypeError):
|
||||
return None
|
||||
@@ -19,6 +19,7 @@ sys.path.insert(0, str(ROOT))
|
||||
sys.path.insert(0, str(ROOT / "tools"))
|
||||
import setup # noqa: E402
|
||||
import test_setup_dsv41 as D # noqa: E402
|
||||
import serve.server as server # noqa: E402
|
||||
from strata_control import dsv41_fit, gpu_pick # noqa: E402
|
||||
|
||||
|
||||
@@ -74,6 +75,35 @@ class Rule(unittest.TestCase):
|
||||
self.assertEqual(ids(keep), [0, 1])
|
||||
self.assertEqual(left, [])
|
||||
|
||||
def test_windows_rx_7900_and_rx_9070_run_on_the_card_setup_takes_and_nothing_is_dropped_by_arch(self):
|
||||
cards = [amd(0, "gfx1201", 16.0), amd(1, "gfx1100", 24.0)]
|
||||
keep, left = dsv41_fit.run_cards(cards, "amd", windows=True)
|
||||
self.assertEqual(ids(keep), [1]) # discrete, then the most memory: setup's amd_rank
|
||||
self.assertEqual([c["index"] for c in left], [0])
|
||||
self.assertIn("Windows", left[0]["why_ignored"])
|
||||
self.assertNotIn("no code", left[0]["why_ignored"]) # Windows ships another package: the Linux list is not applied
|
||||
with mock.patch.object(setup, "amd_problem", lambda g: None), mock.patch.object(setup, "WIN", True):
|
||||
self.assertEqual(ids(setup.dsv41_auto_cards(cards, Path("nowhere"))), [1])
|
||||
self.assertEqual(min(cards, key=setup.amd_rank)["index"], 1) # what setup pins as a.gpu
|
||||
|
||||
def test_windows_prefers_a_discrete_card_to_an_apu(self):
|
||||
keep, _ = dsv41_fit.run_cards([apu(0), amd(1, "gfx1100", 24.0), amd(2, "gfx1100", 24.0)], "amd", windows=True)
|
||||
self.assertEqual(ids(keep), [1])
|
||||
|
||||
def test_no_manifest_list_means_no_code_warning_for_a_named_card(self):
|
||||
self.assertIsNone(setup.dsv41_covered_archs(Path("nowhere")))
|
||||
|
||||
def test_nvidia_small_cards_are_said_as_before_and_options_single_is_the_largest(self):
|
||||
nv = [{"index": 0, "name": "RTX 3060", "vram_gb": 12.0, "vendor": "nvidia", "arch": 86},
|
||||
{"index": 1, "name": "RTX 3090", "vram_gb": 24.0, "vendor": "nvidia", "arch": 86},
|
||||
{"index": 2, "name": "GT 1030", "vram_gb": 2.0, "vendor": "nvidia", "arch": 61}]
|
||||
keep, left = dsv41_fit.run_cards(nv, "nvidia", windows=True)
|
||||
self.assertEqual(ids(keep), [0, 1])
|
||||
self.assertEqual([c["index"] for c in left], [2]) # only the truth: 2 GB (usable_cards says it already)
|
||||
opts = dsv41_fit.options(nv, 128.0, vendor="nvidia", model="IST-DAS-2.25bpw")
|
||||
single = next(o for o in opts["options"] if o["key"] == "single")
|
||||
self.assertEqual(single["cards"], [1])
|
||||
|
||||
def test_nvidia_cards_are_not_touched(self):
|
||||
nv = [{"index": i, "name": "RTX 3090", "vram_gb": 24.0, "vendor": "nvidia", "arch": 86} for i in range(2)]
|
||||
self.assertEqual(ids(dsv41_fit.run_cards(nv, "nvidia", windows=True)[0]), [0, 1])
|
||||
@@ -144,8 +174,10 @@ class Install(unittest.TestCase):
|
||||
setUp = D.Install.setUp
|
||||
install = D.Install.install
|
||||
|
||||
def go(self, all_cards, cards, hip=True, **kw):
|
||||
def go(self, all_cards, cards, hip=True, pick=None, **kw):
|
||||
named = kw.pop("named", False)
|
||||
if pick is not None: # setup's own pick, written into a.gpu by the AMD branch (more than one device)
|
||||
kw["gpu"] = pick
|
||||
gpu = {"index": cards[0]["index"], "count": len(all_cards or cards), "vram_gb": 32.0, "name": "R9700", "cards": cards, "arch": "gfx1201"}
|
||||
self.exe.parent.mkdir(parents=True, exist_ok=True)
|
||||
self.exe.write_text("x")
|
||||
@@ -155,12 +187,13 @@ class Install(unittest.TestCase):
|
||||
self.assertEqual(rc, 0, out)
|
||||
return out
|
||||
|
||||
def test_nothing_asked_uses_every_card_and_is_not_marked_asked(self):
|
||||
def test_nothing_asked_uses_every_card_and_says_setup_chose_them(self):
|
||||
out = self.go(FOUR, [FOUR[0]])
|
||||
self.assertEqual(self.cfg["gpu"], [0, 1, 2, 3])
|
||||
self.assertNotIn("gpus_asked", self.cfg)
|
||||
self.assertTrue(self.cfg["gpus_asked"]) # as setup always wrote it for a card list; gpus_by says who chose
|
||||
self.assertEqual(self.cfg["gpus_by"], "setup")
|
||||
self.assertIn("4 cards", out)
|
||||
self.assertEqual(server.child_env({**self.cfg})["HIP_VISIBLE_DEVICES"], "0,1,2,3")
|
||||
|
||||
def test_gpu_0_is_one_card_and_remembered_as_the_persons(self):
|
||||
self.go(None, [FOUR[0]], gpu=0, named=True)
|
||||
@@ -174,10 +207,31 @@ class Install(unittest.TestCase):
|
||||
self.assertTrue(self.cfg["gpus_asked"])
|
||||
self.assertEqual(self.cfg["gpus_by"], "person")
|
||||
|
||||
def test_a_windows_pc_runs_on_one_card_and_writes_no_card_choice(self):
|
||||
def test_windows_with_two_cards_pins_the_one_card_and_the_engine_sees_only_it(self):
|
||||
self.go(None, [FOUR[0]], pick=0)
|
||||
self.assertEqual(self.cfg["gpu"], 0)
|
||||
self.assertTrue(self.cfg["gpus_asked"])
|
||||
self.assertEqual(self.cfg["gpus_by"], "setup")
|
||||
self.assertEqual(server.child_env({**self.cfg})["HIP_VISIBLE_DEVICES"], "0")
|
||||
|
||||
def test_an_apu_beside_a_discrete_card_not_at_index_0_pins_the_discrete_card(self):
|
||||
discrete = amd(1)
|
||||
self.go([discrete], [discrete], pick=1)
|
||||
self.assertEqual(self.cfg["gpu"], 1)
|
||||
self.assertTrue(self.cfg["gpus_asked"])
|
||||
self.assertEqual(self.cfg["gpus_by"], "setup")
|
||||
self.assertEqual(server.child_env({**self.cfg})["HIP_VISIBLE_DEVICES"], "1")
|
||||
|
||||
def test_two_mixed_cards_pin_the_one_the_package_runs_even_when_setup_picked_the_other(self):
|
||||
covered = amd(0, "gfx1201", 16.0)
|
||||
self.go([covered], [covered], pick=1) # setup's own pick (more memory) was the gfx1100 card
|
||||
self.assertEqual(self.cfg["gpu"], 0)
|
||||
self.assertEqual(self.cfg["gpus_by"], "setup")
|
||||
self.assertEqual(server.child_env({**self.cfg})["HIP_VISIBLE_DEVICES"], "0")
|
||||
|
||||
def test_one_card_in_the_pc_writes_no_card_choice(self):
|
||||
self.go(None, [FOUR[0]])
|
||||
self.assertNotIn("gpu", self.cfg)
|
||||
self.assertNotIn("gpus_asked", self.cfg)
|
||||
|
||||
def test_nvidia_is_written_as_before(self):
|
||||
nv = [{"index": i, "name": "RTX 3090", "vram_gb": 24.0, "vendor": "nvidia", "arch": 86} for i in range(2)]
|
||||
@@ -211,7 +265,7 @@ class Widen(unittest.TestCase):
|
||||
new, saved = self.widen({"gpu": 0, "gpus_asked": True})
|
||||
self.assertEqual(saved["gpu"], [0, 1, 2, 3])
|
||||
self.assertEqual(new["gpu"], [0, 1, 2, 3])
|
||||
self.assertNotIn("gpus_asked", saved)
|
||||
self.assertTrue(saved["gpus_asked"]) # as for every card list; "gpus_by" says setup chose them
|
||||
self.assertEqual(saved["gpus_by"], "setup")
|
||||
self.assertEqual(saved["args"], self.args) # the pack and the files are not touched
|
||||
|
||||
@@ -250,6 +304,115 @@ class Widen(unittest.TestCase):
|
||||
self.assertEqual(saved["gpu"], [0, 2])
|
||||
|
||||
|
||||
class Adoption(unittest.TestCase):
|
||||
"""A new copy set up like an earlier install: only a DeepSeek-on-AMD config of setup's own pick loses its card."""
|
||||
|
||||
def kept(self, cfg, listing=None, win=False):
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
path = Path(d) / "strata-x.json"
|
||||
path.write_text(json.dumps(cfg))
|
||||
with mock.patch.object(setup, "WIN", win), mock.patch.object(setup, "amd_problem", lambda g: None), \
|
||||
mock.patch.object(setup, "amd_gpus", listing or (lambda: FOUR)):
|
||||
return setup.earlier_card_kept(path)
|
||||
|
||||
def test_nvidia_and_qwen_configs_keep_their_card_whatever_marks_they_have(self):
|
||||
def boom():
|
||||
raise AssertionError("the AMD listing must not be read for another model or make")
|
||||
self.assertTrue(self.kept({"arch": "qwen4exp", "backend": "cuda", "gpu": 1}, boom))
|
||||
self.assertTrue(self.kept({"arch": "qwen4exp", "backend": "hip", "gpu": 1, "gpus_asked": True}, boom))
|
||||
self.assertTrue(self.kept({"arch": "deepseek41", "backend": "cuda", "gpu": 1}, boom))
|
||||
|
||||
def test_deepseek_on_amd_by_setups_own_pick_is_not_carried_over(self):
|
||||
self.assertFalse(self.kept({"arch": "deepseek41", "backend": "hip", "gpu": 0, "gpus_asked": True}))
|
||||
|
||||
def test_deepseek_on_amd_by_the_person_is_carried_over(self):
|
||||
self.assertTrue(self.kept({"arch": "deepseek41", "backend": "hip", "gpu": 2, "gpus_asked": True}))
|
||||
self.assertTrue(self.kept({"arch": "deepseek41", "backend": "hip", "gpu": 0, "gpus_asked": True, "gpus_by": "person"}))
|
||||
|
||||
def test_a_listing_that_fails_or_windows_cannot_stop_a_setup(self):
|
||||
def boom():
|
||||
raise OSError("no kfd")
|
||||
self.assertTrue(self.kept({"arch": "deepseek41", "backend": "hip", "gpu": 0, "gpus_asked": True}, boom))
|
||||
self.assertTrue(self.kept({"arch": "deepseek41", "backend": "hip", "gpu": 0, "gpus_asked": True}, win=True))
|
||||
self.assertTrue(setup.earlier_card_kept(Path("does-not-exist.json")))
|
||||
|
||||
|
||||
class Remember(unittest.TestCase):
|
||||
"""`strata launch --gpu N` / `setup --gpu N` on a DeepSeek AMD model is the person's choice from then on."""
|
||||
|
||||
def test_the_choice_is_saved_and_then_kept_by_every_later_launch(self):
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
path = Path(d) / "strata-ds.json"
|
||||
old = {"arch": "deepseek41", "backend": "hip", "gpu": 0, "gpus_asked": True, "args": ["--pack", "/p"]}
|
||||
path.write_text(json.dumps(old))
|
||||
self.assertIsNotNone(gpu_pick.remember(path, [0]))
|
||||
saved = json.loads(path.read_text())
|
||||
self.assertEqual((saved["gpu"], saved["gpus_by"], saved["args"]), (0, "person", ["--pack", "/p"]))
|
||||
from strata_cli.launch.runner import installed_cards
|
||||
self.assertEqual(installed_cards(saved, FOUR), [0]) # a person's card 0 is not widened again
|
||||
self.assertFalse(Path(str(path) + ".tmp").exists())
|
||||
|
||||
def test_other_configs_are_left_alone(self):
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
path = Path(d) / "strata-q.json"
|
||||
path.write_text(json.dumps({"arch": "qwen4exp", "backend": "hip", "gpu": 0}))
|
||||
self.assertIsNone(gpu_pick.remember(path, [1]))
|
||||
self.assertEqual(json.loads(path.read_text())["gpu"], 0)
|
||||
self.assertIsNone(gpu_pick.remember(Path(d) / "missing.json", [1]))
|
||||
|
||||
|
||||
class LauncherCards(unittest.TestCase):
|
||||
"""cards_for_launch: what the launcher puts on the engine matches what setup and the plan say."""
|
||||
|
||||
class Comp:
|
||||
def __init__(self, gpus):
|
||||
self.gpus, self.engine_vendor = gpus, "amd"
|
||||
|
||||
@property
|
||||
def usable_gpus(self):
|
||||
from strata_control import gpu_fit
|
||||
return gpu_fit.usable_cards([{**g, "usable": True} for g in self.gpus])[0]
|
||||
|
||||
class Cat:
|
||||
def __init__(self, gpus):
|
||||
self.comp = LauncherCards.Comp(gpus)
|
||||
|
||||
def computer(self):
|
||||
return self.comp
|
||||
|
||||
def cards(self, gpus, base, windows=False, gpus_named=None):
|
||||
from strata_cli.launch import runner
|
||||
from strata_cli.launch import settings as S
|
||||
s = S.LaunchSettings(family="deepseek41", gpus=gpus_named)
|
||||
with mock.patch.object(dsv41_fit, "_on_windows", lambda: windows):
|
||||
return runner.cards_for_launch(s, self.Cat(gpus), base=base)
|
||||
|
||||
def base(self, **kw):
|
||||
return {"arch": "deepseek41", "backend": "hip", **kw}
|
||||
|
||||
def test_nothing_named_on_linux_uses_every_card_in_roles_order(self):
|
||||
self.assertEqual(sorted(self.cards(FOUR, self.base())), [0, 1, 2, 3])
|
||||
|
||||
def test_an_old_config_of_setups_own_pick_is_widened_for_this_launch(self):
|
||||
self.assertEqual(sorted(self.cards(FOUR, self.base(gpu=0, gpus_asked=True))), [0, 1, 2, 3])
|
||||
|
||||
def test_a_card_the_person_named_is_kept(self):
|
||||
self.assertIsNone(self.cards(FOUR, self.base(gpu=2, gpus_asked=True)))
|
||||
self.assertIsNone(self.cards(FOUR, self.base(gpu=0, gpus_asked=True, gpus_by="person")))
|
||||
|
||||
def test_gpu_0_named_on_this_launch_is_one_card(self):
|
||||
self.assertEqual(self.cards(FOUR, self.base(), gpus_named=[0]), [0])
|
||||
|
||||
def test_windows_pins_the_one_card_setup_takes(self):
|
||||
self.assertEqual(self.cards([amd(0), amd(1)], self.base(gpus_by="setup", gpu=0, gpus_asked=True), windows=True), [0])
|
||||
|
||||
def test_an_apu_beside_a_discrete_card_leaves_nothing_to_split(self):
|
||||
self.assertIsNone(self.cards([apu(0), amd(1)], self.base(gpus_by="setup", gpu=1, gpus_asked=True)))
|
||||
|
||||
def test_mixed_cards_run_on_the_ones_the_package_has_code_for(self):
|
||||
self.assertEqual(self.cards([amd(0), amd(1, "gfx1100", 24.0)], self.base(gpus_by="setup", gpu=0, gpus_asked=True)), [0])
|
||||
|
||||
|
||||
class Launcher(unittest.TestCase):
|
||||
def test_installed_cards_skips_setups_own_pick_and_keeps_a_choice(self):
|
||||
from strata_cli.launch.runner import installed_cards
|
||||
|
||||
Reference in new issue
Block a user