From a08686cc46a6941cdb87ccae4790d7ff99217dcc Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 24 May 2026 14:33:49 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- studio/backend/core/inference/diffusion.py | 15 ++++++++++++--- studio/backend/tests/test_diffusion_backend.py | 18 +++++++++++++++--- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/studio/backend/core/inference/diffusion.py b/studio/backend/core/inference/diffusion.py index c44f132142..dee46a3704 100644 --- a/studio/backend/core/inference/diffusion.py +++ b/studio/backend/core/inference/diffusion.py @@ -60,6 +60,7 @@ logger = get_logger(__name__) # the user gave us a GGUF-only repo. The base_repo is documented to the # user via ``status()`` so they understand why a second download fires. + @dataclass(frozen = True) class DiffusionFamily: name: str @@ -117,7 +118,9 @@ _FAMILIES: tuple[DiffusionFamily, ...] = ( ) -def detect_family(repo_id: str, *, override_family: Optional[str] = None) -> Optional[DiffusionFamily]: +def detect_family( + repo_id: str, *, override_family: Optional[str] = None +) -> Optional[DiffusionFamily]: """Return the diffusion family matching ``repo_id``. Matching is substring-based and case-insensitive. ``override_family`` @@ -217,7 +220,11 @@ class DiffusionBackend: if torch.cuda.is_available(): return "cuda", torch.bfloat16 - if hasattr(torch, "backends") and getattr(torch.backends, "mps", None) and torch.backends.mps.is_available(): + if ( + hasattr(torch, "backends") + and getattr(torch.backends, "mps", None) + and torch.backends.mps.is_available() + ): return "mps", torch.float16 return "cpu", torch.float32 @@ -401,7 +408,9 @@ class DiffusionBackend: # Match the device of the pipeline so determinism holds # across reload cycles. For CPU offload, the noise still # has to live on the device the diffusion forward runs on. - gen_device = "cuda" if device == "cuda" and torch.cuda.is_available() else "cpu" + gen_device = ( + "cuda" if device == "cuda" and torch.cuda.is_available() else "cpu" + ) generator = torch.Generator(device = gen_device).manual_seed(int(seed)) call_kwargs: dict[str, Any] = { diff --git a/studio/backend/tests/test_diffusion_backend.py b/studio/backend/tests/test_diffusion_backend.py index d70b4a2acb..642af72361 100644 --- a/studio/backend/tests/test_diffusion_backend.py +++ b/studio/backend/tests/test_diffusion_backend.py @@ -184,10 +184,17 @@ def _stub_pipeline(monkeypatch, *, returns = None, raises = None): def __call__(self, **kwargs): if raises is not None: raise raises + class _Out: pass + o = _Out() - o.images = [returns or Image.new("RGB", (kwargs["width"], kwargs["height"]), color = (0, 255, 0))] + o.images = [ + returns + or Image.new( + "RGB", (kwargs["width"], kwargs["height"]), color = (0, 255, 0) + ) + ] return o backend._pipe = _StubPipe() @@ -293,8 +300,11 @@ def _install_fake_diffusers(monkeypatch, *, raise_on_pipeline = False): def __call__(self, **kwargs): class _Out: pass + o = _Out() - o.images = [Image.new("RGB", (kwargs["width"], kwargs["height"]), color = (0, 0, 255))] + o.images = [ + Image.new("RGB", (kwargs["width"], kwargs["height"]), color = (0, 0, 255)) + ] return o def enable_model_cpu_offload(self): @@ -320,7 +330,9 @@ def _install_fake_diffusers(monkeypatch, *, raise_on_pipeline = False): # Pretend HF Hub gave us a local file without actually fetching. fake_hub = types.ModuleType("huggingface_hub") - fake_hub.hf_hub_download = lambda repo_id, filename, token = None: f"/fake/{repo_id}/{filename}" + fake_hub.hf_hub_download = ( + lambda repo_id, filename, token = None: f"/fake/{repo_id}/{filename}" + ) monkeypatch.setitem(sys.modules, "huggingface_hub", fake_hub) # Force CPU dtype so the test does not need CUDA.