From 206c9dd9fbed62b6c833fc8a52209224b154a60c Mon Sep 17 00:00:00 2001 From: tazlin Date: Sat, 23 Nov 2024 09:40:02 -0500 Subject: [PATCH 01/11] chore: ignore training data --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 6fc50bf5..270afe8a 100644 --- a/.gitignore +++ b/.gitignore @@ -168,3 +168,6 @@ tmp/ *.pth .gitignore pipeline_debug.json +inference-time-data* +kudos_models/ +optuna_stud*.db From dec43ce32255dce407f68a1e64a6ce0787fa8195 Mon Sep 17 00:00:00 2001 From: tazlin Date: Sat, 23 Nov 2024 09:55:17 -0500 Subject: [PATCH 02/11] fix: remove unneeded type hint --- hordelib/comfy_horde.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hordelib/comfy_horde.py b/hordelib/comfy_horde.py index ec4de9db..4d969e99 100644 --- a/hordelib/comfy_horde.py +++ b/hordelib/comfy_horde.py @@ -90,7 +90,7 @@ """Will aggressively unload models from memory""" _comfy_cleanup_models: Callable[[bool], None] """Will unload unused models from memory""" -_comfy_soft_empty_cache: Callable[[bool], None] +_comfy_soft_empty_cache: Callable """Triggers comfyui and torch to empty their caches""" _comfy_is_changed_cache_get: Callable From 772fb9f4801bc53014e757b9b27a635da9207dff Mon Sep 17 00:00:00 2001 From: db0 Date: Mon, 9 Dec 2024 22:56:02 +0100 Subject: [PATCH 03/11] fix: ensure adhoc loras can be rotated --- hordelib/model_manager/lora.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/hordelib/model_manager/lora.py b/hordelib/model_manager/lora.py index bc34d610..8048e5a4 100644 --- a/hordelib/model_manager/lora.py +++ b/hordelib/model_manager/lora.py @@ -97,7 +97,6 @@ def __init__( self._thread = None self.stop_downloading = True # Not yet handled, as we need a global reference to search through. - self._previous_model_reference = {} # type: ignore # FIXME: add type self._adhoc_loras = set() # type: ignore # FIXME: add type self._download_wait = download_wait # If false, this MM will only download SFW loras @@ -205,7 +204,7 @@ def load_model_database(self) -> None: for version_id in lora["versions"]: self._index_version_ids[version_id] = lora["name"] self.model_reference = new_model_reference - logger.info("Loaded model reference from disk.") + logger.info(f"Loaded model reference from disk with {len(self.model_reference)} lora entries.") except json.JSONDecodeError: logger.error(f"Could not load {self.models_db_name} model reference from disk! Bad JSON?") self.model_reference = {} @@ -544,7 +543,8 @@ def _download_thread(self, thread_number): lora["last_checked"] = datetime.now().strftime("%Y-%m-%d %H:%M:%S") self._add_lora_to_reference(lora) if self.is_adhoc_cache_full(): - self.delete_oldest_lora() + for _lora_iter in range(self.amount_of_adhoc_loras_to_delete()): + self.delete_oldest_lora() self.save_cached_reference_to_disk() break @@ -680,7 +680,6 @@ def download_default_loras(self, nsfw=True, timeout=None): if not self.are_downloads_complete(): return self.nsfw = nsfw - self._previous_model_reference = copy.deepcopy(self.model_reference) # TODO: Avoid clearing this out, until we know CivitAI is not dead. self.clear_all_references() os.makedirs(self.model_folder_path, exist_ok=True) @@ -891,6 +890,12 @@ def is_default_cache_full(self): def is_adhoc_cache_full(self): return self.calculate_adhoc_loras_cache() >= self.max_adhoc_disk + def amount_of_adhoc_loras_to_delete(self): + if not self.is_adhoc_cache_full(): + return 0 + # If we have exceeded our cache, we delete 1 lora + 1 extra lora per 4G over our cache. + return 1 + ((self.calculate_adhoc_loras_cache() - self._max_top_disk) / 4096) + def calculate_download_queue(self): total_queue = 0 for lora in self._download_queue: @@ -1010,7 +1015,7 @@ def reset_adhoc_loras(self): self._adhoc_loras = set() unsorted_items = [] sorted_items = [] - for plora_key, plora in self._previous_model_reference.items(): + for plora_key, plora in self.model_reference.items(): for version in plora.get("versions", {}).values(): unsorted_items.append((plora_key, version)) try: @@ -1021,9 +1026,9 @@ def reset_adhoc_loras(self): ) except Exception as err: logger.error(err) - while not self.is_adhoc_cache_full() and len(sorted_items) > 0: + while len(sorted_items) > 0: prevlora_key, prevversion = sorted_items.pop() - if prevlora_key in self.model_reference: + if prevversion.get("adhoc", True) is False: continue # If True, it will initiates a redownload and call _add_lora_to_reference() later if not self._check_for_refresh(prevlora_key): @@ -1031,14 +1036,16 @@ def reset_adhoc_loras(self): prevversion["last_used"] = now # We create a temp lora dict holding the just one version (the one we want to keep) # The _add_lora_to_reference() will anyway merge versions if we keep more than 1 - temp_lora = self._previous_model_reference[prevlora_key].copy() + temp_lora = self.model_reference[prevlora_key].copy() temp_lora["versions"] = {} temp_lora["versions"][prevversion["version_id"]] = prevversion self._add_lora_to_reference(temp_lora) self._adhoc_loras.add(prevlora_key) - self._previous_model_reference = {} self.save_cached_reference_to_disk() - logger.debug("Finished lora reset") + logger.debug( + f"Finished lora reset. Added {len(self._adhoc_loras)} adhoc loras " + f"with a total size of {self.calculate_adhoc_loras_cache()}" + ) def get_lora_metadata(self, url: str) -> dict: """Returns parsed Lora details from civitAI From a7e8d96c928cca9e4f6564738077cf1150b19594 Mon Sep 17 00:00:00 2001 From: db0 Date: Tue, 10 Dec 2024 00:30:30 +0100 Subject: [PATCH 04/11] feat: adds delete_adhoc_loras_over_limit() --- hordelib/model_manager/lora.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/hordelib/model_manager/lora.py b/hordelib/model_manager/lora.py index 8048e5a4..8cb18e36 100644 --- a/hordelib/model_manager/lora.py +++ b/hordelib/model_manager/lora.py @@ -1,4 +1,3 @@ -import copy import glob import hashlib import json @@ -960,6 +959,10 @@ def delete_unused_loras(self, timeout=0): logger.warning(f"Expected to delete lora file {lora_filename} but it was not found.") return loras_to_delete + def delete_adhoc_loras_over_limit(self): + while self.is_adhoc_cache_full(): + self.delete_oldest_lora() + def delete_lora_files(self, lora_filename: str): filename = os.path.join(self.model_folder_path, lora_filename) if not os.path.exists(filename): @@ -1044,7 +1047,7 @@ def reset_adhoc_loras(self): self.save_cached_reference_to_disk() logger.debug( f"Finished lora reset. Added {len(self._adhoc_loras)} adhoc loras " - f"with a total size of {self.calculate_adhoc_loras_cache()}" + f"with a total size of {self.calculate_adhoc_loras_cache()}", ) def get_lora_metadata(self, url: str) -> dict: From 1cdd90e2ae98285497cebee8feefeab3331d7ab4 Mon Sep 17 00:00:00 2001 From: db0 Date: Tue, 10 Dec 2024 00:32:21 +0100 Subject: [PATCH 05/11] fix: used wrong var --- hordelib/model_manager/lora.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hordelib/model_manager/lora.py b/hordelib/model_manager/lora.py index 8cb18e36..9a27c45b 100644 --- a/hordelib/model_manager/lora.py +++ b/hordelib/model_manager/lora.py @@ -893,7 +893,7 @@ def amount_of_adhoc_loras_to_delete(self): if not self.is_adhoc_cache_full(): return 0 # If we have exceeded our cache, we delete 1 lora + 1 extra lora per 4G over our cache. - return 1 + ((self.calculate_adhoc_loras_cache() - self._max_top_disk) / 4096) + return 1 + int((self.calculate_adhoc_loras_cache() - self.max_adhoc_disk) / 4096) def calculate_download_queue(self): total_queue = 0 From 295e8701ae96f1010b1a654621d785f67a9309cd Mon Sep 17 00:00:00 2001 From: tazlin Date: Wed, 11 Dec 2024 10:20:40 -0500 Subject: [PATCH 06/11] feat: use comfyui `7a7efe8` - See the diff for ComfyUI from the last update here: https://github.com/comfyanonymous/ComfyUI/compare/839ed3368efd0f61a2b986f57fe9e0698fd08e9f...7a7efe8424d960a95be393a85ca4d94e5892edea --- hordelib/consts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hordelib/consts.py b/hordelib/consts.py index d8955241..10b39bb9 100644 --- a/hordelib/consts.py +++ b/hordelib/consts.py @@ -6,7 +6,7 @@ from hordelib.config_path import get_hordelib_path -COMFYUI_VERSION = "839ed3368efd0f61a2b986f57fe9e0698fd08e9f" +COMFYUI_VERSION = "7a7efe8424d960a95be393a85ca4d94e5892edea" """The exact version of ComfyUI version to load.""" REMOTE_PROXY = "" From 518888a3073a4ed29987476cb62dd333b63555ef Mon Sep 17 00:00:00 2001 From: tazlin Date: Wed, 11 Dec 2024 10:57:21 -0500 Subject: [PATCH 07/11] fix: adjust to use new signature for `cleanup_models` --- hordelib/comfy_horde.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hordelib/comfy_horde.py b/hordelib/comfy_horde.py index 4d969e99..734b3ab2 100644 --- a/hordelib/comfy_horde.py +++ b/hordelib/comfy_horde.py @@ -88,7 +88,7 @@ _comfy_model_loading: types.ModuleType _comfy_free_memory: Callable[[float, torch.device, list], None] """Will aggressively unload models from memory""" -_comfy_cleanup_models: Callable[[bool], None] +_comfy_cleanup_models: Callable[[None], None] """Will unload unused models from memory""" _comfy_soft_empty_cache: Callable """Triggers comfyui and torch to empty their caches""" @@ -944,7 +944,7 @@ def _run_pipeline( if self.aggressive_unloading: global _comfy_cleanup_models logger.debug("Cleaning up models") - _comfy_cleanup_models(False) + _comfy_cleanup_models() _comfy_soft_empty_cache() stdio.replay() From 6fb8e789951c0e7be044f5dc39ba63fe509fe075 Mon Sep 17 00:00:00 2001 From: tazlin Date: Wed, 11 Dec 2024 10:58:01 -0500 Subject: [PATCH 08/11] fix: remove reference in layer diffusion to obsolete func --- .../lib_layerdiffusion/attention_sharing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hordelib/nodes/comfyui_layerdiffuse/lib_layerdiffusion/attention_sharing.py b/hordelib/nodes/comfyui_layerdiffuse/lib_layerdiffusion/attention_sharing.py index a511f745..c707a949 100644 --- a/hordelib/nodes/comfyui_layerdiffuse/lib_layerdiffusion/attention_sharing.py +++ b/hordelib/nodes/comfyui_layerdiffuse/lib_layerdiffusion/attention_sharing.py @@ -296,7 +296,7 @@ def __init__(self, layer_list): class AttentionSharingPatcher(torch.nn.Module): def __init__(self, unet, frames=2, use_control=True, rank=256): super().__init__() - model_management.unload_model_clones(unet) + # model_management.unload_model_clones(unet) # this is now handled implicitly in comfyui units = [] for i in range(32): From 1a09ddf6b9e6f199d7905ab81b59b490bfbed5dd Mon Sep 17 00:00:00 2001 From: tazlin Date: Wed, 11 Dec 2024 11:26:00 -0500 Subject: [PATCH 09/11] fix: add new required param for clip_vision w/ remix --- hordelib/pipeline_designs/pipeline_stable_cascade_remix.json | 5 ++++- hordelib/pipelines/pipeline_stable_cascade_remix.json | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/hordelib/pipeline_designs/pipeline_stable_cascade_remix.json b/hordelib/pipeline_designs/pipeline_stable_cascade_remix.json index efc0f567..1b3660be 100644 --- a/hordelib/pipeline_designs/pipeline_stable_cascade_remix.json +++ b/hordelib/pipeline_designs/pipeline_stable_cascade_remix.json @@ -460,7 +460,10 @@ "title": "clip_vision_encode_0", "properties": { "Node name for S&R": "CLIPVisionEncode" - } + }, + "widgets_values": [ + "none" + ] }, { "id": 51, diff --git a/hordelib/pipelines/pipeline_stable_cascade_remix.json b/hordelib/pipelines/pipeline_stable_cascade_remix.json index 3036c79d..23b81fd1 100644 --- a/hordelib/pipelines/pipeline_stable_cascade_remix.json +++ b/hordelib/pipelines/pipeline_stable_cascade_remix.json @@ -171,7 +171,8 @@ } }, "50": { - "inputs": { + "inputs": { + "crop": "none", "clip_vision": [ "49", 3 From b61ef4194e9633622fb668dc5cf3ef78069f83e5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 11 Dec 2024 16:30:08 +0000 Subject: [PATCH 10/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- hordelib/pipelines/pipeline_stable_cascade_remix.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hordelib/pipelines/pipeline_stable_cascade_remix.json b/hordelib/pipelines/pipeline_stable_cascade_remix.json index 23b81fd1..cf1ce15e 100644 --- a/hordelib/pipelines/pipeline_stable_cascade_remix.json +++ b/hordelib/pipelines/pipeline_stable_cascade_remix.json @@ -171,7 +171,7 @@ } }, "50": { - "inputs": { + "inputs": { "crop": "none", "clip_vision": [ "49", From 5de5bc7ec8be58d5e51bae8abd8242ce9c8b2c7e Mon Sep 17 00:00:00 2001 From: tazlin Date: Wed, 11 Dec 2024 11:32:06 -0500 Subject: [PATCH 11/11] style/fix: remove unneeded type hint --- hordelib/comfy_horde.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hordelib/comfy_horde.py b/hordelib/comfy_horde.py index 734b3ab2..a94cdaa2 100644 --- a/hordelib/comfy_horde.py +++ b/hordelib/comfy_horde.py @@ -88,7 +88,7 @@ _comfy_model_loading: types.ModuleType _comfy_free_memory: Callable[[float, torch.device, list], None] """Will aggressively unload models from memory""" -_comfy_cleanup_models: Callable[[None], None] +_comfy_cleanup_models: Callable """Will unload unused models from memory""" _comfy_soft_empty_cache: Callable """Triggers comfyui and torch to empty their caches"""