Skip to content

The agent that grows with you

fix(local-runtime): Vulkan/HIP launches subtract what other programs hold on the card

teknium1c8301ea6c9b7
diff --git a/hermes_cli/local_runtime/hardware.py b/hermes_cli/local_runtime/hardware.py
index 187dd3fabd9..350bcd12283 100644
--- a/hermes_cli/local_runtime/hardware.py
+++ b/hermes_cli/local_runtime/hardware.py
@@ -348,13 +348,14 @@ def _device_pool_view() -> "tuple[int, bool | None] | None":
_accelerator_cache: "dict[str, tuple[float, dict | None]]" = {}
-def _accelerator_device() -> "dict | None":
+def _accelerator_device(*, fresh: bool = False) -> "dict | None":
"""The device a Vulkan/HIP engine will place layers on, or None (no such engine, probe miss).
Mirrors llama.cpp's own placement: discrete devices whenever one exists, an integrated one only
otherwise; among discrete devices the largest. Cached per engine binary like
``_device_pool_view`` (a hit lasts the process, a miss retries after the TTL): the hardware
- endpoint polls this every few seconds and each probe initializes the GPU driver.
+ endpoint polls this every few seconds and each probe initializes the GPU driver. ``fresh`` skips
+ the cache read for a launch-time free-memory answer.
"""
with suppress(Exception): # a probe miss must never block budgeting
from hermes_cli.local_runtime.devices import probe_devices
@@ -364,7 +365,7 @@ def _accelerator_device() -> "dict | None":
return None
key, now = str(engine.binary), time.monotonic()
cached = _accelerator_cache.get(key)
- if cached is not None and (cached[1] is not None or now - cached[0] < _POOL_NEGATIVE_TTL_S):
+ if not fresh and cached is not None and (cached[1] is not None or now - cached[0] < _POOL_NEGATIVE_TTL_S):
return cached[1]
devices = probe_devices(engine.binary.parent, engine.backend)
device = max(devices, key=lambda d: (d["type"] == GGML_DEVICE_GPU, d["total"]), default=None)
@@ -437,7 +438,7 @@ def probe_budget(*, planning: bool = False) -> HardwareBudget:
device = _accelerator_device()
if device is not None and device["type"] == GGML_DEVICE_GPU:
# Discrete AMD/Intel card behind a Vulkan/HIP engine: its own memory, with system RAM
- # as spill. Capacity serves the live view too; no per-poll free query exists here.
+ # as spill. Capacity serves the polled live view; launch_budget reads free memory.
total = device["total"]
margin = max(_MARGIN_FLOOR, int(total * _MARGIN_FRACTION))
return HardwareBudget(usable_vram_bytes=max(0, total - margin), total_device_bytes=total,
@@ -471,9 +472,14 @@ def launch_budget(capacity: HardwareBudget, *, own_bytes: int = 0) -> HardwareBu
if capacity.uma:
return None
vram = _nvidia_vram()
- if vram is None:
- return None
- total, free, _name, _pci_id = vram
+ if vram is not None:
+ total, free = vram[0], vram[1]
+ else:
+ # A discrete card behind Vulkan/HIP: the driver's free count includes other programs.
+ device = _accelerator_device(fresh=True)
+ if device is None or device["type"] != GGML_DEVICE_GPU:
+ return None
+ total, free = device["total"], device["free"]
others = max(0, total - free - max(0, own_bytes))
usable = min(capacity.usable_vram_bytes, max(0, total - others - _LAUNCH_HEADROOM))
return replace(capacity, usable_vram_bytes=usable)
diff --git a/tests/hermes_cli/test_local_launch_budget.py b/tests/hermes_cli/test_local_launch_budget.py
index 18bd0f9327e..ac169a89c1a 100644
--- a/tests/hermes_cli/test_local_launch_budget.py
+++ b/tests/hermes_cli/test_local_launch_budget.py
@@ -62,6 +62,26 @@ def test_launch_budget_subtracts_other_programs_plus_headroom(monkeypatch):
assert budget.total_device_bytes == CARD_TOTAL and budget.uma is False
+def test_launch_budget_reads_free_memory_on_a_vulkan_card(monkeypatch, tmp_path):
+ """Behind Vulkan/HIP (no nvidia-smi) the engine's own device probe reports free memory, and each
+ launch asks again: the cached capacity probe predates programs that started since."""
+ import hermes_cli.local_runtime.devices as devices
+
+ held_gib = [0.0]
+ monkeypatch.setattr(hardware, "_nvidia_vram", lambda: None)
+ monkeypatch.setattr(hardware, "_configured_engine",
+ lambda: SimpleNamespace(backend="vulkan", binary=tmp_path / "llama-server"))
+ monkeypatch.setattr(hardware, "_accelerator_cache", {})
+ monkeypatch.setattr(devices, "probe_devices", lambda directory, backend: [{
+ "description": "AMD Radeon RX 9060 XT", "type": 1, "total": CARD_TOTAL,
+ "free": CARD_TOTAL - int(held_gib[0] * GIB)}])
+ hardware._accelerator_device() # capacity cache warmed while the card was idle
+ held_gib[0] = 5.4
+
+ budget = hardware.launch_budget(CARD_CAPACITY)
+ assert budget.usable_vram_bytes == CARD_TOTAL - int(5.4 * GIB) - hardware._LAUNCH_HEADROOM
+
+
def test_launch_budget_never_exceeds_capacity(monkeypatch):
_card(monkeypatch, 0.0)
assert hardware.launch_budget(CARD_CAPACITY).usable_vram_bytes == CARD_CAPACITY.usable_vram_bytes
diff --git a/website/docs/user-guide/local-models.md b/website/docs/user-guide/local-models.md
index 5038a98845d..d28a66698b9 100644
--- a/website/docs/user-guide/local-models.md
+++ b/website/docs/user-guide/local-models.md
@@ -179,10 +179,13 @@ Selecting a local model as your main model uses the standard
**Linux:** Vulkan or CPU; the pinned release has no prebuilt CUDA archive.
**macOS:** Metal or CPU. HIP/ROCm is an explicit choice on supported x64
targets. Unsupported backend/target pairs fail before any download.
-- `backend: auto` picks CUDA for NVIDIA, Vulkan for AMD and Intel GPUs, and
- CPU only when no GPU is found. Behind a Vulkan or HIP engine, a discrete
- card is sized from its own memory (system RAM is spill space); an integrated
- GPU shares system RAM and is sized from that.
+- `backend: auto` prefers CUDA for NVIDIA and Vulkan for AMD and Intel GPUs,
+ then falls back to the builds listed above for your platform (CPU when no
+ GPU is found). Behind a Vulkan or HIP engine, a discrete card is sized from
+ its own memory (system RAM is spill space) and each launch subtracts what
+ other programs hold on it; an integrated GPU shares system RAM and is sized
+ from that. Quickstart installs the engine before choosing the model, so the
+ pick reflects the card.
- A GPU with 8 GB+ of memory runs the small catalog models comfortably;
16 GB+ runs the 27–35B models at high quality.
- Model completeness is checked against the server's response, not catalog