From 39eb022b52057e63d058b50efbd8809ef190735a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 25 Jun 2026 04:11:46 +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 | 21 +++++++++++++++---- .../backend/tests/test_diffusion_backend.py | 14 +++++++++---- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/studio/backend/core/inference/diffusion.py b/studio/backend/core/inference/diffusion.py index c42bc4ccac..23b761dd32 100644 --- a/studio/backend/core/inference/diffusion.py +++ b/studio/backend/core/inference/diffusion.py @@ -130,7 +130,12 @@ class DiffusionBackend: return hf_hub_download(repo_id, gguf_filename, token = hf_token) def _prefetch_files( - self, repo_id: str, gguf_filename: Optional[str], base: str, base_files: list[str], hf_token: Optional[str] + self, + repo_id: str, + gguf_filename: Optional[str], + base: str, + base_files: list[str], + hf_token: Optional[str], ) -> None: """Pre-download the GGUF + the given ``base_files`` into the HF cache, WITHOUT the lock and honoring ``_cancel_event``, so load_pipeline's @@ -140,12 +145,16 @@ class DiffusionBackend: # GGUF transformer (hub repos only; a local path is already on disk). if gguf_filename and not Path(repo_id).expanduser().exists(): - hf_hub_download_with_xet_fallback(repo_id, gguf_filename, hf_token, cancel_event = self._cancel_event) + hf_hub_download_with_xet_fallback( + repo_id, gguf_filename, hf_token, cancel_event = self._cancel_event + ) # Base repo (VAE / text-encoder / scheduler); list comes from the estimate. for rfilename in base_files: if self._cancel_event.is_set(): raise RuntimeError("Cancelled") - hf_hub_download_with_xet_fallback(base, rfilename, hf_token, cancel_event = self._cancel_event) + hf_hub_download_with_xet_fallback( + base, rfilename, hf_token, cancel_event = self._cancel_event + ) # ── Background load + progress ───────────────────────────────────────── @@ -219,7 +228,11 @@ class DiffusionBackend: # Download outside the lock so unload()/an eviction can preempt the # multi-GB pull; load_pipeline below then assembles from the cache. self._prefetch_files( - kwargs["repo_id"], kwargs.get("gguf_filename"), base, base_files, kwargs.get("hf_token") + kwargs["repo_id"], + kwargs.get("gguf_filename"), + base, + base_files, + kwargs.get("hf_token"), ) self.load_pipeline(**kwargs) with self._lock: diff --git a/studio/backend/tests/test_diffusion_backend.py b/studio/backend/tests/test_diffusion_backend.py index 65bc0602ac..4c486e9a96 100644 --- a/studio/backend/tests/test_diffusion_backend.py +++ b/studio/backend/tests/test_diffusion_backend.py @@ -465,8 +465,11 @@ def test_prefetch_aborts_when_cancelled(tmp_path): (tmp_path / "model.gguf").write_bytes(b"x") with pytest.raises(RuntimeError, match = "Cancelled"): backend._prefetch_files( - str(tmp_path), "model.gguf", "Tongyi-MAI/Z-Image-Turbo", - ["vae/diffusion_pytorch_model.safetensors"], None, + str(tmp_path), + "model.gguf", + "Tongyi-MAI/Z-Image-Turbo", + ["vae/diffusion_pytorch_model.safetensors"], + None, ) @@ -479,8 +482,11 @@ def test_prefetch_downloads_gguf_and_base(monkeypatch, tmp_path): ) # Hub repo: the GGUF transformer and each base file are fetched. backend._prefetch_files( - "unsloth/Z-Image-Turbo-GGUF", "model.gguf", "base/repo", - ["vae/x.safetensors", "text_encoder/y.safetensors"], "hf_tok", + "unsloth/Z-Image-Turbo-GGUF", + "model.gguf", + "base/repo", + ["vae/x.safetensors", "text_encoder/y.safetensors"], + "hf_tok", ) assert ("unsloth/Z-Image-Turbo-GGUF", "model.gguf") in calls assert ("base/repo", "vae/x.safetensors") in calls