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.

Installers: read lspci and the audio.cpp driver version once per run, one WMI query for both AMD scans (#14984)

Daniel Han1939a801b143
diff --git a/install.ps1 b/install.ps1
index 218e1668bd2..55af28469c7 100644
--- a/install.ps1
+++ b/install.ps1
@@ -9571,6 +9571,8 @@ main()
# silent, so a supported Radeon named only by Windows took the CPU path there, and
# the report-only peer scan cannot undo that. Same class and fields as every other
# adapter scan in this file, and identical output under Windows PowerShell 5.1.
+ # Both AMD scans below ask WMI the same question; the peer scan reuses this answer.
+ $amdWmiScanned = $false
if (-not $HasROCm) {
try {
# ConfigManagerErrorCode 0 is "working properly". Filter on it exactly as
@@ -9581,8 +9583,11 @@ main()
# If the filter leaves none, keep the full list: code 45 ("not connected") is
# routine on a muxless laptop with a parked dGPU, and there is no healthy peer
# to prefer. @() wraps the WHOLE if so a one-element branch stays indexable.
- $amdAdapters = @(Get-CimInstance Win32_VideoController -ErrorAction SilentlyContinue |
+ $amdWmiErr = $null
+ $amdAdapters = @(Get-CimInstance Win32_VideoController -ErrorAction SilentlyContinue -ErrorVariable amdWmiErr |
Where-Object { $_.Name -match "AMD|Radeon" })
+ # A scan that reported an error may be partial: the peer scan then asks again, as before.
+ $amdWmiScanned = (-not $amdWmiErr)
$healthyAdapters = @($amdAdapters | Where-Object {
($null -eq $_.ConfigManagerErrorCode) -or ($_.ConfigManagerErrorCode -eq 0) })
$wmiGpu = @(if ($healthyAdapters.Count -gt 0) { $healthyAdapters } else { $amdAdapters })[0]
@@ -9594,8 +9599,9 @@ main()
$wmiAmdNames = @()
if (-not $ROCmGfxArch) {
try {
- $peerAdapters = @(Get-CimInstance Win32_VideoController -ErrorAction SilentlyContinue |
- Where-Object { $_.Name -match "AMD|Radeon" })
+ $peerAdapters = @(if ($amdWmiScanned) { $amdAdapters } else {
+ Get-CimInstance Win32_VideoController -ErrorAction SilentlyContinue |
+ Where-Object { $_.Name -match "AMD|Radeon" } })
$healthyPeers = @($peerAdapters | Where-Object {
($null -eq $_.ConfigManagerErrorCode) -or ($_.ConfigManagerErrorCode -eq 0) })
$usePeers = @(if ($healthyPeers.Count -gt 0) { $healthyPeers } else { $peerAdapters })
diff --git a/install.sh b/install.sh
index 4c39f04a86a..3ceb5bb0221 100755
--- a/install.sh
+++ b/install.sh
@@ -1430,6 +1430,7 @@ _UIP_STAGE=""
_UIP_STAGE2=""
_ROCM_TAG_MEMO_DIR=""
_ROCM_TAG_MEMO=""
+_LSPCI_MEMO=""
_UV_PROBE_TARGET=""
_UV_PROBE_PID=""
trap _on_install_exit EXIT
@@ -5377,7 +5378,16 @@ _infer_unsupported_amd_gfx_arch_from_gpu_name() {
# Linux counterpart: first AMD display-class lspci line naming a generation ROCm does not cover. Messaging only, never fed into index selection.
_infer_linux_unsupported_amd_gfx_arch() {
command -v lspci >/dev/null 2>&1 || return 1
- _unsup_disp=$(lspci -nn 2>/dev/null | grep -E 'VGA compatible controller|3D controller|Display controller' | grep -E 'AMD|ATI' || true)
+ if [ -n "${_LSPCI_MEMO:-}" ] && [ -f "$_LSPCI_MEMO" ]; then
+ _unsup_disp=$(cat "$_LSPCI_MEMO")
+ else
+ _unsup_raw=$(lspci -nn 2>/dev/null) && _unsup_ok=1 || _unsup_ok=""
+ _unsup_disp=$(printf '%s\n' "$_unsup_raw" | grep -E 'VGA compatible controller|3D controller|Display controller' | grep -E 'AMD|ATI' || true)
+ # Only a successful query is kept, written whole (temp file + rename) so a failed write leaves no memo.
+ if [ -n "$_unsup_ok" ] && [ -n "${_LSPCI_MEMO:-}" ]; then
+ { printf '%s\n' "$_unsup_disp" > "$_LSPCI_MEMO.tmp" && mv -f "$_LSPCI_MEMO.tmp" "$_LSPCI_MEMO"; } 2>/dev/null || rm -f "$_LSPCI_MEMO.tmp" 2>/dev/null || true
+ fi
+ fi
while IFS= read -r _unsup_ln; do
[ -n "$_unsup_ln" ] || continue
if _unsup_gfx=$(_infer_unsupported_amd_gfx_arch_from_gpu_name "$_unsup_ln"); then
@@ -5430,7 +5440,17 @@ _infer_linux_amd_gfx_arch() {
fi
if command -v lspci >/dev/null 2>&1; then
# A non-AMD controller can enumerate first (Intel/ASPEED before an AMD dGPU), so scan every display-class line and take the first AMD one that maps. The vendor guard is case-SENSITIVE (a -i "ATI" would match "CorporATIon" on every Intel/NVIDIA line); whole-line matching also survives the 0000: PCI domain prefix.
- _amd_disp=$(lspci -nn 2>/dev/null | grep -E 'VGA compatible controller|3D controller|Display controller' | grep -E 'AMD|ATI' || true)
+ # Read once per install: the callers run in command substitutions, so the answer is kept in a file (_LSPCI_MEMO).
+ if [ -n "${_LSPCI_MEMO:-}" ] && [ -f "$_LSPCI_MEMO" ]; then
+ _amd_disp=$(cat "$_LSPCI_MEMO")
+ else
+ _amd_raw=$(lspci -nn 2>/dev/null) && _amd_ok=1 || _amd_ok=""
+ _amd_disp=$(printf '%s\n' "$_amd_raw" | grep -E 'VGA compatible controller|3D controller|Display controller' | grep -E 'AMD|ATI' || true)
+ # Only a successful query is kept, written whole (temp file + rename) so a failed write leaves no memo.
+ if [ -n "$_amd_ok" ] && [ -n "${_LSPCI_MEMO:-}" ]; then
+ { printf '%s\n' "$_amd_disp" > "$_LSPCI_MEMO.tmp" && mv -f "$_LSPCI_MEMO.tmp" "$_LSPCI_MEMO"; } 2>/dev/null || rm -f "$_LSPCI_MEMO.tmp" 2>/dev/null || true
+ fi
+ fi
while IFS= read -r _ln; do
[ -n "$_ln" ] || continue
# A Krackan Point 2 line is only the fallback: a covered adapter later still answers.
@@ -6866,6 +6886,9 @@ fi
# Created here, not inside get_torch_index_url: that runs in a command substitution, so only a file outlives it. mktemp -d, never a $$-derived name: a predictable path under a world-writable /tmp can be pre-created as a symlink, feeding the probe a chosen version.
_ROCM_TAG_MEMO_DIR=$(mktemp -d "${TMPDIR:-/tmp}/unsloth-rocm.XXXXXX" 2>/dev/null) \
&& _ROCM_TAG_MEMO="$_ROCM_TAG_MEMO_DIR/tag" || _ROCM_TAG_MEMO=""
+# The AMD display-class lspci lines, shared by _infer_linux_amd_gfx_arch and _infer_linux_unsupported_amd_gfx_arch.
+_LSPCI_MEMO=""
+[ -z "$_ROCM_TAG_MEMO_DIR" ] || _LSPCI_MEMO="$_ROCM_TAG_MEMO_DIR/lspci"
# UNSLOTH_TORCH_EXTRA selects a build on indexes that discriminate by package extra
# (TheRock's whl-multi-arch). Gated on a pinned index: no index this script picks by itself
# publishes extras, so an unpinned extra could only break a working resolve.
diff --git a/studio/install_audio_cpp_prebuilt.py b/studio/install_audio_cpp_prebuilt.py
index eaf96b26a9d..def52408ac9 100644
--- a/studio/install_audio_cpp_prebuilt.py
+++ b/studio/install_audio_cpp_prebuilt.py
@@ -50,6 +50,7 @@ import re
import shutil
import subprocess
import sys
+import time
import tarfile
import urllib.error
import urllib.request
@@ -255,18 +256,44 @@ def default_install_dir() -> Path:
return legacy if root == (Path.home() / ".unsloth" / "studio").resolve() else root / "audio.cpp"
+# detect_accelerator and the release pick both ask within one install, so a version nvidia-smi reported
+# is kept for a few minutes: a later install in the same Studio process asks again. Keyed on its mtime
+# (a driver update replaces it) and the runner, so a stubbed subprocess.run never reads another stub's
+# answer. No answer is not kept: a driver that recovers is seen next time.
+_DRIVER_CUDA_MEMO: Optional[tuple] = None
+_DRIVER_CUDA_MEMO_TTL_S = 300.0
+
+
def nvidia_driver_cuda_version() -> Optional[tuple[int, int]]:
"""The CUDA version the installed NVIDIA driver supports, from nvidia-smi, or None."""
+ global _DRIVER_CUDA_MEMO
exe = shutil.which("nvidia-smi")
if not exe:
return None
try:
- out = subprocess.run([exe], capture_output = True, text = True, timeout = 15).stdout
+ stamp = os.stat(exe).st_mtime_ns
+ except OSError:
+ stamp = None
+ runner = subprocess.run
+ memo = _DRIVER_CUDA_MEMO
+ if (
+ memo is not None
+ and memo[:2] == (exe, stamp)
+ and memo[2] is runner
+ and time.monotonic() - memo[4] < _DRIVER_CUDA_MEMO_TTL_S
+ ):
+ return memo[3]
+ try:
+ out = runner([exe], capture_output = True, text = True, timeout = 15).stdout
except (OSError, subprocess.SubprocessError):
return None
# Newer drivers print "CUDA UMD Version: X.Y" in place of "CUDA Version: X.Y" (same rule as the llama installer).
match = re.search(r"CUDA(?: UMD)? Version:\s*(\d+)\.(\d+)", out or "")
- return (int(match.group(1)), int(match.group(2))) if match else None
+ if not match:
+ return None
+ version = (int(match.group(1)), int(match.group(2)))
+ _DRIVER_CUDA_MEMO = (exe, stamp, runner, version, time.monotonic())
+ return version
def _nvidia_has_prebuilt_arch() -> Optional[bool]:
diff --git a/studio/install_python_stack.py b/studio/install_python_stack.py
index e24f822682f..4ea128d6ca7 100644
--- a/studio/install_python_stack.py
+++ b/studio/install_python_stack.py
@@ -2454,18 +2454,22 @@ def _linux_amd_gfx_from_cpuinfo() -> "str | None":
return None
-def _linux_amd_gfx_from_lspci(beside_krackan2: bool = False) -> "str | None":
- """First AMD display-class lspci line mapping to a known gfx arch. A non-AMD
- controller can enumerate first (Intel/ASPEED before an AMD dGPU), so scan
- them all. The vendor guard is case-SENSITIVE: a -i "ATI" would match
- "CorporATIon" on every Intel/NVIDIA line. Whole-line matching also survives
- the 0000: PCI domain prefix. beside_krackan2 skips that APU's own iGPU line, so only a
- discrete peer answers."""
+# One `lspci -nn` answer per run: _infer_linux_amd_gfx_arch has several callers. Keyed on the
+# lspci path and the runner too, so a stubbed subprocess.run never reads another stub's answer.
+_LSPCI_MEMO: "tuple | None" = None
+
+
+def _lspci_nn_stdout() -> "str | None":
+ """`lspci -nn` output, or None when lspci is missing or fails."""
+ global _LSPCI_MEMO
lspci = shutil.which("lspci")
if not lspci:
return None
+ runner = subprocess.run
+ if _LSPCI_MEMO is not None and _LSPCI_MEMO[0] == lspci and _LSPCI_MEMO[1] is runner:
+ return _LSPCI_MEMO[2]
try:
- result = subprocess.run(
+ result = runner(
[lspci, "-nn"],
stdout = subprocess.PIPE,
stderr = subprocess.DEVNULL,
@@ -2477,11 +2481,25 @@ def _linux_amd_gfx_from_lspci(beside_krackan2: bool = False) -> "str | None":
except Exception:
return None
if result.returncode != 0:
+ return None # a failed query is not kept: the next caller asks again
+ _LSPCI_MEMO = (lspci, runner, result.stdout)
+ return result.stdout
+
+
+def _linux_amd_gfx_from_lspci(beside_krackan2: bool = False) -> "str | None":
+ """First AMD display-class lspci line mapping to a known gfx arch. A non-AMD
+ controller can enumerate first (Intel/ASPEED before an AMD dGPU), so scan
+ them all. The vendor guard is case-SENSITIVE: a -i "ATI" would match
+ "CorporATIon" on every Intel/NVIDIA line. Whole-line matching also survives
+ the 0000: PCI domain prefix. beside_krackan2 skips that APU's own iGPU line, so only a
+ discrete peer answers."""
+ stdout = _lspci_nn_stdout()
+ if stdout is None:
return None
# A Krackan Point 2 line (gfx1153, no Linux torch wheel) is only the fallback: a covered
# adapter later in the list still answers, as for the CPU-name case.
krackan2 = beside_krackan2
- for line in result.stdout.splitlines():
+ for line in stdout.splitlines():
if not re.search(r"VGA compatible controller|3D controller|Display controller", line, re.I):
continue
if not re.search(r"AMD|ATI", line):
diff --git a/tests/sh/test_rocm_no_version_arch_route_e2e.sh b/tests/sh/test_rocm_no_version_arch_route_e2e.sh
index 920cd2ada25..37199cd4f01 100755
--- a/tests/sh/test_rocm_no_version_arch_route_e2e.sh
+++ b/tests/sh/test_rocm_no_version_arch_route_e2e.sh
@@ -35,7 +35,7 @@ _TOOLS="$_ROOT/tools"
mkdir -p "$_MOCK" "$_TOOLS"
for _cmd in uname grep sed awk head tail tr ls sort cat cut wc mktemp rm mkdir chmod \
dirname basename expr readlink id date find stat env timeout sleep sh bash \
- printf echo test true false touch cp ln; do
+ printf echo test true false touch cp ln mv; do
_real=$(command -v "$_cmd" 2>/dev/null || true)
[ -n "$_real" ] && ln -sf "$_real" "$_TOOLS/$_cmd"
done
@@ -525,6 +525,37 @@ fedora_no_version_host gfx1201
assert_eq "an override that corroborated nothing is left alone" \
"11.0.0" "$(HSA_OVERRIDE_GFX_VERSION=11.0.0 run_hsa)"
+# lspci is read once per install: every caller runs in a command substitution, so the
+# answer is shared through a file, not a variable.
+mock_lspci_counting() { # $1 = the display-controller name lspci reports
+ mock_lspci "$1"
+ : > "$_MOCK/.lspci.calls"
+ cat > "$_MOCK/lspci" <<'MOCK'
+#!/bin/sh
+echo x >> "$(dirname "$0")/.lspci.calls"
+cat "$(dirname "$0")/.lspci.out"
+MOCK
+ chmod +x "$_MOCK/lspci"
+}
+lspci_calls() { wc -l < "$_MOCK/.lspci.calls" | tr -d ' '; }
+for _probe_host in "gfx1201 gfx1036" "gfx1200 gfx1201"; do
+ # shellcheck disable=SC2086
+ fedora_no_version_host $_probe_host
+ mock_lspci_counting "Navi 48 [Radeon RX 9070 XT]"
+ _probe_index=$(run_index)
+ _probe_calls=$(lspci_calls)
+ assert_eq "lspci runs at most once for $_probe_host (index $_probe_index)" \
+ "yes" "$([ "$_probe_calls" -le 1 ] && echo yes || echo "no ($_probe_calls)")"
+done
+# A failing lspci (output printed, non-zero exit) is used but not kept, so each reader asks again.
+fedora_no_version_host gfx1200 gfx1201
+mock_lspci_counting "Navi 48 [Radeon RX 9070 XT]"
+printf '#!/bin/sh\necho x >> "$(dirname "$0")/.lspci.calls"\ncat "$(dirname "$0")/.lspci.out"\nexit 1\n' > "$_MOCK/lspci"
+_fail_index=$(run_index)
+_fail_calls=$(lspci_calls)
+assert_eq "a failing lspci is asked again (index $_fail_index)" \
+ "yes" "$([ "$_fail_calls" -ge 2 ] && echo yes || echo "no ($_fail_calls)")"
+
echo ""
echo " passed: $PASS, failed: $FAIL"
[ "$FAIL" -eq 0 ]
diff --git a/tests/studio/install/test_install_audio_cpp_prebuilt_logic.py b/tests/studio/install/test_install_audio_cpp_prebuilt_logic.py
index 3b2a330c1aa..c931bc4d07e 100644
--- a/tests/studio/install/test_install_audio_cpp_prebuilt_logic.py
+++ b/tests/studio/install/test_install_audio_cpp_prebuilt_logic.py
@@ -5,6 +5,7 @@
import importlib.util
import json
+import os
import sys
import zipfile
from pathlib import Path
@@ -127,6 +128,43 @@ def test_driver_cuda_version_reads_both_spellings(monkeypatch, smi, expected):
assert M.nvidia_driver_cuda_version() == expected
+def test_driver_cuda_version_is_read_once_per_binary(monkeypatch, tmp_path):
+ # detect_accelerator and the release pick both ask; nvidia-smi runs once.
+ exe = tmp_path / "nvidia-smi"
+ exe.write_text("")
+ calls = []
+
+ def run(*a, **k):
+ calls.append(a)
+ return type("R", (), {"stdout": "CUDA Version: 12.6"})()
+
+ monkeypatch.setattr(M.shutil, "which", lambda name: str(exe))
+ monkeypatch.setattr(M.subprocess, "run", run)
+ assert M.nvidia_driver_cuda_version() == (12, 6)
+ assert M.nvidia_driver_cuda_version() == (12, 6)
+ assert len(calls) == 1
+ # A driver update replaces the binary: asked again.
+ os.utime(exe, ns = (1, 1))
+ assert M.nvidia_driver_cuda_version() == (12, 6)
+ assert len(calls) == 2
+
+
+def test_driver_cuda_version_keeps_no_failed_answer(monkeypatch, tmp_path):
+ # A driver that did not answer can recover without a restart (in-app update): ask again.
+ exe = tmp_path / "nvidia-smi"
+ exe.write_text("")
+ outputs = [
+ "NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver",
+ "CUDA Version: 12.8",
+ ]
+ monkeypatch.setattr(M.shutil, "which", lambda name: str(exe))
+ monkeypatch.setattr(
+ M.subprocess, "run", lambda *a, **k: type("R", (), {"stdout": outputs.pop(0)})()
+ )
+ assert M.nvidia_driver_cuda_version() is None
+ assert M.nvidia_driver_cuda_version() == (12, 8)
+
+
def _fake_nvidia_smi(
monkeypatch,
caps,
@@ -2370,3 +2408,26 @@ def test_the_sweep_skips_a_retired_tree_it_cannot_read(monkeypatch, tmp_path):
assert server.is_file() and stuck.is_dir()
finally:
stuck.chmod(0o755)
+
+
+def test_driver_cuda_version_is_asked_again_after_the_memo_window(monkeypatch, tmp_path):
+ # A later install in the same Studio process reads the driver again.
+ exe = tmp_path / "nvidia-smi"
+ exe.write_text("")
+ calls = []
+ now = [1000.0]
+
+ def run(*a, **k):
+ calls.append(a)
+ return type("R", (), {"stdout": "CUDA Version: 12.6"})()
+
+ monkeypatch.setattr(M.shutil, "which", lambda name: str(exe))
+ monkeypatch.setattr(M.subprocess, "run", run)
+ monkeypatch.setattr(M.time, "monotonic", lambda: now[0])
+ assert M.nvidia_driver_cuda_version() == (12, 6)
+ now[0] += M._DRIVER_CUDA_MEMO_TTL_S - 1
+ assert M.nvidia_driver_cuda_version() == (12, 6)
+ assert len(calls) == 1
+ now[0] += 2
+ assert M.nvidia_driver_cuda_version() == (12, 6)
+ assert len(calls) == 2
diff --git a/tests/studio/install/test_linux_amd_strix_dgpu_gfx1153.py b/tests/studio/install/test_linux_amd_strix_dgpu_gfx1153.py
index dbff1f9da36..524a8d3d91a 100644
--- a/tests/studio/install/test_linux_amd_strix_dgpu_gfx1153.py
+++ b/tests/studio/install/test_linux_amd_strix_dgpu_gfx1153.py
@@ -236,6 +236,50 @@ def test_python_lspci_names_gfx1153_before_gfx1152(monkeypatch):
assert stack_mod._linux_amd_gfx_from_lspci() == "gfx1153"
+def test_python_lspci_keeps_no_failed_query(monkeypatch):
+ # A failed lspci is not an answer: the next caller asks again.
+ line = "c4:00.0 VGA compatible controller [0300]: " + _KRACKAN2_TEXT[1]
+ results = [
+ subprocess.CompletedProcess([], 1, "", ""),
+ subprocess.CompletedProcess([], 0, line, ""),
+ ]
+ calls = []
+
+ def run(*a, **k):
+ calls.append(a)
+ return results.pop(0)
+
+ monkeypatch.setattr(stack_mod, "_LSPCI_MEMO", None)
+ monkeypatch.setattr(stack_mod.shutil, "which", lambda _n: "/usr/bin/lspci")
+ monkeypatch.setattr(stack_mod.subprocess, "run", run)
+ assert stack_mod._linux_amd_gfx_from_lspci() is None
+ assert stack_mod._linux_amd_gfx_from_lspci() == "gfx1153"
+ assert stack_mod._linux_amd_gfx_from_lspci() == "gfx1153"
+ assert len(calls) == 2
+
+
+def test_python_lspci_runs_once_per_run(monkeypatch):
+ # _infer_linux_amd_gfx_arch has several callers in one install; lspci answers once.
+ line = "c4:00.0 VGA compatible controller [0300]: " + _KRACKAN2_TEXT[1]
+ calls = []
+
+ def run(*a, **k):
+ calls.append(a)
+ return subprocess.CompletedProcess(a, 0, line, "")
+
+ monkeypatch.setattr(stack_mod.shutil, "which", lambda _n: "/usr/bin/lspci")
+ monkeypatch.setattr(stack_mod.subprocess, "run", run)
+ assert stack_mod._linux_amd_gfx_from_lspci() == "gfx1153"
+ assert stack_mod._linux_amd_gfx_from_lspci(beside_krackan2 = True) is None
+ assert stack_mod._linux_amd_gfx_from_lspci() == "gfx1153"
+ assert len(calls) == 1
+ # Another runner (a different stub) is asked afresh, never handed this answer.
+ monkeypatch.setattr(
+ stack_mod.subprocess, "run", lambda *a, **k: subprocess.CompletedProcess(a, 1, "", "")
+ )
+ assert stack_mod._linux_amd_gfx_from_lspci() is None
+
+
def _sh_infer(
tmp_path,
cpuinfo,
diff --git a/tests/test_windows_amd_gpu_scan_fallback.py b/tests/test_windows_amd_gpu_scan_fallback.py
index 7321beb449e..8dd66cf50cc 100644
--- a/tests/test_windows_amd_gpu_scan_fallback.py
+++ b/tests/test_windows_amd_gpu_scan_fallback.py
@@ -404,7 +404,11 @@ def _installer_scan_block() -> str:
return src[start:end]
-def _run_installer_scan(tmp_path: Path, adapters: list[tuple[str, int]]) -> dict:
+def _run_installer_scan(
+ tmp_path: Path,
+ adapters: list[tuple[str, int]],
+ cim_error: bool = False,
+) -> dict:
items = ", ".join(
f"[pscustomobject]@{{ Name = '{name}'; ConfigManagerErrorCode = {code} }}"
for name, code in adapters
@@ -415,14 +419,21 @@ def _run_installer_scan(tmp_path: Path, adapters: list[tuple[str, int]]) -> dict
[
"$ErrorActionPreference = 'Stop'",
# Both names: routing scan uses WMI, the report-only peer scan uses CIM.
- f"function Get-CimInstance {{ param([Parameter(ValueFromRemainingArguments = $true)]$Rest) @({items}) }}",
+ "$script:cimCalls = 0",
+ (
+ # A partial answer: CIM reports a non-terminating error beside the rows it read.
+ f"function Get-CimInstance {{ [CmdletBinding()] param([Parameter(ValueFromRemainingArguments = $true)]$Rest) $script:cimCalls++; Write-Error 'partial'; @({items}) }}"
+ if cim_error
+ else f"function Get-CimInstance {{ param([Parameter(ValueFromRemainingArguments = $true)]$Rest) $script:cimCalls++; @({items}) }}"
+ ),
f"function Get-WmiObject {{ param([Parameter(ValueFromRemainingArguments = $true)]$Rest) @({items}) }}",
"function substep { param($a, $b) }",
"$HasROCm = $false",
"$ROCmGpuLabel = $null",
"$ROCmGfxArch = $null",
_installer_scan_block(),
- "@{ label = $ROCmGpuLabel; arch = $ROCmGfxArch } | ConvertTo-Json -Compress",
+ "@{ label = $ROCmGpuLabel; arch = $ROCmGfxArch; cim = $script:cimCalls; peers = @($wmiAmdNames) }"
+ " | ConvertTo-Json -Compress",
]
),
encoding = "utf-8",
@@ -448,6 +459,16 @@ def test_the_installer_skips_a_disabled_adapter(tmp_path):
assert out["arch"] is None, "the active card is unsupported, so this host belongs on CPU"
+@requires_pwsh
+def test_the_peer_scan_reuses_the_routing_scan(tmp_path):
+ """No arch is inferred for an RX 580, so the report-only peer scan runs too. It asks WMI the
+ same question as the routing scan, so one query answers both, with the same peer list."""
+ out = _run_installer_scan(tmp_path, [("AMD Radeon RX 9070 XT", 22), ("AMD Radeon RX 580", 0)])
+ assert out["arch"] is None
+ assert out["peers"] == ["AMD Radeon RX 580"]
+ assert out["cim"] == 1
+
+
@requires_pwsh
def test_the_installer_keeps_a_parked_adapter_when_it_is_the_only_one(tmp_path):
"""Same fallback setup makes: code 45 is routine on a muxless laptop, and with no healthy
@@ -935,3 +956,13 @@ def test_these_assertions_fail_without_the_array_wraps(tmp_path):
assert not before["wmi_array"], "the unwrapped scan should collapse to a scalar"
assert before["label"] is None, "the unwrapped scan should report no GPU under 5.1 semantics"
assert pinned["arch"] is None, "the unwrapped name list should infer nothing when pinned"
+
+
+@requires_pwsh
+def test_the_peer_scan_asks_again_after_a_routing_scan_error(tmp_path):
+ """A routing scan that reported an error may be partial, so the peer scan queries WMI itself, as before."""
+ out = _run_installer_scan(
+ tmp_path, [("AMD Radeon RX 9070 XT", 22), ("AMD Radeon RX 580", 0)], cim_error = True
+ )
+ assert out["arch"] is None
+ assert out["cim"] == 2