From dd792c6312040d5284214dd8f97286e028a159b3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 2 Jul 2026 03:30:12 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- scripts/diffusion_quality.py | 4 +++- scripts/perf_levers_probe.py | 4 +++- scripts/verify_prequant_backend.py | 1 + .../backend/core/inference/diffusion_engine_router.py | 1 + studio/backend/core/inference/diffusion_prequant.py | 10 +++++++--- studio/backend/core/inference/sd_cpp_backend.py | 1 + 6 files changed, 16 insertions(+), 5 deletions(-) diff --git a/scripts/diffusion_quality.py b/scripts/diffusion_quality.py index 2d0df87e0e..a8d504713d 100644 --- a/scripts/diffusion_quality.py +++ b/scripts/diffusion_quality.py @@ -296,7 +296,9 @@ def _compare( if all(x == math.inf for x in xs): return math.inf vals = [ - _PERFECT_MATCH_PSNR if x == math.inf else x for x in xs if math.isfinite(x) or x == math.inf + _PERFECT_MATCH_PSNR if x == math.inf else x + for x in xs + if math.isfinite(x) or x == math.inf ] return round(sum(vals) / len(vals), 4) if vals else None diff --git a/scripts/perf_levers_probe.py b/scripts/perf_levers_probe.py index 1f33608060..565e28c6b9 100644 --- a/scripts/perf_levers_probe.py +++ b/scripts/perf_levers_probe.py @@ -156,7 +156,9 @@ def run( try: pipe.transformer.set_attention_backend("native") except Exception as exc: # noqa: BLE001 — best-effort isolation - print(f" [{tag}] attn(native-reset)={type(exc).__name__}:{str(exc)[:60]}", flush = True) + print( + f" [{tag}] attn(native-reset)={type(exc).__name__}:{str(exc)[:60]}", flush = True + ) if fbcache is not None: try: from diffusers.hooks import FirstBlockCacheConfig, apply_first_block_cache diff --git a/scripts/verify_prequant_backend.py b/scripts/verify_prequant_backend.py index 226fb1aaf1..66dc89b0c6 100644 --- a/scripts/verify_prequant_backend.py +++ b/scripts/verify_prequant_backend.py @@ -160,6 +160,7 @@ def run(mode, steps, seed, res): print("FAIL: runtime reference image missing; run --mode runtime first", flush = True) return 1 from PIL import Image + lp = _lpips(np.array(Image.open(ref_path).convert("RGB")), np.array(img)) print(f"[prequant] LPIPS_vs_runtime={lp}", flush = True) if lp is None: diff --git a/studio/backend/core/inference/diffusion_engine_router.py b/studio/backend/core/inference/diffusion_engine_router.py index 7c1fb22fbf..0c758501f8 100644 --- a/studio/backend/core/inference/diffusion_engine_router.py +++ b/studio/backend/core/inference/diffusion_engine_router.py @@ -55,6 +55,7 @@ _INSTALL_ACCELERATOR = {"rocm": "rocm", "cuda": "cuda", "xpu": "vulkan"} def _install_accelerator_for(backend: str) -> str: return _INSTALL_ACCELERATOR.get(backend, "auto") + # The engine the current (or most recent) load committed to, and why a non-native # choice was made. Mutated only under _lock during selection. _lock = threading.Lock() diff --git a/studio/backend/core/inference/diffusion_prequant.py b/studio/backend/core/inference/diffusion_prequant.py index cd7a726dc1..088ebc3575 100644 --- a/studio/backend/core/inference/diffusion_prequant.py +++ b/studio/backend/core/inference/diffusion_prequant.py @@ -226,6 +226,7 @@ def _resolve_checkpoint_path(source: PrequantSource, hf_token: Optional[str]) -> """The local file path for ``source``, downloading from the Hub if needed; None if absent.""" if source.kind == "path": import os + # Expand ~ once: the allowlist gate (_local_prequant_path_allowed) already # expands it, so a "~/..." path that passed the gate must be expanded here too # or os.path.isfile() sees the literal "~" and silently skips a real checkpoint. @@ -277,7 +278,9 @@ def _validate_checkpoint( _warn( logger, scheme, - ValueError(f"checkpoint metadata missing base_model_id; refusing for base {base!r}"), + ValueError( + f"checkpoint metadata missing base_model_id; refusing for base {base!r}" + ), ) return False if not _same_base_model(ckpt_base, base): @@ -300,13 +303,14 @@ def _validate_checkpoint( ckpt_excludes = meta.get("exclude_name_tokens") if ckpt_excludes is not None: from .diffusion_transformer_quant import exclude_tokens_for_scheme - expected = tuple(exclude_tokens_for_scheme(scheme)) if tuple(ckpt_excludes) != expected: _warn( logger, scheme, - ValueError(f"checkpoint exclude_name_tokens {tuple(ckpt_excludes)!r} != {expected!r}"), + ValueError( + f"checkpoint exclude_name_tokens {tuple(ckpt_excludes)!r} != {expected!r}" + ), ) return False # fp8 fast-accum is baked into the saved kernels; only enforce when the caller forces it. diff --git a/studio/backend/core/inference/sd_cpp_backend.py b/studio/backend/core/inference/sd_cpp_backend.py index 20e63459d1..3c79b14f2d 100644 --- a/studio/backend/core/inference/sd_cpp_backend.py +++ b/studio/backend/core/inference/sd_cpp_backend.py @@ -370,6 +370,7 @@ class SdCppDiffusionBackend: # asset-fetch / local-path / cache-IO failure can embed absolute paths # (e.g. /home//...), and the diffusers load path scrubs the same way. from utils.native_path_leases import redact_native_paths + with self._lock: if self._load_token == _load_token and self._loading is not None: self._loading.error = redact_native_paths(str(exc))