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.

FLUX.3 upsampler: name older NVIDIA Vulkan devices as NVIDIA, probe an empty answer once per window (#14604)

Daniel Hand4c220b3a465
diff --git a/studio/backend/core/inference/flux3_prompt_upsampler.py b/studio/backend/core/inference/flux3_prompt_upsampler.py
index 2fd235042a8..e659f39c4fb 100644
--- a/studio/backend/core/inference/flux3_prompt_upsampler.py
+++ b/studio/backend/core/inference/flux3_prompt_upsampler.py
@@ -897,27 +897,34 @@ def _child_device_mask(ordinal: Optional[int]) -> dict:
_VULKAN_ROWS_TTL_S = 120.0
_vulkan_rows_memo: dict = {}
+# One probe at a time: concurrent prefetches read the answer the first one cached.
+_vulkan_rows_lock = threading.Lock()
-def _vulkan_rows(binary: str, retry_empty: bool = False) -> list:
- """Vulkan probe rows, cached briefly; ``retry_empty`` re-probes a cached (maybe transient) empty answer."""
+def _vulkan_rows(
+ binary: str,
+ retry_empty: bool = False,
+ throttle_retry: bool = False,
+) -> list:
+ """Vulkan probe rows, cached briefly; ``retry_empty`` re-probes a cached (maybe transient) empty answer. With
+ ``throttle_retry`` (a speculative prefetch) an empty answer that already was a retry stands until the window ends."""
from core.inference.llama_cpp import LlamaCppBackend
try:
key = (binary, os.path.getmtime(binary))
except OSError:
key = (binary, None)
- hit = _vulkan_rows_memo.get(key)
- if (
- hit is not None
- and time.monotonic() - hit[1] < _VULKAN_ROWS_TTL_S
- and (hit[0] or not retry_empty)
- ):
- return hit[0]
- rows = list(LlamaCppBackend._run_vulkan_probe(binary) or [])
- _vulkan_rows_memo.clear()
- _vulkan_rows_memo[key] = (rows, time.monotonic())
- return rows
+ with _vulkan_rows_lock:
+ hit = _vulkan_rows_memo.get(key)
+ live = hit is not None and time.monotonic() - hit[1] < _VULKAN_ROWS_TTL_S
+ # Only a speculative prefetch is throttled: a real launch always asks again.
+ if live and (hit[0] or not retry_empty or (throttle_retry and len(hit) > 2 and hit[2])):
+ return hit[0]
+ rows = list(LlamaCppBackend._run_vulkan_probe(binary) or [])
+ _vulkan_rows_memo.clear()
+ # (rows, probed at, this probe retried a live empty answer)
+ _vulkan_rows_memo[key] = (rows, time.monotonic(), live)
+ return rows
def _user_device_pick(binary: Optional[str] = None) -> bool:
@@ -966,7 +973,9 @@ def _prefetch_vulkan_rows(binary: str, cancel: Optional[threading.Event] = None)
def _work() -> None:
try:
# An empty answer (cached or fresh) is retried once, as the launch it stands in for did.
- rows = _vulkan_rows(binary, retry_empty = True) or _vulkan_rows(binary, retry_empty = True)
+ rows = _vulkan_rows(binary, retry_empty = True, throttle_retry = True) or _vulkan_rows(
+ binary, retry_empty = True, throttle_retry = True
+ )
# One row on one torch card launches unpinned, so it needs no card lookup.
if rows and (len(rows) > 1 or torch.cuda.device_count() > 1):
ordinal = _resident_cuda_ordinal()
@@ -1037,14 +1046,29 @@ def _vulkan_card_name(ordinal: int, torch) -> tuple:
return name, names[:ordinal].count(name)
+# Vendor by positive evidence: older NVIDIA drivers name Vulkan devices "Tesla T4" or "GeForce GTX 1080 Ti".
+_VULKAN_VENDOR_RES = (
+ ("nvidia", re.compile(r"\b(?:nvidia|geforce|quadro|tesla|titan|rtx)\b")),
+ ("amd", re.compile(r"\b(?:amd|radeon|radv|instinct|firepro)\b")),
+ ("intel", re.compile(r"\b(?:intel|arc|iris|uhd)\b")),
+ ("software", re.compile(r"\b(?:llvmpipe|lavapipe|swiftshader)\b")),
+)
+
+
+def _vulkan_row_vendor(row_name: str) -> Optional[str]:
+ """``nvidia`` / ``amd`` / ``intel`` / ``software`` when the Vulkan row names one, else None (unknown)."""
+ name = str(row_name or "").lower()
+ return next((vendor for vendor, pattern in _VULKAN_VENDOR_RES if pattern.search(name)), None)
+
+
def _vulkan_row_is_another_vendor(row_name: str, torch) -> bool:
- """A CUDA torch's card is NVIDIA's and a ROCm torch's AMD's: a Vulkan row naming neither is another card."""
+ """A CUDA torch's card is NVIDIA's and a ROCm torch's AMD's: a Vulkan row is another card only when it names
+ another vendor. A row naming no vendor at all is not evidence either way."""
from core.inference.llama_cpp import LlamaCppBackend
- name = str(row_name or "").lower()
- if LlamaCppBackend._torch_is_rocm(torch):
- return not any(tag in name for tag in ("amd", "radeon", "instinct"))
- return "nvidia" not in name
+ vendor = _vulkan_row_vendor(row_name)
+ expected = "amd" if LlamaCppBackend._torch_is_rocm(torch) else "nvidia"
+ return vendor is not None and vendor != expected
def _vulkan_device_args(
diff --git a/studio/backend/tests/test_flux3_prompt_upsampler.py b/studio/backend/tests/test_flux3_prompt_upsampler.py
index cd3e45ad77e..b8ec7eab9a8 100644
--- a/studio/backend/tests/test_flux3_prompt_upsampler.py
+++ b/studio/backend/tests/test_flux3_prompt_upsampler.py
@@ -2135,7 +2135,7 @@ def test_the_vulkan_probe_runs_before_the_render_slot(warmable, monkeypatch):
llama_cpp.LlamaCppBackend, "_is_vulkan_backend", staticmethod(lambda b = None: True)
)
monkeypatch.setattr(
- pup, "_vulkan_rows", lambda b, retry_empty = False: order.append("probe") or []
+ pup, "_vulkan_rows", lambda b, retry_empty = False, **_kw: order.append("probe") or []
)
sidecar.warm(binary = "b", model = model, mmproj = None)
# An empty answer is retried once, still before the slot.
@@ -2657,6 +2657,86 @@ def test_a_lone_vulkan_device_of_another_vendor_declines_the_warm_start(
sidecar._cancel_idle_locked()
+ "name", ["Tesla T4", "Quadro RTX 8000", "GeForce GTX 1080 Ti", "NVIDIA GeForce RTX 4090"]
+)
+def test_an_nvidia_vulkan_row_without_the_vendor_name_warm_starts(
+ spawn_argv, warmable, monkeypatch, name
+):
+ # Older NVIDIA drivers name the Vulkan device "Tesla T4": that is the image model's card, not another vendor's.
+ import torch
+
+ state, _run = spawn_argv
+ sidecar, _launched, _memory, model, _mmproj = warmable
+ monkeypatch.setattr(torch.cuda, "device_count", lambda: 1)
+ monkeypatch.setattr(torch.version, "hip", None, raising = False)
+ state["names"] = [name]
+ state["ordinal"] = 0
+ state["rows"] = [{"index": 0, "name": name}]
+ assert sidecar.warm(binary = "b", model = model, mmproj = None) == "started"
+ sidecar._cancel_idle_locked()
+
+
+ "rocm, card, row, other",
+ [
+ (False, "Tesla T4", "AMD Radeon Graphics (RADV RAPHAEL)", True),
+ (False, "NVIDIA GeForce RTX 4090", "Intel(R) Arc(tm) A770 Graphics (DG2)", True),
+ (False, "NVIDIA GeForce RTX 4090", "llvmpipe (LLVM 17.0.6, 256 bits)", True),
+ (True, "AMD Radeon RX 7900 XTX", "NVIDIA GeForce RTX 3060", True),
+ (True, "AMD Radeon RX 7900 XTX", "AMD Radeon RX 7900 XTX (RADV NAVI31)", False),
+ (False, "Tesla T4", "Tesla T4", False),
+ # A generic card name never outweighs a row that names another vendor.
+ (False, "NVIDIA Graphics Device", "Intel(R) Graphics", True),
+ (False, "GeForce GTX 1080 Ti", "NVIDIA GeForce GTX 1080 Ti", False),
+ (False, "NVIDIA A100-SXM4-40GB", "Virtual GPU 0", False),
+ (True, "AMD Radeon RX 7900 XTX", "Virtual GPU 0", False),
+ ],
+)
+def test_another_vendor_needs_positive_evidence(monkeypatch, rocm, card, row, other):
+ # Only a row naming a different vendor is another card; an unknown name is not evidence either way.
+ from core.inference import llama_cpp
+ monkeypatch.setattr(
+ llama_cpp.LlamaCppBackend, "_torch_is_rocm", staticmethod(lambda t = None: rocm)
+ )
+ assert pup._vulkan_row_is_another_vendor(row, object()) is other
+
+
+def test_repeated_prefetches_retry_an_empty_probe_once_per_window(monkeypatch):
+ # The retry stands for the window: two prefetches cost one probe and one retry, not two each.
+ calls, _looked_up = _prefetch_host(monkeypatch, 2, [])
+ monkeypatch.setattr(pup, "_vulkan_rows_memo", {})
+ pup._prefetch_vulkan_rows("b")
+ pup._prefetch_vulkan_rows("b")
+ assert calls == ["b", "b"]
+ # A new window probes (and may retry) again.
+ monkeypatch.setattr(pup, "_VULKAN_ROWS_TTL_S", 0.0)
+ pup._prefetch_vulkan_rows("b")
+ assert len(calls) == 4
+
+
+def test_a_real_launch_reprobes_after_throttled_prefetches(monkeypatch):
+ # Prefetches stop retrying for the window, a launch does not: a device that came up since is found.
+ calls, _looked_up = _prefetch_host(monkeypatch, 2, [])
+ monkeypatch.setattr(pup, "_vulkan_rows_memo", {})
+ pup._prefetch_vulkan_rows("b")
+ pup._prefetch_vulkan_rows("b")
+ assert calls == ["b", "b"]
+ pup._vulkan_rows("b", retry_empty = True)
+ assert len(calls) == 3
+
+
+def test_concurrent_prefetches_share_one_probe(monkeypatch):
+ calls, _looked_up = _prefetch_host(monkeypatch, 2, [])
+ monkeypatch.setattr(pup, "_vulkan_rows_memo", {})
+ threads = [threading.Thread(target = pup._prefetch_vulkan_rows, args = ("b",)) for _ in range(4)]
+ for thread in threads:
+ thread.start()
+ for thread in threads:
+ thread.join(10)
+ assert calls == ["b", "b"]
+
+
def test_maintenance_never_joins_an_unstarted_probe(monkeypatch):
# A worker is registered only once started, so a maintenance pass cannot hit "cannot join thread".
import inspect