Skip to content

Commit 25de7b1

Browse files
Try to fix slow load issue on low ram hardware with pinned mem. (#10536)
1 parent ab7ab5b commit 25de7b1

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

comfy/model_patcher.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,7 @@ def load(self, device_to=None, lowvram_model_memory=0, force_patch_weights=False
658658
loading = self._load_list()
659659

660660
load_completely = []
661+
offloaded = []
661662
loading.sort(reverse=True)
662663
for x in loading:
663664
n = x[1]
@@ -699,8 +700,7 @@ def load(self, device_to=None, lowvram_model_memory=0, force_patch_weights=False
699700
patch_counter += 1
700701

701702
cast_weight = True
702-
for param in params:
703-
self.pin_weight_to_device("{}.{}".format(n, param))
703+
offloaded.append((module_mem, n, m, params))
704704
else:
705705
if hasattr(m, "comfy_cast_weights"):
706706
wipe_lowvram_weight(m)
@@ -741,6 +741,12 @@ def load(self, device_to=None, lowvram_model_memory=0, force_patch_weights=False
741741
for x in load_completely:
742742
x[2].to(device_to)
743743

744+
for x in offloaded:
745+
n = x[1]
746+
params = x[3]
747+
for param in params:
748+
self.pin_weight_to_device("{}.{}".format(n, param))
749+
744750
if lowvram_counter > 0:
745751
logging.info("loaded partially {} {} {}".format(lowvram_model_memory / (1024 * 1024), mem_counter / (1024 * 1024), patch_counter))
746752
self.model.model_lowvram = True

0 commit comments

Comments
 (0)