Skip to content

Commit

Permalink
Better fix for lowvram issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
comfyanonymous committed Aug 9, 2024
1 parent 86a97e9 commit a3cc326
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions comfy/model_patcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,9 @@ def lowvram_load(self, device_to=None, lowvram_model_memory=0, force_patch_weigh
if m.comfy_cast_weights:
wipe_lowvram_weight(m)

param = list(m.parameters())
if len(param) > 0:
if hasattr(m, "weight"):
mem_counter += comfy.model_management.module_size(m)
param = list(m.parameters())
weight = param[0]
if weight.device == device_to:
continue
Expand Down

5 comments on commit a3cc326

@maedtb
Copy link
Contributor

@maedtb maedtb commented on a3cc326 Aug 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This gives me an IndexError when I try to convert merge a unet fp16 flux1-schnell and clip/vae into a checkpoint file:

13:32:40.463 [Warning] [ComfyUI-0/STDERR] Traceback (most recent call last):
13:32:40.463 [Warning] [ComfyUI-0/STDERR]   File "/opt/comfyui/execution.py", line 152, in recursive_execute
13:32:40.463 [Warning] [ComfyUI-0/STDERR]     output_data, output_ui = get_output_data(obj, input_data_all)
13:32:40.463 [Warning] [ComfyUI-0/STDERR]   File "/opt/comfyui/execution.py", line 82, in get_output_data
13:32:40.463 [Warning] [ComfyUI-0/STDERR]     return_values = map_node_over_list(obj, input_data_all, obj.FUNCTION, allow_interrupt=True)
13:32:40.463 [Warning] [ComfyUI-0/STDERR]   File "/opt/comfyui/execution.py", line 75, in map_node_over_list
13:32:40.464 [Warning] [ComfyUI-0/STDERR]     results.append(getattr(obj, func)(**slice_dict(input_data_all, i)))
13:32:40.464 [Warning] [ComfyUI-0/STDERR]   File "/opt/comfyui/comfy_extras/nodes_model_merging.py", line 242, in save
13:32:40.464 [Warning] [ComfyUI-0/STDERR]     save_checkpoint(model, clip=clip, vae=vae, filename_prefix=filename_prefix, output_dir=self.output_dir, prompt=prompt, extra_pnginfo=extra_pnginfo)
13:32:40.464 [Warning] [ComfyUI-0/STDERR]   File "/opt/comfyui/comfy_extras/nodes_model_merging.py", line 222, in save_checkpoint
13:32:40.464 [Warning] [ComfyUI-0/STDERR]     comfy.sd.save_checkpoint(output_checkpoint, model, clip, vae, clip_vision, metadata=metadata, extra_keys=extra_keys)
13:32:40.464 [Warning] [ComfyUI-0/STDERR]   File "/opt/comfyui/comfy/sd.py", line 640, in save_checkpoint
13:32:40.464 [Warning] [ComfyUI-0/STDERR]     model_management.load_models_gpu(load_models, force_patch_weights=True)
13:32:40.464 [Warning] [ComfyUI-0/STDERR]   File "/opt/comfyui/comfy/model_management.py", line 517, in load_models_gpu
13:32:40.464 [Warning] [ComfyUI-0/STDERR]     cur_loaded_model = loaded_model.model_load(lowvram_model_memory, force_patch_weights=force_patch_weights)
13:32:40.464 [Warning] [ComfyUI-0/STDERR]   File "/opt/comfyui/comfy/model_management.py", line 319, in model_load
13:32:40.464 [Warning] [ComfyUI-0/STDERR]     raise e
13:32:40.464 [Warning] [ComfyUI-0/STDERR]   File "/opt/comfyui/comfy/model_management.py", line 313, in model_load
13:32:40.464 [Warning] [ComfyUI-0/STDERR]     self.real_model = self.model.patch_model_lowvram(device_to=patch_model_to, lowvram_model_memory=lowvram_model_memory, force_patch_weights=force_patch_weights)
13:32:40.464 [Warning] [ComfyUI-0/STDERR]   File "/opt/comfyui/comfy/model_patcher.py", line 421, in patch_model_lowvram
13:32:40.464 [Warning] [ComfyUI-0/STDERR]     self.lowvram_load(device_to, lowvram_model_memory=lowvram_model_memory, force_patch_weights=force_patch_weights)
13:32:40.464 [Warning] [ComfyUI-0/STDERR]   File "/opt/comfyui/comfy/model_patcher.py", line 399, in lowvram_load
13:32:40.464 [Warning] [ComfyUI-0/STDERR]     weight = param[0]
13:32:40.464 [Warning] [ComfyUI-0/STDERR] IndexError: list index out of range

In this case, param has a value of [].

Other people seem to be having issues as well: #4289

@JorgeR81
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, me and some other users are having the same error when I trying to run Flux

IndexError: list index out of range

#4271 (comment)

@marhensa
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, me and some other users are having the same error when I trying to run Flux

IndexError: list index out of range

#4271 (comment)

Oh, that's why!
I'm glad that I found this particular update is what makes Comfy with Flux-1 broken.

Before the update, I could run it without any problems.

@Naturalien
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue for me. Please revert this change!

@maedtb
Copy link
Contributor

@maedtb maedtb commented on a3cc326 Aug 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue for me. Please revert this change!

This has already been fixed in 6678d5c.

Please sign in to comment.