[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2026-05-24 14:33:49 +00:00
commit a08686cc46
2 changed files with 27 additions and 6 deletions

View file

@ -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] = {

View file

@ -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.