Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: keep the GPU order the user asked for instead of re-emitting it ascending (#11034)

Leo Borcherding39268d393918
diff --git a/studio/backend/core/inference/llama_cpp.py b/studio/backend/core/inference/llama_cpp.py
index 7ce13beda5e..6d32fb898e6 100644
--- a/studio/backend/core/inference/llama_cpp.py
+++ b/studio/backend/core/inference/llama_cpp.py
@@ -6787,6 +6787,23 @@ def _write_direct_stream_key(key: str) -> "Path":
return path
+def _extra_args_have_tensor_split(
+ extra_args: Optional[Iterable[str]], env: Optional[Mapping[str, str]]
+) -> bool:
+ """PRESENCE of a pass-through split, parseable or not, in argv or the CHILD env.
+
+ _extra_args_tensor_split returns None for a value it cannot parse, and the repointer
+ does no numeric validation and takes the LAST occurrence, so a parse-check veto lets
+ the repointer permute a user share it exists to protect. Reads the child env rather
+ than os.environ because LLAMA_ARG_TENSOR_SPLIT is scrubbed before this point, and a
+ value the child never receives must not suppress the reorder.
+ """
+ for token in extra_args or ():
+ if str(token).split("=", 1)[0] in ("--tensor-split", "-ts", "--tensor_split"):
+ return True
+ return bool(str((env or {}).get("LLAMA_ARG_TENSOR_SPLIT", "")).strip())
+
+
class LlamaCppBackend:
"""Manages a llama-server subprocess for GGUF model inference.
@@ -9744,6 +9761,54 @@ class LlamaCppBackend:
return (int(parent_gpu_ids[0]),)
return None
+ @staticmethod
+ def _inherited_child_gpu_order(pinned_ids: Iterable[int]) -> Optional[list[int]]:
+ """``pinned_ids`` in the parent mask's order, or None to keep them as given.
+
+ A numeric visibility mask defines enumeration ORDER as well as membership
+ (CUDA_VISIBLE_DEVICES=1,0 makes physical 1 the child's device 0), and every
+ producer of gpu_indices sorts ascending, so re-emitting it verbatim silently
+ reverses a deliberate reordering and the user has no way to place a card
+ first. Same rule _pin_visible_gpu_order_for_split applies to a manual
+ --tensor-split, which is where it was already spelled out.
+
+ Only when the mask covers the whole pinned set: a partial mask cannot say
+ where the ids it omits belong. None when the order is already what we would
+ emit, so callers can treat non-None as "this changed something".
+ """
+ inherited = LlamaCppBackend._resolve_visible_physical_ids()
+ if not inherited:
+ return None
+ wanted = [int(i) for i in pinned_ids]
+ ordered = [i for i in inherited if i in set(wanted)]
+ if sorted(ordered) != sorted(wanted) or ordered == wanted:
+ return None
+ return ordered
+
+ @staticmethod
+ def _repoint_emitted_tensor_split(
+ cmd: list, old_order: list[int], new_order: list[int]
+ ) -> bool:
+ """Move Unsloth's own ``--tensor-split`` shares onto the reordered devices.
+
+ _plan_tensor_parallel returns the shares positional over gpu_indices, so a
+ reordered mask without this hands the roomier card's share to the smaller
+ one. Returns False when the shares cannot be moved, which vetoes the whole
+ reorder: emitting the mask alone would be the same bug.
+ """
+ try:
+ at = len(cmd) - 1 - cmd[::-1].index("--tensor-split")
+ except ValueError:
+ return True # no shares emitted, nothing positional to carry
+ if at + 1 >= len(cmd):
+ return False
+ shares = cmd[at + 1].split(",")
+ if len(shares) != len(old_order):
+ return False
+ by_id = dict(zip(old_order, shares))
+ cmd[at + 1] = ",".join(by_id[i] for i in new_order)
+ return True
+
@staticmethod
def _pin_visible_gpu_order_for_split(env: dict) -> Optional[tuple[int, ...]]:
"""Pin the child's GPU enumeration to the picker's order for a manual
@@ -11261,6 +11326,16 @@ class LlamaCppBackend:
except Exception:
return False
+ def _gpu_ids_own_placement(self, gpu_ids) -> bool:
+ """Whether a ``gpu_ids`` pick overrules a user ``--device`` / ``--main-gpu``.
+
+ One predicate, not eleven copies: launch, fit classifier, cache tuning and
+ reload comparator disagreeing is how the argv and the already-loaded check
+ drift apart. Letting a full-set pick relinquish to a pass-through was tried
+ and withdrawn; the inherited-mask reorder already supplies that ordering.
+ """
+ return gpu_ids is not None
+
@staticmethod
def _strip_device_extra_args(extra_args):
"""Drop device and main-GPU flags so gpu_ids remains authoritative."""
@@ -20344,22 +20419,20 @@ class LlamaCppBackend:
@staticmethod
def _cache_tuning_target_unknown(
- extra_args: Optional[Iterable[str]],
- gpu_ids: Optional[Iterable[int]],
- env: Mapping[str, str],
+ extra_args: Optional[Iterable[str]], device_flags_owned: bool, env: Mapping[str, str]
) -> bool:
"""Whether the device this cache tuning would be chosen against is the one
the child actually gets.
A user device selection is not stripped on an automatic load and llama.cpp
reads it last (argv) or first (env, before argv either way), so it, not the
- automatic placement, names the target. Both spellings count: only an explicit
- ``gpu_ids`` clears LLAMA_ARG_DEVICE, so on an automatic load the env twin
- survives into the child verbatim. Fail-closed by design -- the failure that
+ automatic placement, names the target. Both spellings count: only a pick that
+ OWNS placement clears LLAMA_ARG_DEVICE, so otherwise the env twin survives
+ into the child verbatim. Fail-closed by design -- the failure that
matters is emitting --cache-ram 0 against a shared pool, while keeping the
prompt cache on a discrete card only forgoes a tuning.
"""
- if gpu_ids is not None:
+ if device_flags_owned:
return False
return bool(
_extra_args_set_any_flag(extra_args, _DEVICE_FLAGS)
@@ -21746,6 +21819,9 @@ class LlamaCppBackend:
reasoning_budget_message = reasoning_budget_message,
)
is_vulkan_backend = self._is_vulkan_backend(binary)
+ # Once, and reused everywhere the strip is asked about: the reload
+ # comparator has to reach the same answer as the argv it compares against.
+ _gpu_ids_own_device_flags = self._gpu_ids_own_placement(gpu_ids)
_vulkan_ordinal_pin = (
is_vulkan_backend and bool(gpu_ids) and gpu_ids_are_vulkan_ordinals is not False
)
@@ -24811,13 +24887,13 @@ class LlamaCppBackend:
# strips. Unpinned, the child inherits LLAMA_ARG_DEVICE verbatim.
_fit_extras = (
self._strip_device_extra_args(extra_args)
- if gpu_ids is not None
+ if _gpu_ids_own_device_flags
else extra_args
)
_fit_env = dict(os.environ)
if gpu_memory_mode == "manual":
self._clear_manual_placement_env(_fit_env)
- if gpu_ids is not None:
+ if _gpu_ids_own_device_flags:
self._clear_device_placement_env(_fit_env)
# What the placement branch below will emit, so the effective
# (last-wins) fitter state is readable before the final argv exists.
@@ -25634,7 +25710,9 @@ class LlamaCppBackend:
# Speculative decoding. See _build_speculative_flags for the
# mode resolution, benchmarks, and llama.cpp references.
_vulkan_pin_ids = gpu_indices if gpu_indices is not None else (gpu_ids or None)
- _draft_device = _extra_args_main_device(extra_args) if gpu_ids is None else None
+ _draft_device = (
+ _extra_args_main_device(extra_args) if not _gpu_ids_own_device_flags else None
+ )
if _draft_device is None and is_vulkan_backend and _vulkan_pin_ids:
_draft_device = ",".join(f"Vulkan{i}" for i in _vulkan_pin_ids)
launch_mtp_draft_path = self._resolve_launch_mtp_path(
@@ -25723,7 +25801,7 @@ class LlamaCppBackend:
if gpu_memory_mode == "manual":
self._clear_manual_placement_env(_spec_placement_env)
_spec_placement_extras = extra_args
- if gpu_ids is not None:
+ if _gpu_ids_own_device_flags:
_spec_placement_extras = self._strip_device_extra_args(extra_args)
self._clear_device_placement_env(_spec_placement_env)
# A device the launch really carries, and not the CPU spelling of it.
@@ -26080,7 +26158,7 @@ class LlamaCppBackend:
# LLAMA_ARG_DEVICE, and llama.cpp reads it before argv, so an automatic
# load can place against a target the generated pin never names.
_cache_target_unknown = self._cache_tuning_target_unknown(
- extra_args, gpu_ids, os.environ
+ extra_args, _gpu_ids_own_device_flags, os.environ
)
_shared_memory_offload = (
sys.platform == "win32"
@@ -26236,7 +26314,7 @@ class LlamaCppBackend:
# so classifying on them would pin for a --device cpu the child
# never sees. Same helpers the launch uses, so they cannot drift.
_mem_extra_args = extra_args
- if gpu_ids is not None:
+ if _gpu_ids_own_device_flags:
_mem_extra_args = self._strip_device_extra_args(extra_args)
self._clear_device_placement_env(_mem_env)
_mem_keep_resident, _mem_no_reserve = _mem_settings
@@ -26522,7 +26600,7 @@ class LlamaCppBackend:
# below when the Unsloth picker owns the GPU selection.
if _mem_extras:
_emit_extra_args = list(_mem_extras)
- if gpu_ids is not None:
+ if _gpu_ids_own_device_flags:
# gpu_ids owns placement, so remove competing device flags.
_before_device_strip = list(_emit_extra_args)
_emit_extra_args = self._strip_device_extra_args(_emit_extra_args)
@@ -26535,7 +26613,6 @@ class LlamaCppBackend:
logger.info(
f"Appending user extra args to llama-server: {list(_emit_extra_args)}"
)
-
# Last so it wins: the drafter CPU pin on a virtualised Metal device
# is a correctness fix, not a preference, and llama.cpp is last-wins.
if _pv_draft_cpu_pin:
@@ -26773,7 +26850,7 @@ class LlamaCppBackend:
env.pop("LLAMA_ARG_TENSOR_SPLIT", None)
# A gpu_ids pin also owns inherited device placement.
- if gpu_ids is not None:
+ if _gpu_ids_own_device_flags:
self._clear_device_placement_env(env)
# After the scrubs above, so a placement this launch already dropped
@@ -27133,14 +27210,38 @@ class LlamaCppBackend:
# we cannot pin, _p2p_veto_reason withholds the flag.
if _p2p_launch_order_pinned:
env["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
+ # The set is ours to pin, but the ORDER is the user's to choose,
+ # and gpu_indices is ascending at every producer. Keep a mask that
+ # deliberately reorders the same cards.
+ _pin_ids = list(gpu_indices)
+ _inherited_order = self._inherited_child_gpu_order(_pin_ids)
+ if _inherited_order is not None:
+ # A user --tensor-split is positional over the order they
+ # expected, so reordering under it re-weights the wrong cards.
+ # Theirs to own: decline instead of rewriting it.
+ if _extra_args_have_tensor_split(extra_args, env):
+ logger.info(
+ "Keeping ascending GPU order: a pass-through "
+ "--tensor-split is positional over it."
+ )
+ elif self._repoint_emitted_tensor_split(cmd, _pin_ids, _inherited_order):
+ logger.info(
+ "Pinning the child's GPU order to the inherited "
+ "visibility mask: %s (ascending would be %s).",
+ _inherited_order,
+ _pin_ids,
+ )
+ _pin_ids = _inherited_order
# Mask on AMD at the ROCr/HSA layer: HIP-only masking still
# enumerates every agent first, which segfaults on a deselected
# unsupported GPU (e.g. gfx1036 iGPU under a gfx103X prebuilt).
self._emit_child_gpu_visibility(
- env, LlamaCppBackend._child_visibility_for(gpu_indices), prefer_rocr = True
+ env,
+ LlamaCppBackend._child_visibility_for(_pin_ids),
+ prefer_rocr = True,
)
- _child_gpu_physical_ids = tuple(int(i) for i in gpu_indices)
- _launch_pinned_ids = list(gpu_indices)
+ _child_gpu_physical_ids = tuple(int(i) for i in _pin_ids)
+ _launch_pinned_ids = list(_pin_ids)
elif not is_vulkan_backend and not gpu_ids:
# Nothing above pinned the child. Two shapes land here and the gate
# breaks both the same way, so they share one probe: `--fit on`
@@ -29166,7 +29267,7 @@ class LlamaCppBackend:
# can't resurrect the dropped --device (#7188).
self._extra_args = (
self._strip_device_extra_args(extra_args)
- if gpu_ids is not None
+ if _gpu_ids_own_device_flags
else list(extra_args)
)
# Device-stripped the same way, so both comparator sides share a rule.
@@ -29187,7 +29288,7 @@ class LlamaCppBackend:
)
self._requested_extra_args = (
self._strip_device_extra_args(_pv_requested)
- if gpu_ids is not None
+ if _gpu_ids_own_device_flags
else list(_pv_requested)
)
self._extra_args_source = (model_identifier, hf_variant)
@@ -29930,7 +30031,7 @@ class LlamaCppBackend:
list(intent.extra_args) if intent.extra_args is not None else self._extra_args
)
candidate_extra_args = list(effective_extra_args) if effective_extra_args else []
- if intent.extra_args is not None and intent.gpu_ids is not None:
+ if intent.extra_args is not None and self._gpu_ids_own_placement(intent.gpu_ids):
candidate_extra_args = self._strip_device_extra_args(candidate_extra_args)
# A Model Memory toggle changes only the launch flags, so the intent is
# unchanged and this would otherwise report already-loaded and leave the
@@ -31856,7 +31957,7 @@ class LlamaCppBackend:
if fallback_extra_args is not snapshot.extra_args:
self._requested_extra_args = (
self._strip_device_extra_args(_ea)
- if snapshot.gpu_ids is not None
+ if self._gpu_ids_own_placement(snapshot.gpu_ids)
else list(_ea)
)
# Restore the requested mode + reason load_model("off") cleared,
diff --git a/studio/backend/tests/test_gpu_order_preserved.py b/studio/backend/tests/test_gpu_order_preserved.py
new file mode 100644
index 00000000000..b91ccb0ebbf
--- /dev/null
+++ b/studio/backend/tests/test_gpu_order_preserved.py
@@ -0,0 +1,181 @@
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+"""The child's GPU ORDER, which is separate from the set the picker chooses.
+
+Two ways a user can ask for a specific order, and neither used to survive: a
+reordered CUDA_VISIBLE_DEVICES was re-emitted ascending, and a pass-through
+--device was stripped by a picker selection that narrowed nothing.
+"""
+
+from __future__ import annotations
+
+import sys
+from pathlib import Path
+
+sys.path.insert(0, str(Path(__file__).resolve().parent))
+
+from test_llama_cpp_placement import _backend, _launch # noqa: E402
+
+from core.inference.llama_cpp import LlamaCppBackend # noqa: E402
+
+# One roomier card and one smaller one, so a weighted split is the interesting case.
+_TWO_GPUS = [(0, 15_000, 16_000), (1, 11_000, 12_000)]
+
+
+def _run(
+ monkeypatch,
+ tmp_path,
+ *,
+ mask,
+ gpu_ids = None,
+ extra_args = None,
+):
+ if mask is None:
+ monkeypatch.delenv("CUDA_VISIBLE_DEVICES", raising = False)
+ else:
+ monkeypatch.setenv("CUDA_VISIBLE_DEVICES", mask)
+ monkeypatch.setenv("CUDA_DEVICE_ORDER", "PCI_BUS_ID")
+ backend, gguf = _backend(tmp_path, vulkan = False, memory = _TWO_GPUS)
+ backend._select_gpus = lambda *args, **kwargs: ([0, 1], False)
+ kwargs = {} if extra_args is None else {"extra_args": extra_args}
+ result = _launch(backend, gguf, n_ctx = 4096, gpu_ids = gpu_ids, **kwargs)
+ return backend, result
+
+
+def _device_arg(cmd):
+ return cmd[cmd.index("--device") + 1] if "--device" in cmd else None
+
+
+def test_reordered_parent_mask_reaches_the_child(monkeypatch, tmp_path):
+ """A numeric mask carries ORDER, not just membership, so it must survive."""
+ _, result = _run(monkeypatch, tmp_path, mask = "1,0")
+ assert result["env"]["CUDA_VISIBLE_DEVICES"] == "1,0"
+
+
+def test_reordered_parent_mask_survives_a_gpu_pick(monkeypatch, tmp_path):
+ """The picker owns the SET; the mask still owns the order within it."""
+ backend, result = _run(monkeypatch, tmp_path, mask = "1,0", gpu_ids = [0, 1])
+ assert result["env"]["CUDA_VISIBLE_DEVICES"] == "1,0"
+ # The ordinal -> physical map the buffer parser reads has to match what we emitted.
+ assert backend._child_gpu_physical_ids == (1, 0)
+
+
+def test_ascending_parent_mask_is_left_alone(monkeypatch, tmp_path):
+ _, result = _run(monkeypatch, tmp_path, mask = "0,1")
+ assert result["env"]["CUDA_VISIBLE_DEVICES"] == "0,1"
+
+
+def test_partial_mask_cannot_order_the_rest(monkeypatch, tmp_path):
+ """A mask covering only some pinned ids says nothing about where the others go."""
+ _, result = _run(monkeypatch, tmp_path, mask = "1")
+ assert result["env"]["CUDA_VISIBLE_DEVICES"] == "0,1"
+
+
+def test_tensor_split_shares_follow_the_reorder(monkeypatch, tmp_path):
+ """--tensor-split is positional, so the shares move with the devices."""
+ cmd = ["llama-server", "--tensor-split", "60,40", "--top-k", "5"]
+ assert LlamaCppBackend._repoint_emitted_tensor_split(cmd, [0, 1], [1, 0]) is True
+ assert cmd[cmd.index("--tensor-split") + 1] == "40,60"
+ assert cmd[cmd.index("--top-k") + 1] == "5"
+
+
+def test_tensor_split_repoint_declines_a_mismatched_width(monkeypatch, tmp_path):
+ """Refusing vetoes the reorder; emitting the mask alone would be the same bug."""
+ cmd = ["llama-server", "--tensor-split", "60"]
+ assert LlamaCppBackend._repoint_emitted_tensor_split(cmd, [0, 1], [1, 0]) is False
+ assert cmd[cmd.index("--tensor-split") + 1] == "60"
+
+
+def test_user_tensor_split_keeps_ascending_order(monkeypatch, tmp_path):
+ """Their shares are positional over the order they expected. Decline, don't rewrite."""
+ _, result = _run(monkeypatch, tmp_path, mask = "1,0", extra_args = ["--tensor-split", "60,40"])
+ assert result["env"]["CUDA_VISIBLE_DEVICES"] == "0,1"
+ assert result["cmd"][result["cmd"].index("--tensor-split") + 1] == "60,40"
+
+
+def test_narrowing_pick_still_owns_device_flags(monkeypatch, tmp_path):
+ """A --device naming a deselected card must not outlive the picker."""
+ backend, gguf = _backend(tmp_path, vulkan = False, memory = _TWO_GPUS)
+ monkeypatch.setenv("CUDA_VISIBLE_DEVICES", "0,1")
+ backend._select_gpus = lambda *args, **kwargs: ([1], False)
+ result = _launch(
+ backend,
+ gguf,
+ n_ctx = 4096,
+ gpu_ids = [1],
+ extra_args = ["--device", "CUDA0", "--top-k", "5"],
+ )
+ assert _device_arg(result["cmd"]) is None
+ assert result["cmd"][result["cmd"].index("--top-k") + 1] == "5"
+
+
+def test_an_unparseable_user_split_still_vetoes_the_reorder(monkeypatch, tmp_path):
+ """The veto is presence, not a successful parse: the repointer does no numeric
+ validation and takes the LAST --tensor-split, which is the user's."""
+ _, result = _run(monkeypatch, tmp_path, mask = "1,0", extra_args = ["--tensor-split", "3x,1"])
+ cmd = result["cmd"]
+ assert result["env"]["CUDA_VISIBLE_DEVICES"] == "0,1"
+ assert cmd[len(cmd) - 1 - cmd[::-1].index("--tensor-split") + 1] == "3x,1"
+
+
+def test_a_split_scrubbed_from_the_child_does_not_veto(monkeypatch, tmp_path):
+ """A tensor-parallel launch clears LLAMA_ARG_TENSOR_SPLIT from the child, so
+ reading os.environ let a value the child never receives suppress the reorder.
+
+ Off this path the child DOES inherit it, and the veto is right to fire; that is
+ the control below.
+ """
+ monkeypatch.setenv("CUDA_VISIBLE_DEVICES", "1,0")
+ monkeypatch.setenv("CUDA_DEVICE_ORDER", "PCI_BUS_ID")
+ monkeypatch.setenv("LLAMA_ARG_TENSOR_SPLIT", "60,40")
+ backend, gguf = _backend(tmp_path, vulkan = False, memory = _TWO_GPUS)
+ backend._get_gguf_size_bytes = lambda _path: 14 * 1024**3
+ backend._select_gpus = lambda *args, **kwargs: ([0, 1], False)
+ result = _launch(backend, gguf, n_ctx = 4096, gpu_ids = [0, 1], tensor_parallel = True)
+ assert result["env"].get("LLAMA_ARG_TENSOR_SPLIT") is None
+ assert result["env"]["CUDA_VISIBLE_DEVICES"] == "1,0"
+
+
+def test_a_split_the_child_does_inherit_still_vetoes(monkeypatch, tmp_path):
+ """The control: the child receives it here, so it is positional over the order
+ the user expected and the reorder must decline."""
+ monkeypatch.setenv("LLAMA_ARG_TENSOR_SPLIT", "60,40")
+ _, result = _run(monkeypatch, tmp_path, mask = "1,0")
+ assert result["env"].get("LLAMA_ARG_TENSOR_SPLIT") == "60,40"
+ assert result["env"]["CUDA_VISIBLE_DEVICES"] == "0,1"
+
+
+def test_an_explicit_pick_always_owns_device_flags(monkeypatch, tmp_path):
+ """Withdrawn: a pick covering the whole visible set used to relinquish device
+ flags so a pass-through --device could order the cards. The mask reorder above
+ already does that, and the pass-through cost a recomputation every consumer of
+ the strip had to agree about, so an explicit pick owns placement again.
+ """
+ backend, _ = _backend(tmp_path, vulkan = False, memory = _TWO_GPUS)
+ monkeypatch.setenv("CUDA_VISIBLE_DEVICES", "0,1")
+ own = backend._gpu_ids_own_placement
+ assert own([0, 1]) is True
+ assert own([1]) is True
+ assert own(None) is False
+
+
+def test_a_full_set_pick_strips_a_device_flag(monkeypatch, tmp_path):
+ """Both spellings, including the env twin, which needs no user argv at all."""
+ monkeypatch.setenv("LLAMA_ARG_DEVICE", "CUDA0")
+ _, result = _run(
+ monkeypatch,
+ tmp_path,
+ mask = "0,1",
+ gpu_ids = [0, 1],
+ extra_args = ["--device", "CUDA1,CUDA0"],
+ )
+ assert _device_arg(result["cmd"]) is None
+ assert result["env"].get("LLAMA_ARG_DEVICE") is None
+
+
+def test_the_mask_is_still_how_a_full_pick_orders_its_cards(monkeypatch, tmp_path):
+ """The ordering route the withdrawn pass-through was meant to preserve."""
+ backend, result = _run(monkeypatch, tmp_path, mask = "1,0", gpu_ids = [0, 1])
+ assert result["env"]["CUDA_VISIBLE_DEVICES"] == "1,0"
+ assert backend._child_gpu_physical_ids == (1, 0)
diff --git a/studio/backend/tests/test_shared_memory_offload_keeps_the_prompt_cache.py b/studio/backend/tests/test_shared_memory_offload_keeps_the_prompt_cache.py
index 6a65f54f2f0..af24e756bf5 100644
--- a/studio/backend/tests/test_shared_memory_offload_keeps_the_prompt_cache.py
+++ b/studio/backend/tests/test_shared_memory_offload_keeps_the_prompt_cache.py
@@ -239,23 +239,23 @@ def test_a_trailing_flag_without_its_value_is_left_alone():
def test_a_user_device_flag_makes_the_target_unknown():
- assert LlamaCppBackend._cache_tuning_target_unknown(["--device", "ROCm1"], None, {})
+ assert LlamaCppBackend._cache_tuning_target_unknown(["--device", "ROCm1"], False, {})
def test_an_inherited_device_env_makes_the_target_unknown():
# Only an explicit gpu_ids clears the env twin, and llama.cpp reads it before argv, so
# the generated pin is not what the child places against. Reading argv alone emitted
# --cache-ram 0 at an APU the picker had paired with a discrete card.
- assert LlamaCppBackend._cache_tuning_target_unknown(None, None, {"LLAMA_ARG_DEVICE": "ROCm0"})
- assert not LlamaCppBackend._cache_tuning_target_unknown(None, None, {"LLAMA_ARG_DEVICE": " "})
+ assert LlamaCppBackend._cache_tuning_target_unknown(None, False, {"LLAMA_ARG_DEVICE": "ROCm0"})
+ assert not LlamaCppBackend._cache_tuning_target_unknown(None, False, {"LLAMA_ARG_DEVICE": " "})
def test_an_explicit_pin_owns_the_placement_so_the_target_is_known():
# The control: gpu_ids clears both spellings, so neither can name another device.
assert not LlamaCppBackend._cache_tuning_target_unknown(
- ["--device", "ROCm1"], [0], {"LLAMA_ARG_DEVICE": "ROCm0"}
+ ["--device", "ROCm1"], True, {"LLAMA_ARG_DEVICE": "ROCm0"}
)
- assert not LlamaCppBackend._cache_tuning_target_unknown(None, None, {})
+ assert not LlamaCppBackend._cache_tuning_target_unknown(None, False, {})
# ── the arch-crash retry keeps the launch's precedence ──