setup: a calibration on Linux HIP names the AMD card and is reused for it (#566)
hardware_key, the settings file's key for a saved calibration, read the cards with nvidia-smi's list: on an AMD PC
every card was "?|0GB" (two different cards shared one calibration), and on a PC with an NVIDIA card too a HIP index
named that NVIDIA card or stopped setup ("there is no GPU N"). A HIP config's cards now come from amd_gpus, in HIP's
numbering, with the architecture in the name (an RX 7900 XTX and an RX 7900 XT are both gfx1100; a card without a
product name is known by its arch). Setup reuses a saved calibration on Linux HIP as on NVIDIA (setup_calibration);
Windows HIP keeps the defaults for now. The tuning is still offered on NVIDIA only - a `./setup.sh --calibrate` on
HIP runs it by hand, and each control is verified on HIP before setup offers it.
The NVIDIA key and the settings file's format are unchanged. Tests: tools/test_setup_amd.py CalibrationKey (7).
This commit is contained in:
1 parent
5c50fbbcf2
commit
19dbffde75
2 files changed
+114
-3
No files matched your search
@@ -2479,11 +2479,37 @@ def is_wsl() -> bool:
|
||||
return sys.platform.startswith("linux") and "microsoft" in platform.uname().release.lower()
|
||||
|
||||
|
||||
def hip_config_cards(sel) -> list[dict]:
|
||||
"""#566: the AMD cards a HIP config runs on - its "gpu" (one index or a list) in HIP's numbering, as amd_gpus
|
||||
lists them; no "gpu": the supported card with the most VRAM, as setup picks it. Each card's name carries its
|
||||
architecture (an RX 7900 XTX and an RX 7900 XT are both gfx1100; a card without a product name in sysfs is known
|
||||
by its arch only). A card that is not found is {} (the key then says "?")."""
|
||||
amd = amd_gpus()
|
||||
if sel is None:
|
||||
usable = [g for g in amd if amd_problem(g) is None]
|
||||
sel = max(usable, key=lambda x: (round(x["vram_gb"]), -x["index"]))["index"] if usable else None
|
||||
byid = {g["index"]: g for g in amd}
|
||||
cards = []
|
||||
for i in (sel if isinstance(sel, list) else [sel]):
|
||||
g = byid.get(i)
|
||||
if g is None:
|
||||
cards.append({})
|
||||
continue
|
||||
arch = g.get("arch") or ""
|
||||
name = g.get("name") or "?"
|
||||
cards.append({**g, "name": name if not arch or arch in name else f"{name} ({arch})"})
|
||||
return cards
|
||||
|
||||
|
||||
def hardware_key(cfg: dict) -> str:
|
||||
"""What a calibration is valid for: this GPU, CPU and RAM, and the model with its context and images setting
|
||||
(the context's KV cache and the image encoder take VRAM from the expert cache)."""
|
||||
(the context's KV cache and the image encoder take VRAM from the expert cache). #566: a HIP config's cards are
|
||||
AMD's (hip_config_cards) - nvidia-smi's list named them "?" (or another card with that number) before."""
|
||||
sel = cfg.get("gpu")
|
||||
gl = [gpu_info(i) or {} for i in sel] if isinstance(sel, list) else [gpu_info(sel) or {}]
|
||||
if cfg.get("backend") == "hip":
|
||||
gl = hip_config_cards(sel)
|
||||
else:
|
||||
gl = [gpu_info(i) or {} for i in sel] if isinstance(sel, list) else [gpu_info(sel) or {}]
|
||||
g = {"name": " + ".join(x.get("name", "?") for x in gl), "vram_gb": sum(x.get("vram_gb", 0) for x in gl)}
|
||||
a = cfg.get("args", [])
|
||||
ctx = a[a.index("--max-context") + 1] if "--max-context" in a else "?"
|
||||
@@ -2532,6 +2558,16 @@ def saved_calibration(cfg: dict) -> dict | None:
|
||||
return (load_settings().get("calibration") or {}).get(hardware_key(cfg))
|
||||
|
||||
|
||||
def setup_calibration(cfg: dict, hip: bool) -> dict | None:
|
||||
"""The calibration a (re-)install applies to its new config: the one saved for this PC and model. #566: on Linux
|
||||
HIP too - hardware_key now names the AMD cards, so a `./setup.sh --calibrate` run is matched to its card and
|
||||
model. Windows HIP keeps the defaults for now (not tried there). Setup still offers the tuning itself on NVIDIA
|
||||
only: each control is verified on HIP first."""
|
||||
if hip and WIN:
|
||||
return None
|
||||
return saved_calibration(cfg)
|
||||
|
||||
|
||||
def upgrade_config(cfg_path: Path, cfg: dict) -> dict:
|
||||
"""Configs written before v0.1.13 read prompts in fixed 2048-token chunks; the engine now picks the chunk
|
||||
itself (`--prefill auto`: up to 8192, as the free VRAM allows - about 2x faster on long prompts). Under WSL,
|
||||
@@ -3661,7 +3697,7 @@ def main() -> int:
|
||||
if vision == "cpu":
|
||||
cfg["vision"]["threads"] = max(1, (os.cpu_count() or 8) // 2)
|
||||
cfg_path = ROOT / f"strata-{tag.lower()}.json"
|
||||
cal = None if hip else saved_calibration(cfg) # tools/calibrate.py is NVIDIA-only for now
|
||||
cal = setup_calibration(cfg, hip) # #566: Linux HIP too; the tuning is offered on NVIDIA only
|
||||
if cal is not None:
|
||||
sys.path.insert(0, str(ROOT / "tools"))
|
||||
import calibrate as CAL
|
||||
|
||||
@@ -336,6 +336,81 @@ def setup_hip(text):
|
||||
return _HIP_DEVICES(text=text)
|
||||
|
||||
|
||||
class CalibrationKey(unittest.TestCase):
|
||||
"""#566: a calibration is saved and found again per PC and model (hardware_key). A HIP config's cards are AMD's,
|
||||
in HIP's numbering - nvidia-smi named them "?" (or another card with that number) before - and setup reuses a
|
||||
saved calibration on Linux HIP. The NVIDIA key and the settings file's format are unchanged."""
|
||||
AMD = [{"index": 0, "name": "AMD Radeon RX 7900 XTX", "vram_gb": 23.98, "arch": "gfx1100"},
|
||||
{"index": 1, "name": "AMD Radeon RX 7900 XT", "vram_gb": 19.98, "arch": "gfx1100"},
|
||||
{"index": 2, "name": "AMD Radeon (gfx1201)", "vram_gb": 15.92, "arch": "gfx1201"},
|
||||
{"index": 3, "name": "AMD Radeon (gfx1036)", "vram_gb": 0.5, "arch": "gfx1036"}]
|
||||
|
||||
def setUp(self):
|
||||
self.patches = [mock.patch.object(setup, "amd_gpus", lambda *a, **k: [dict(g) for g in self.AMD]),
|
||||
mock.patch.object(setup, "cpu_info", lambda: ("AMD Ryzen 9 7950X", 16)),
|
||||
mock.patch.object(setup, "ram_gb", lambda: 63.6)]
|
||||
for p in self.patches:
|
||||
p.start()
|
||||
|
||||
def tearDown(self):
|
||||
for p in self.patches:
|
||||
p.stop()
|
||||
|
||||
@staticmethod
|
||||
def cfg(gpu, backend="hip", ctx="32768"):
|
||||
c = {"model_name": "qwen3.8-flash-next-iq3_xxs", "args": ["--max-context", ctx, "--kv", "int8"], "gpu": gpu}
|
||||
if backend:
|
||||
c["backend"] = backend
|
||||
return c
|
||||
|
||||
def test_hip_key_names_the_amd_card_and_its_arch(self):
|
||||
def no_nvidia(*a, **k): # a HIP config never asks nvidia-smi (a PC with both kinds)
|
||||
raise AssertionError("gpu_info called for a HIP config")
|
||||
with mock.patch.object(setup, "gpu_info", no_nvidia):
|
||||
self.assertEqual(setup.hardware_key(self.cfg(0)),
|
||||
"AMD Radeon RX 7900 XTX (gfx1100)|24GB|AMD Ryzen 9 7950X|64GB|qwen3.8-flash-next-iq3_xxs|"
|
||||
"32768|text")
|
||||
# the arch is not repeated when the name already holds it (no product name in sysfs)
|
||||
self.assertTrue(setup.hardware_key(self.cfg(2)).startswith("AMD Radeon (gfx1201)|16GB|"))
|
||||
|
||||
def test_two_cards_of_one_arch_are_two_keys(self):
|
||||
keys = {setup.hardware_key(self.cfg(i)) for i in (0, 1, 2)}
|
||||
self.assertEqual(len(keys), 3)
|
||||
|
||||
def test_a_split_names_every_card(self):
|
||||
self.assertTrue(setup.hardware_key(self.cfg([1, 0])).startswith(
|
||||
"AMD Radeon RX 7900 XT (gfx1100) + AMD Radeon RX 7900 XTX (gfx1100)|44GB|"))
|
||||
|
||||
def test_no_gpu_in_the_config_is_the_supported_card_with_the_most_vram(self):
|
||||
self.assertTrue(setup.hardware_key(self.cfg(None)).startswith("AMD Radeon RX 7900 XTX (gfx1100)|24GB|"))
|
||||
|
||||
def test_a_card_that_is_gone_is_unknown(self):
|
||||
self.assertTrue(setup.hardware_key(self.cfg(7)).startswith("?|0GB|"))
|
||||
|
||||
def test_nvidia_key_unchanged(self):
|
||||
def amd(*a, **k):
|
||||
raise AssertionError("amd_gpus called for an NVIDIA config")
|
||||
with mock.patch.object(setup, "amd_gpus", amd), \
|
||||
mock.patch.object(setup, "gpu_info", lambda i=None: {"name": "NVIDIA GeForce RTX 5070", "vram_gb": 11.94}):
|
||||
self.assertEqual(setup.hardware_key(self.cfg(0, backend=None)),
|
||||
"NVIDIA GeForce RTX 5070|12GB|AMD Ryzen 9 7950X|64GB|qwen3.8-flash-next-iq3_xxs|32768|text")
|
||||
self.assertEqual(setup.hardware_key(self.cfg([0, 1], backend="cuda")),
|
||||
"NVIDIA GeForce RTX 5070 + NVIDIA GeForce RTX 5070|24GB|AMD Ryzen 9 7950X|64GB|"
|
||||
"qwen3.8-flash-next-iq3_xxs|32768|text")
|
||||
|
||||
def test_setup_reuses_a_saved_calibration_on_linux_hip(self):
|
||||
cfg = self.cfg(1)
|
||||
saved = {"settings": {"pcie_frac": 0.0}, "tok_s": 40.1, "date": "2026-10-03"}
|
||||
other = {"settings": {"pcie_frac": 0.5}, "tok_s": 50.0, "date": "2026-10-02"}
|
||||
store = {"calibration": {setup.hardware_key(cfg): saved, setup.hardware_key(self.cfg(0)): other}}
|
||||
with mock.patch.object(setup, "load_settings", lambda: store):
|
||||
with mock.patch.object(setup, "WIN", False):
|
||||
self.assertEqual(setup.setup_calibration(cfg, hip=True), saved) # its own card's, not the XTX's
|
||||
self.assertIsNone(setup.setup_calibration(self.cfg(2), hip=True)) # never tuned on that card
|
||||
with mock.patch.object(setup, "WIN", True):
|
||||
self.assertIsNone(setup.setup_calibration(cfg, hip=True)) # Windows HIP: defaults for now
|
||||
|
||||
|
||||
class WindowsHipVision(unittest.TestCase):
|
||||
def test_no_cpu_encoder_on_windows(self):
|
||||
with mock.patch.object(setup, "WIN", True), mock.patch.object(setup, "warn", lambda *a: None):
|
||||
|
||||
Reference in new issue
Block a user