Maximilian Noichl commited on
Commit
2b73808
·
verified ·
1 Parent(s): 0057f41

Upload 2 files

Browse files
Files changed (2) hide show
  1. VERO_FLUX_lora_01_000002100.safetensors +3 -0
  2. main.py +277 -0
VERO_FLUX_lora_01_000002100.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:16bba396e0e30e2c671a2066d22198c5ef77260a10a0c00446efb09149009ea7
3
+ size 687476560
main.py ADDED
@@ -0,0 +1,277 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import comfy.options
2
+ comfy.options.enable_args_parsing()
3
+
4
+ import os
5
+ import importlib.util
6
+ import folder_paths
7
+ import time
8
+ from comfy.cli_args import args
9
+ from app.logger import setup_logger
10
+ import itertools
11
+ import utils.extra_config
12
+ import logging
13
+
14
+ if __name__ == "__main__":
15
+ #NOTE: These do not do anything on core ComfyUI which should already have no communication with the internet, they are for custom nodes.
16
+ os.environ['HF_HUB_DISABLE_TELEMETRY'] = '1'
17
+ os.environ['DO_NOT_TRACK'] = '1'
18
+
19
+
20
+ setup_logger(log_level=args.verbose)
21
+
22
+ def apply_custom_paths():
23
+ # extra model paths
24
+ extra_model_paths_config_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "extra_model_paths.yaml")
25
+ if os.path.isfile(extra_model_paths_config_path):
26
+ utils.extra_config.load_extra_path_config(extra_model_paths_config_path)
27
+
28
+ if args.extra_model_paths_config:
29
+ for config_path in itertools.chain(*args.extra_model_paths_config):
30
+ utils.extra_config.load_extra_path_config(config_path)
31
+
32
+ # --output-directory, --input-directory, --user-directory
33
+ if args.output_directory:
34
+ output_dir = os.path.abspath(args.output_directory)
35
+ logging.info(f"Setting output directory to: {output_dir}")
36
+ folder_paths.set_output_directory(output_dir)
37
+
38
+ # These are the default folders that checkpoints, clip and vae models will be saved to when using CheckpointSave, etc.. nodes
39
+ folder_paths.add_model_folder_path("checkpoints", os.path.join(folder_paths.get_output_directory(), "checkpoints"))
40
+ folder_paths.add_model_folder_path("clip", os.path.join(folder_paths.get_output_directory(), "clip"))
41
+ folder_paths.add_model_folder_path("vae", os.path.join(folder_paths.get_output_directory(), "vae"))
42
+ folder_paths.add_model_folder_path("diffusion_models",
43
+ os.path.join(folder_paths.get_output_directory(), "diffusion_models"))
44
+ folder_paths.add_model_folder_path("loras", os.path.join(folder_paths.get_output_directory(), "loras"))
45
+
46
+ if args.input_directory:
47
+ input_dir = os.path.abspath(args.input_directory)
48
+ logging.info(f"Setting input directory to: {input_dir}")
49
+ folder_paths.set_input_directory(input_dir)
50
+
51
+ if args.user_directory:
52
+ user_dir = os.path.abspath(args.user_directory)
53
+ logging.info(f"Setting user directory to: {user_dir}")
54
+ folder_paths.set_user_directory(user_dir)
55
+
56
+
57
+ def execute_prestartup_script():
58
+ def execute_script(script_path):
59
+ module_name = os.path.splitext(script_path)[0]
60
+ try:
61
+ spec = importlib.util.spec_from_file_location(module_name, script_path)
62
+ module = importlib.util.module_from_spec(spec)
63
+ spec.loader.exec_module(module)
64
+ return True
65
+ except Exception as e:
66
+ print(f"Failed to execute startup-script: {script_path} / {e}")
67
+ return False
68
+
69
+ if args.disable_all_custom_nodes:
70
+ return
71
+
72
+ node_paths = folder_paths.get_folder_paths("custom_nodes")
73
+ for custom_node_path in node_paths:
74
+ possible_modules = os.listdir(custom_node_path)
75
+ node_prestartup_times = []
76
+
77
+ for possible_module in possible_modules:
78
+ module_path = os.path.join(custom_node_path, possible_module)
79
+ if os.path.isfile(module_path) or module_path.endswith(".disabled") or module_path == "__pycache__":
80
+ continue
81
+
82
+ script_path = os.path.join(module_path, "prestartup_script.py")
83
+ if os.path.exists(script_path):
84
+ time_before = time.perf_counter()
85
+ success = execute_script(script_path)
86
+ node_prestartup_times.append((time.perf_counter() - time_before, module_path, success))
87
+ if len(node_prestartup_times) > 0:
88
+ print("\nPrestartup times for custom nodes:")
89
+ for n in sorted(node_prestartup_times):
90
+ if n[2]:
91
+ import_message = ""
92
+ else:
93
+ import_message = " (PRESTARTUP FAILED)"
94
+ print("{:6.1f} seconds{}:".format(n[0], import_message), n[1])
95
+ print()
96
+
97
+ apply_custom_paths()
98
+ execute_prestartup_script()
99
+
100
+
101
+ # Main code
102
+ import asyncio
103
+ import shutil
104
+ import threading
105
+ import gc
106
+
107
+
108
+ if os.name == "nt":
109
+ logging.getLogger("xformers").addFilter(lambda record: 'A matching Triton is not available' not in record.getMessage())
110
+
111
+ if __name__ == "__main__":
112
+ if args.cuda_device is not None:
113
+ os.environ['CUDA_VISIBLE_DEVICES'] = str(args.cuda_device)
114
+ os.environ['HIP_VISIBLE_DEVICES'] = str(args.cuda_device)
115
+ logging.info("Set cuda device to: {}".format(args.cuda_device))
116
+
117
+ if args.deterministic:
118
+ if 'CUBLAS_WORKSPACE_CONFIG' not in os.environ:
119
+ os.environ['CUBLAS_WORKSPACE_CONFIG'] = ":4096:8"
120
+
121
+ import cuda_malloc
122
+
123
+ if args.windows_standalone_build:
124
+ try:
125
+ from fix_torch import fix_pytorch_libomp
126
+ fix_pytorch_libomp()
127
+ except:
128
+ pass
129
+
130
+ import comfy.utils
131
+
132
+ import execution
133
+ import server
134
+ from server import BinaryEventTypes
135
+ import nodes
136
+ import comfy.model_management
137
+
138
+ def cuda_malloc_warning():
139
+ device = comfy.model_management.get_torch_device()
140
+ device_name = comfy.model_management.get_torch_device_name(device)
141
+ cuda_malloc_warning = False
142
+ if "cudaMallocAsync" in device_name:
143
+ for b in cuda_malloc.blacklist:
144
+ if b in device_name:
145
+ cuda_malloc_warning = True
146
+ if cuda_malloc_warning:
147
+ logging.warning("\nWARNING: this card most likely does not support cuda-malloc, if you get \"CUDA error\" please run ComfyUI with: --disable-cuda-malloc\n")
148
+
149
+ def prompt_worker(q, server):
150
+ current_time: float = 0.0
151
+ e = execution.PromptExecutor(server, lru_size=args.cache_lru)
152
+ last_gc_collect = 0
153
+ need_gc = False
154
+ gc_collect_interval = 10.0
155
+
156
+ while True:
157
+ timeout = 1000.0
158
+ if need_gc:
159
+ timeout = max(gc_collect_interval - (current_time - last_gc_collect), 0.0)
160
+
161
+ queue_item = q.get(timeout=timeout)
162
+ if queue_item is not None:
163
+ item, item_id = queue_item
164
+ execution_start_time = time.perf_counter()
165
+ prompt_id = item[1]
166
+ server.last_prompt_id = prompt_id
167
+
168
+ e.execute(item[2], prompt_id, item[3], item[4])
169
+ need_gc = True
170
+ q.task_done(item_id,
171
+ e.history_result,
172
+ status=execution.PromptQueue.ExecutionStatus(
173
+ status_str='success' if e.success else 'error',
174
+ completed=e.success,
175
+ messages=e.status_messages))
176
+ if server.client_id is not None:
177
+ server.send_sync("executing", { "node": None, "prompt_id": prompt_id }, server.client_id)
178
+
179
+ current_time = time.perf_counter()
180
+ execution_time = current_time - execution_start_time
181
+ logging.info("Prompt executed in {:.2f} seconds".format(execution_time))
182
+
183
+ flags = q.get_flags()
184
+ free_memory = flags.get("free_memory", False)
185
+
186
+ if flags.get("unload_models", free_memory):
187
+ comfy.model_management.unload_all_models()
188
+ need_gc = True
189
+ last_gc_collect = 0
190
+
191
+ if free_memory:
192
+ e.reset()
193
+ need_gc = True
194
+ last_gc_collect = 0
195
+
196
+ if need_gc:
197
+ current_time = time.perf_counter()
198
+ if (current_time - last_gc_collect) > gc_collect_interval:
199
+ gc.collect()
200
+ comfy.model_management.soft_empty_cache()
201
+ last_gc_collect = current_time
202
+ need_gc = False
203
+
204
+ async def run(server, address='', port=8188, verbose=True, call_on_start=None):
205
+ addresses = []
206
+ for addr in address.split(","):
207
+ addresses.append((addr, port))
208
+ await asyncio.gather(server.start_multi_address(addresses, call_on_start), server.publish_loop())
209
+
210
+
211
+ def hijack_progress(server):
212
+ def hook(value, total, preview_image):
213
+ comfy.model_management.throw_exception_if_processing_interrupted()
214
+ progress = {"value": value, "max": total, "prompt_id": server.last_prompt_id, "node": server.last_node_id}
215
+
216
+ server.send_sync("progress", progress, server.client_id)
217
+ if preview_image is not None:
218
+ server.send_sync(BinaryEventTypes.UNENCODED_PREVIEW_IMAGE, preview_image, server.client_id)
219
+ comfy.utils.set_progress_bar_global_hook(hook)
220
+
221
+
222
+ def cleanup_temp():
223
+ temp_dir = folder_paths.get_temp_directory()
224
+ if os.path.exists(temp_dir):
225
+ shutil.rmtree(temp_dir, ignore_errors=True)
226
+
227
+
228
+ if __name__ == "__main__":
229
+ if args.temp_directory:
230
+ temp_dir = os.path.join(os.path.abspath(args.temp_directory), "temp")
231
+ logging.info(f"Setting temp directory to: {temp_dir}")
232
+ folder_paths.set_temp_directory(temp_dir)
233
+ cleanup_temp()
234
+
235
+ if args.windows_standalone_build:
236
+ try:
237
+ import new_updater
238
+ new_updater.update_windows_updater()
239
+ except:
240
+ pass
241
+
242
+ loop = asyncio.new_event_loop()
243
+ asyncio.set_event_loop(loop)
244
+ server = server.PromptServer(loop)
245
+ q = execution.PromptQueue(server)
246
+
247
+ nodes.init_extra_nodes(init_custom_nodes=not args.disable_all_custom_nodes)
248
+
249
+ cuda_malloc_warning()
250
+
251
+ server.add_routes()
252
+ hijack_progress(server)
253
+
254
+ threading.Thread(target=prompt_worker, daemon=True, args=(q, server,)).start()
255
+
256
+ if args.quick_test_for_ci:
257
+ exit(0)
258
+
259
+ os.makedirs(folder_paths.get_temp_directory(), exist_ok=True)
260
+ call_on_start = None
261
+ if args.auto_launch:
262
+ def startup_server(scheme, address, port):
263
+ import webbrowser
264
+ if os.name == 'nt' and address == '0.0.0.0':
265
+ address = '127.0.0.1'
266
+ if ':' in address:
267
+ address = "[{}]".format(address)
268
+ webbrowser.open(f"{scheme}://{address}:{port}")
269
+ call_on_start = startup_server
270
+
271
+ try:
272
+ loop.run_until_complete(server.setup())
273
+ loop.run_until_complete(run(server, address=args.listen, port=args.port, verbose=not args.dont_print_server, call_on_start=call_on_start))
274
+ except KeyboardInterrupt:
275
+ logging.info("\nStopped server")
276
+
277
+ cleanup_temp()