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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio FLUX.3 upsampler: pin the sidecar to the native sd.cpp image card (#14696)
Daniel Hanfacc3a6faf49
diff --git a/studio/backend/core/inference/sd_cpp_backend.py b/studio/backend/core/inference/sd_cpp_backend.pyindex b9c228cb07c..235c087768e 100644--- a/studio/backend/core/inference/sd_cpp_backend.py+++ b/studio/backend/core/inference/sd_cpp_backend.py@@ -2795,6 +2795,18 @@ class _SdState:def spawn_env(self) -> Optional[dict[str, str]]:return dict(self.child_env) or None+ @property+ def placed_ordinal(self) -> Optional[int]:+ """Torch ordinal of ``physical_gpu_id``; without it card-sharing helpers (upsampler) split over all GPUs."""+ if self.physical_gpu_id is None or self.off_torch_device is not None:+ return None+ try:+ from utils.hardware import get_parent_visible_gpu_ids+ visible = [int(i) for i in get_parent_visible_gpu_ids()]+ return visible.index(int(self.physical_gpu_id))+ except Exception: # noqa: BLE001+ return None+def _offload_with_device_pin_impl(offload: tuple[str, ...] | list[str], binary: Optional[str], ordinal: Optional[int]diff --git a/studio/backend/tests/test_sd_cpp_upsampler_placement.py b/studio/backend/tests/test_sd_cpp_upsampler_placement.pynew file mode 100644index 00000000000..1eb541dcf27--- /dev/null+++ b/studio/backend/tests/test_sd_cpp_upsampler_placement.py@@ -0,0 +1,61 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++import types++import pytest++import utils.hardware as hardware+from core.inference import diffusion_engine_router+from core.inference import flux3_prompt_upsampler as pup+from core.inference.sd_cpp_backend import _SdState+++def _native_state(**overrides):+ fields = dict(+ repo_id = "unsloth/FLUX.3-klein-GGUF",+ base_repo = "unsloth/FLUX.3-klein",+ family = types.SimpleNamespace(name = "flux3-klein"),+ device = "cuda",+ files = types.SimpleNamespace(),+ )+ fields.update(overrides)+ return _SdState(**fields)+++def _activate(monkeypatch, state, visible):+ monkeypatch.setattr(+ diffusion_engine_router,+ "get_active_diffusion_engine",+ lambda: types.SimpleNamespace(_state = state),+ )+ monkeypatch.setattr(hardware, "get_parent_visible_gpu_ids", lambda: list(visible))+++ "visible, physical, expected",+ [([0, 1], 1, 1), ([0, 1], 0, 0), ([3, 5], 5, 1), ([3, 5], 4, None)],+)+def test_upsampler_reads_the_native_sd_cpp_card(monkeypatch, visible, physical, expected):+ _activate(monkeypatch, _native_state(physical_gpu_id = physical), visible)+ assert pup._resident_cuda_ordinal() == expected+++def test_unresolved_or_off_torch_native_placement_stays_unplaced(monkeypatch):+ _activate(monkeypatch, _native_state(physical_gpu_id = None), [0, 1])+ assert pup._resident_cuda_ordinal() is None+ _activate(monkeypatch, _native_state(physical_gpu_id = 1, off_torch_device = "Vulkan1"), [0, 1])+ assert pup._resident_cuda_ordinal() is None+++def test_llama_server_is_masked_to_the_native_card(monkeypatch):+ torch = pytest.importorskip("torch")+ _activate(monkeypatch, _native_state(physical_gpu_id = 5), [3, 5])+ monkeypatch.setenv("CUDA_VISIBLE_DEVICES", "3,5")+ monkeypatch.delenv("HIP_VISIBLE_DEVICES", raising = False)+ monkeypatch.delenv("LLAMA_ARG_DEVICE", raising = False)+ monkeypatch.setattr(torch.cuda, "device_count", lambda: 2)+ from core.inference.llama_cpp import LlamaCppBackend++ monkeypatch.setattr(LlamaCppBackend, "_torch_is_rocm", staticmethod(lambda _torch: False))+ assert pup._child_device_mask(pup._resident_cuda_ordinal()) == {"CUDA_VISIBLE_DEVICES": "5"}