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 sd.cpp: pass the Windows core count to MiniMax-H3 when sd.cpp would halve it (#17089)
Daniel Han4439f8791898
diff --git a/studio/backend/core/inference/sd_cpp_backend.py b/studio/backend/core/inference/sd_cpp_backend.pyindex 0085d973201..cc00e5d4e9f 100644--- a/studio/backend/core/inference/sd_cpp_backend.py+++ b/studio/backend/core/inference/sd_cpp_backend.py@@ -458,7 +458,7 @@ def _default_threads(smt: bool = True) -> int:windows = None if linux else _windows_cores()if physical:threads = _smt_threads(physical, _allowed_cpus(), _linux_hybrid_cpu(), smt)- elif windows is not None and smt:+ elif windows is not None:cores, hybrid = windowsthreads = _smt_threads(cores, os.cpu_count(), hybrid, smt)else:@@ -493,9 +493,9 @@ def _cpus_restricted(cpu: Optional[int]) -> bool:def _explicit_threads() -> Optional[int]:- """``UNSLOTH_CPU_THREADS``, the macOS fast cores, or (Linux) the thread count above whenever it differs from what- sd.cpp would pick by itself; None keeps sd.cpp's default. sd.cpp builds before the fork's topology fix count half- the logical CPUs and ignore the affinity mask, so a host without SMT or a cpuset needs the count passed."""+ """``UNSLOTH_CPU_THREADS``, the macOS fast cores, or (Linux, Windows) the thread count above whenever it differs+ from what sd.cpp would pick by itself; None keeps sd.cpp's default. sd.cpp halves the logical CPUs on Windows (and+ on Linux before the fork's topology fix) and ignores the affinity mask: hosts without SMT need the count passed."""try:configured = int(os.environ.get("UNSLOTH_CPU_THREADS") or 0)except ValueError:@@ -505,7 +505,7 @@ def _explicit_threads() -> Optional[int]:performance_cores = _apple_performance_cores()if performance_cores:return performance_cores- if sys.platform.startswith("linux"):+ if sys.platform.startswith("linux") or sys.platform == "win32":cpu = os.cpu_count()threads = _default_threads(smt = False)sd_default = _sd_cpp_default_threads(cpu)diff --git a/studio/backend/tests/test_sd_cpp_cpu_defaults.py b/studio/backend/tests/test_sd_cpp_cpu_defaults.pyindex f5ac198d1dd..884e18c0f1c 100644--- a/studio/backend/tests/test_sd_cpp_cpu_defaults.py+++ b/studio/backend/tests/test_sd_cpp_cpu_defaults.py@@ -286,6 +286,9 @@ def test_h3_video_keeps_sd_cpps_default_threads_unless_studio_knows_better(monkemonkeypatch.setattr(bk, "_cgroup_cpu_limit", lambda *a, **k: 6) # a tighter container quotaassert bk._explicit_threads() == 6monkeypatch.setattr(bk.sys, "platform", "win32")+ monkeypatch.setattr(+ bk, "_windows_cores", lambda: None+ ) # unreadable topology: sd.cpp's own defaultassert bk._explicit_threads() is Nonemonkeypatch.setenv("UNSLOTH_CPU_THREADS", "12")assert bk._explicit_threads() == 12@@ -488,6 +491,53 @@ def test_windows_runs_the_logical_cpus_on_a_small_non_hybrid_smt_host(monkeypatcassert bk._default_threads(smt = False) == 2+def _win_topology(+ p_cores,+ e_cores = 0,+ smt = True,+):+ """P cores (EfficiencyClass 1 on a hybrid part) then E cores (class 0, no SMT)."""+ p_class = 1 if e_cores else 0+ buf = b"".join(_win_record(0, p_class, smt = smt) for _ in range(p_cores))+ return buf + b"".join(_win_record(0, 0, smt = False) for _ in range(e_cores)) + _win_record(2)+++ "cpus, topology, expected",+ [+ (+ 16,+ _win_topology(16, smt = False),+ 16,+ ), # no SMT (e.g. a VM): sd.cpp's Windows fallback runs 8+ (24, _win_topology(8, 16, smt = False), 24), # Arrow Lake 8P + 16E, no SMT: sd.cpp runs 12+ (8, _win_topology(4, 4, smt = False), 8), # Lunar Lake 4P + 4E: sd.cpp runs 4+ (32, _win_topology(8, 16), 24), # Raptor Lake 8P (SMT) + 16E: one per core, as on Linux+ (16, _win_topology(8), None), # 8 cores / 16 threads: sd.cpp's half is the core count+ (+ 4,+ _win_topology(2),+ None,+ ), # 2 cores / 4 threads: sd.cpp's all-CPU default measured faster+ (4, _win_topology(4, smt = False), None), # 4 CPUs: sd.cpp already runs all of them+ (16, None, None), # unreadable topology: sd.cpp's own default+ ],+ ids = ["16c", "8p16e", "4p4e", "8p_smt16e", "8c16t", "2c4t", "4c", "unreadable"],+)+def test_h3_video_passes_the_windows_core_count_when_sd_cpp_would_halve_it(+ monkeypatch, cpus, topology, expected+):+ _host(monkeypatch, cpus = cpus, platform = "win32")+ monkeypatch.setattr(bk, "_apple_performance_cores", lambda: None)+ parsed = bk._parse_windows_cores(topology) if topology is not None else None+ monkeypatch.setattr(bk, "_windows_cores", lambda: parsed)+ assert bk._explicit_threads() == expected+ if parsed is not None:+ assert bk._default_threads(smt = False) == parsed[0]+ monkeypatch.setenv("UNSLOTH_CPU_THREADS", "5")+ assert bk._explicit_threads() == 5++def test_windows_cores_is_none_off_windows(monkeypatch):monkeypatch.setattr(bk.sys, "platform", "linux")assert bk._windows_cores() is None