11import psutil
2+ import logging
23from enum import Enum
34from comfy .cli_args import args
45import comfy .utils
@@ -29,7 +30,7 @@ class CPUState(Enum):
2930xpu_available = False
3031
3132if args .deterministic :
32- print ("Using deterministic algorithms for pytorch" )
33+ logging . warning ("Using deterministic algorithms for pytorch" )
3334 torch .use_deterministic_algorithms (True , warn_only = True )
3435
3536directml_enabled = False
@@ -41,7 +42,7 @@ class CPUState(Enum):
4142 directml_device = torch_directml .device ()
4243 else :
4344 directml_device = torch_directml .device (device_index )
44- print ("Using directml with device:" , torch_directml .device_name (device_index ))
45+ logging . warning ("Using directml with device: {}" . format ( torch_directml .device_name (device_index ) ))
4546 # torch_directml.disable_tiled_resources(True)
4647 lowvram_available = False #TODO: need to find a way to get free memory in directml before this can be enabled by default.
4748
@@ -117,10 +118,10 @@ def get_total_memory(dev=None, torch_total_too=False):
117118
118119total_vram = get_total_memory (get_torch_device ()) / (1024 * 1024 )
119120total_ram = psutil .virtual_memory ().total / (1024 * 1024 )
120- print ("Total VRAM {:0.0f} MB, total RAM {:0.0f} MB" .format (total_vram , total_ram ))
121+ logging . warning ("Total VRAM {:0.0f} MB, total RAM {:0.0f} MB" .format (total_vram , total_ram ))
121122if not args .normalvram and not args .cpu :
122123 if lowvram_available and total_vram <= 4096 :
123- print ("Trying to enable lowvram mode because your GPU seems to have 4GB or less. If you don't want this use: --normalvram" )
124+ logging . warning ("Trying to enable lowvram mode because your GPU seems to have 4GB or less. If you don't want this use: --normalvram" )
124125 set_vram_to = VRAMState .LOW_VRAM
125126
126127try :
@@ -143,12 +144,10 @@ def get_total_memory(dev=None, torch_total_too=False):
143144 pass
144145 try :
145146 XFORMERS_VERSION = xformers .version .__version__
146- print ("xformers version:" , XFORMERS_VERSION )
147+ logging . warning ("xformers version: {}" . format ( XFORMERS_VERSION ) )
147148 if XFORMERS_VERSION .startswith ("0.0.18" ):
148- print ()
149- print ("WARNING: This version of xformers has a major bug where you will get black images when generating high resolution images." )
150- print ("Please downgrade or upgrade xformers to a different version." )
151- print ()
149+ logging .warning ("\n WARNING: This version of xformers has a major bug where you will get black images when generating high resolution images." )
150+ logging .warning ("Please downgrade or upgrade xformers to a different version.\n " )
152151 XFORMERS_ENABLED_VAE = False
153152 except :
154153 pass
@@ -213,11 +212,11 @@ def is_nvidia():
213212FORCE_FP32 = False
214213FORCE_FP16 = False
215214if args .force_fp32 :
216- print ("Forcing FP32, if this improves things please report it." )
215+ logging . warning ("Forcing FP32, if this improves things please report it." )
217216 FORCE_FP32 = True
218217
219218if args .force_fp16 :
220- print ("Forcing FP16." )
219+ logging . warning ("Forcing FP16." )
221220 FORCE_FP16 = True
222221
223222if lowvram_available :
@@ -231,12 +230,12 @@ def is_nvidia():
231230if cpu_state == CPUState .MPS :
232231 vram_state = VRAMState .SHARED
233232
234- print (f"Set vram state to: { vram_state .name } " )
233+ logging . warning (f"Set vram state to: { vram_state .name } " )
235234
236235DISABLE_SMART_MEMORY = args .disable_smart_memory
237236
238237if DISABLE_SMART_MEMORY :
239- print ("Disabling smart memory management" )
238+ logging . warning ("Disabling smart memory management" )
240239
241240def get_torch_device_name (device ):
242241 if hasattr (device , 'type' ):
@@ -254,11 +253,11 @@ def get_torch_device_name(device):
254253 return "CUDA {}: {}" .format (device , torch .cuda .get_device_name (device ))
255254
256255try :
257- print ("Device:" , get_torch_device_name (get_torch_device ()))
256+ logging . warning ("Device: {}" . format ( get_torch_device_name (get_torch_device () )))
258257except :
259- print ("Could not pick default device." )
258+ logging . warning ("Could not pick default device." )
260259
261- print ("VAE dtype:" , VAE_DTYPE )
260+ logging . warning ("VAE dtype: {}" . format ( VAE_DTYPE ) )
262261
263262current_loaded_models = []
264263
@@ -301,7 +300,7 @@ def model_load(self, lowvram_model_memory=0):
301300 raise e
302301
303302 if lowvram_model_memory > 0 :
304- print ("loading in lowvram mode" , lowvram_model_memory / (1024 * 1024 ))
303+ logging . warning ("loading in lowvram mode {}" . format ( lowvram_model_memory / (1024 * 1024 ) ))
305304 mem_counter = 0
306305 for m in self .real_model .modules ():
307306 if hasattr (m , "comfy_cast_weights" ):
@@ -314,7 +313,7 @@ def model_load(self, lowvram_model_memory=0):
314313 elif hasattr (m , "weight" ): #only modules with comfy_cast_weights can be set to lowvram mode
315314 m .to (self .device )
316315 mem_counter += module_size (m )
317- print ("lowvram: loaded module regularly" , m )
316+ logging . warning ("lowvram: loaded module regularly {}" . format ( m ) )
318317
319318 self .model_accelerated = True
320319
@@ -348,7 +347,7 @@ def unload_model_clones(model):
348347 to_unload = [i ] + to_unload
349348
350349 for i in to_unload :
351- print ("unload clone" , i )
350+ logging . warning ("unload clone {}" . format ( i ) )
352351 current_loaded_models .pop (i ).model_unload ()
353352
354353def free_memory (memory_required , device , keep_loaded = []):
@@ -390,7 +389,7 @@ def load_models_gpu(models, memory_required=0):
390389 models_already_loaded .append (loaded_model )
391390 else :
392391 if hasattr (x , "model" ):
393- print (f"Requested to load { x .model .__class__ .__name__ } " )
392+ logging . warning (f"Requested to load { x .model .__class__ .__name__ } " )
394393 models_to_load .append (loaded_model )
395394
396395 if len (models_to_load ) == 0 :
@@ -400,7 +399,7 @@ def load_models_gpu(models, memory_required=0):
400399 free_memory (extra_mem , d , models_already_loaded )
401400 return
402401
403- print (f"Loading { len (models_to_load )} new model{ 's' if len (models_to_load ) > 1 else '' } " )
402+ logging . warning (f"Loading { len (models_to_load )} new model{ 's' if len (models_to_load ) > 1 else '' } " )
404403
405404 total_memory_required = {}
406405 for loaded_model in models_to_load :
0 commit comments