-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel_loader_patch.py
More file actions
38 lines (33 loc) · 1.35 KB
/
model_loader_patch.py
File metadata and controls
38 lines (33 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import comfy.model_management
import logging
from concurrent.futures import ThreadPoolExecutor, as_completed
import folder_paths
import os
def thread_load_model_files(model_type):
paths = folder_paths.get_folder_paths(model_type)
files = []
for path in paths:
if not os.path.isdir(path):
continue
for name in os.listdir(path):
full_path = os.path.join(path, name)
if os.path.isfile(full_path):
files.append(full_path)
def load_file(path):
try:
comfy.model_management.load_model(path, model_type)
return (path, True)
except Exception as e:
return (path, False, str(e))
logging.info(f"[THREAD] Loading {len(files)} {model_type} models...")
with ThreadPoolExecutor(max_workers=os.cpu_count()) as executor:
futures = {executor.submit(load_file, f): f for f in files}
for future in as_completed(futures):
result = future.result()
if result[1]:
logging.info(f"[{model_type.upper()}] Loaded {result[0]}")
else:
logging.warning(f"[{model_type.upper()}] Failed {result[0]} - {result[2]}")
def patch_model_loading():
for model_type in ["checkpoints", "vae", "loras", "clip"]:
thread_load_model_files(model_type)