From 6dca17bd2dd7455701d5eb466d39d72aa4520b1c Mon Sep 17 00:00:00 2001 From: Jedrzej Kosinski Date: Mon, 3 Mar 2025 23:08:29 -0600 Subject: [PATCH] Satisfy ruff linting --- comfy/controlnet.py | 6 +++--- comfy/model_management.py | 1 - comfy/multigpu.py | 6 +++--- comfy/samplers.py | 4 ++-- comfy_extras/nodes_multigpu.py | 5 ++--- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/comfy/controlnet.py b/comfy/controlnet.py index 9bcd1d2e..14f13bd9 100644 --- a/comfy/controlnet.py +++ b/comfy/controlnet.py @@ -72,7 +72,7 @@ class ControlIsolation: def __enter__(self): self.control.previous_controlnet = None - + def __exit__(self, *args): self.control.previous_controlnet = self.orig_previous_controlnet @@ -151,7 +151,7 @@ class ControlBase: def deepclone_multigpu(self, load_device, autoregister=False): ''' Create deep clone of Control object where model(s) is set to other devices. - + When autoregister is set to True, the deep clone is also added to multigpu_clones dict. ''' raise NotImplementedError("Classes inheriting from ControlBase should define their own deepclone_multigpu funtion.") @@ -846,7 +846,7 @@ class T2IAdapter(ControlBase): c = T2IAdapter(self.t2i_model, self.channels_in, self.compression_ratio, self.upscale_algorithm) self.copy_to(c) return c - + def deepclone_multigpu(self, load_device, autoregister=False): c = self.copy() c.t2i_model = copy.deepcopy(c.t2i_model) diff --git a/comfy/model_management.py b/comfy/model_management.py index 10d0dece..6e243a43 100644 --- a/comfy/model_management.py +++ b/comfy/model_management.py @@ -30,7 +30,6 @@ import gc from typing import TYPE_CHECKING if TYPE_CHECKING: from comfy.model_patcher import ModelPatcher - from comfy.model_base import BaseModel class VRAMState(Enum): DISABLED = 0 #No vram present: no need to move models to vram diff --git a/comfy/multigpu.py b/comfy/multigpu.py index 9cc8a37f..aef0b68e 100644 --- a/comfy/multigpu.py +++ b/comfy/multigpu.py @@ -18,7 +18,7 @@ class GPUOptions: def clone(self): return GPUOptions(self.device_index, self.relative_speed) - + def create_dict(self): return { "relative_speed": self.relative_speed @@ -86,7 +86,7 @@ def create_multigpu_deepclones(model: ModelPatcher, max_gpus: int, gpu_options: device_patcher = lm.clone() logging.info(f"Reusing loaded deepclone of {device_patcher.model.__class__.__name__} for {device}") break - if device_patcher is None: + if device_patcher is None: device_patcher = model.deepclone_multigpu(new_load_device=device) device_patcher.is_multigpu_base_clone = True multigpu_models = model.get_additional_models_with_key("multigpu") @@ -138,7 +138,7 @@ def load_balance_devices(model_options: dict[str], total_work: int, return_idle_ # if need to compare work idle time, need to normalize to a common total work if work_normalized: idle_time *= (work_normalized/total_work) - + return LoadBalance(dict_work_per_device, idle_time) def round_preserved(values: list[float]): diff --git a/comfy/samplers.py b/comfy/samplers.py index babfe7a4..bc97f9f7 100644 --- a/comfy/samplers.py +++ b/comfy/samplers.py @@ -384,7 +384,7 @@ def _calc_cond_batch_multigpu(model: BaseModel, conds: list[list[dict]], x_in: t devices = [dev_m for dev_m in model_options['multigpu_clones'].keys()] device_batched_hooked_to_run: dict[torch.device, list[tuple[comfy.hooks.HookGroup, tuple]]] = {} - + total_conds = 0 for to_run in hooked_to_run.values(): total_conds += len(to_run) @@ -504,7 +504,7 @@ def _calc_cond_batch_multigpu(model: BaseModel, conds: list[list[dict]], x_in: t new_thread = threading.Thread(target=_handle_batch, args=(device, batch_tuple, results)) threads.append(new_thread) new_thread.start() - + for thread in threads: thread.join() diff --git a/comfy_extras/nodes_multigpu.py b/comfy_extras/nodes_multigpu.py index d1e458b7..3b68c10f 100644 --- a/comfy_extras/nodes_multigpu.py +++ b/comfy_extras/nodes_multigpu.py @@ -1,5 +1,4 @@ from __future__ import annotations -import logging from inspect import cleandoc from typing import TYPE_CHECKING @@ -11,7 +10,7 @@ import comfy.multigpu class MultiGPUWorkUnitsNode: """ Prepares model to have sampling accelerated via splitting work units. - + Should be placed after nodes that modify the model object itself, such as compile or attention-switch nodes. Other than those exceptions, this node can be placed in any order. @@ -30,7 +29,7 @@ class MultiGPUWorkUnitsNode: "gpu_options": ("GPU_OPTIONS",) } } - + RETURN_TYPES = ("MODEL",) FUNCTION = "init_multigpu" CATEGORY = "advanced/multigpu"