From 69b437fa21237bedb1393e8526c8ab31958c4965 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 4 Jul 2026 07:31:30 +0000 Subject: [PATCH 1/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- studio/backend/core/inference/diffusion_speed.py | 6 +++++- studio/backend/tests/test_diffusion_speed.py | 11 +++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/studio/backend/core/inference/diffusion_speed.py b/studio/backend/core/inference/diffusion_speed.py index dd2f2e664d..cb9101d03d 100644 --- a/studio/backend/core/inference/diffusion_speed.py +++ b/studio/backend/core/inference/diffusion_speed.py @@ -357,7 +357,11 @@ _FP16_ACCUM_DENY: frozenset[str] = frozenset() def _enable_fp16_accumulation( - family: Any, logger: Any, *, dtype: Any = None, speed_mode: Optional[str] = None + family: Any, + logger: Any, + *, + dtype: Any = None, + speed_mode: Optional[str] = None, ) -> bool: """Turn on fp16-accumulated fp16 GEMMs for consumer GPUs, where they run ~2x the fp32-accumulate rate (datacenter HBM parts are not throughput-nerfed, so they keep diff --git a/studio/backend/tests/test_diffusion_speed.py b/studio/backend/tests/test_diffusion_speed.py index 9dc50f4e28..5b645022e1 100644 --- a/studio/backend/tests/test_diffusion_speed.py +++ b/studio/backend/tests/test_diffusion_speed.py @@ -357,7 +357,12 @@ def test_apply_tolerates_missing_optims(monkeypatch): # ── fp16 accumulation (consumer fp16-GEMM fast path) ────────────────────────── -def _stub_torch_fp16_accum(monkeypatch, *, consumer = True, with_flag = True): +def _stub_torch_fp16_accum( + monkeypatch, + *, + consumer = True, + with_flag = True, +): torch = types.ModuleType("torch") torch.bfloat16 = "bfloat16" torch.channels_last = "channels_last" @@ -427,9 +432,7 @@ def test_fp16_accum_respects_family_deny_list(monkeypatch): _stub_gguf_accel(monkeypatch) monkeypatch.setattr(ds_mod, "_FP16_ACCUM_DENY", frozenset({"fragile-family"})) fam = types.SimpleNamespace(supports_torch_compile = True, name = "fragile-family") - applied = apply_speed_optims( - _Pipe(), _target(), is_gguf = True, family = fam, speed_mode = "default" - ) + applied = apply_speed_optims(_Pipe(), _target(), is_gguf = True, family = fam, speed_mode = "default") assert applied["fp16_accum"] is False From 86d1d1fd89060305861f3999b70484a87b6f7998 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 4 Jul 2026 07:34:02 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- studio/backend/core/inference/diffusion.py | 8 ++------ studio/backend/tests/test_diffusion_attention.py | 1 - 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/studio/backend/core/inference/diffusion.py b/studio/backend/core/inference/diffusion.py index 8037dde174..25244e55c9 100644 --- a/studio/backend/core/inference/diffusion.py +++ b/studio/backend/core/inference/diffusion.py @@ -1167,17 +1167,13 @@ class DiffusionBackend: # explicit "off" / "fbcache" are pinned and never toggled. cache_request = normalize_transformer_cache(transformer_cache) cache_auto = transformer_cache is None or cache_request == TC_AUTO - cache_quant_active = ( - transformer_quant_engaged is not None or bool(gguf_filename) - ) + cache_quant_active = transformer_quant_engaged is not None or bool(gguf_filename) default_steps: Optional[int] = None if cache_auto: default_steps, _ = default_generation_params( gguf_filename, repo_id, base, fam.name ) - cache_request = ( - TC_FBCACHE if default_steps >= FBCACHE_MIN_STEPS else None - ) + cache_request = TC_FBCACHE if default_steps >= FBCACHE_MIN_STEPS else None cache_engaged = apply_step_cache( pipe, mode = cache_request, diff --git a/studio/backend/tests/test_diffusion_attention.py b/studio/backend/tests/test_diffusion_attention.py index 48647bb0b4..dce7dd2bfa 100644 --- a/studio/backend/tests/test_diffusion_attention.py +++ b/studio/backend/tests/test_diffusion_attention.py @@ -245,7 +245,6 @@ class _Recorder: def _stub_subprocess(monkeypatch, run): import subprocess - monkeypatch.setattr(subprocess, "run", run) From a173b002910266ffa5d527ee353f6754e62d7720 Mon Sep 17 00:00:00 2001 From: Daniel Han Date: Sat, 4 Jul 2026 07:40:34 +0000 Subject: [PATCH 3/4] Pin the sd.cpp CPU backend to physical cores threads = None let sd.cpp default to the logical-core count. The diffusion CPU path is compute-bound GGML matmuls, where oversubscribing hyperthreads adds scheduling contention without extra throughput, so both the persistent server and the one-shot sd-cli now pass cpu_count // 2 (min 1, fallback 8). --- .../backend/core/inference/sd_cpp_backend.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/studio/backend/core/inference/sd_cpp_backend.py b/studio/backend/core/inference/sd_cpp_backend.py index d8cb21d409..45ecee64f5 100644 --- a/studio/backend/core/inference/sd_cpp_backend.py +++ b/studio/backend/core/inference/sd_cpp_backend.py @@ -89,6 +89,17 @@ _MAX_SERVER_BATCH = 8 _SERVER_PER_IMAGE_TIMEOUT_S = 1800.0 +def _default_threads() -> int: + """Physical-core thread count for the sd.cpp CPU backend. + + ``threads = None`` lets sd.cpp pick its own default, which is the logical-core + count (all hyperthreads). For the compute-bound GGML matmuls the diffusion CPU + path runs, oversubscribing the hyperthreads adds scheduling contention without + extra throughput, so pin to physical cores (``cpu_count // 2``) instead. Falls + back to 8 when the count is unknown, and clamps to at least 1.""" + return max(1, (os.cpu_count() or 8) // 2) + + def _server_binary_runnable(binary: str) -> bool: """Best-effort probe that ``binary`` can actually execute (not just exist). @@ -531,7 +542,9 @@ class SdCppDiffusionBackend: vae_format = fam.sd_cpp_vae_format, offload = list(offload), native_speed = native_speed, - threads = None, + # Pin the CPU backend to physical cores; sd.cpp's own + # default oversubscribes hyperthreads (see _default_threads). + threads = _default_threads(), ) except SdCppCancelled: # Startup was aborted by an unload / superseding load: stop the @@ -568,7 +581,9 @@ class SdCppDiffusionBackend: vae_format = fam.sd_cpp_vae_format, native_speed = native_speed, offload_flags = offload, - threads = None, + # One-shot sd-cli reads this per generation (state.threads); pin to + # physical cores for the same reason as the server (see _default_threads). + threads = _default_threads(), sampling_method = fam.sd_cpp_sampling_method, flow_shift = fam.sd_cpp_flow_shift, server = server, From 5df56c080400c438f40fb4eae0d6486536fcbe98 Mon Sep 17 00:00:00 2001 From: Daniel Han Date: Sat, 4 Jul 2026 08:21:07 +0000 Subject: [PATCH 4/4] Stub the torchao probe in the precision-mode capability tests train_precision_modes gates int8/fp8/mxfp8 on has_functional_torchao, and the Backend CI runner does not install torchao, so the three capability-gating tests collapsed to nf4/bf16/auto and failed. They exercise the CAPABILITY gate, not torchao presence: stub the probe functional alongside the CUDA capability patch. Validated with a torchao-blocked run (22 passed). --- studio/backend/tests/test_diffusion_dit_trainer.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/studio/backend/tests/test_diffusion_dit_trainer.py b/studio/backend/tests/test_diffusion_dit_trainer.py index b58868c701..6d7736a106 100644 --- a/studio/backend/tests/test_diffusion_dit_trainer.py +++ b/studio/backend/tests/test_diffusion_dit_trainer.py @@ -230,10 +230,15 @@ def test_mxfp8_training_config_falls_back_to_the_torchao_0_17_api(monkeypatch): def _patch_capability(monkeypatch, capability): # Drive train_precision_modes' GPU probe: pretend CUDA is present at the given tensor - # core capability (fp8 needs sm89+, mxfp8 needs sm100+). + # core capability (fp8 needs sm89+, mxfp8 needs sm100+). The torchao probe is stubbed + # functional so these tests exercise the CAPABILITY gate on hosts without torchao + # (the CPU-only CI runner does not install it). import torch + + import core.training.diffusion_train_common as dtc monkeypatch.setattr(torch.cuda, "is_available", lambda: True) monkeypatch.setattr(torch.cuda, "get_device_capability", lambda *a, **k: capability) + monkeypatch.setattr(dtc, "has_functional_torchao", lambda: True) def test_train_precision_modes_blackwell_lists_mxfp8(monkeypatch):