Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
ComfyUI
Commits
e1e322cf
Commit
e1e322cf
authored
Dec 28, 2023
by
comfyanonymous
Browse files
Load weights that can't be lowvramed to target device.
parent
a8baa40d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
5 deletions
+13
-5
comfy/model_management.py
comfy/model_management.py
+13
-5
No files found.
comfy/model_management.py
View file @
e1e322cf
...
...
@@ -259,6 +259,14 @@ print("VAE dtype:", VAE_DTYPE)
current_loaded_models
=
[]
def
module_size
(
module
):
module_mem
=
0
sd
=
module
.
state_dict
()
for
k
in
sd
:
t
=
sd
[
k
]
module_mem
+=
t
.
nelement
()
*
t
.
element_size
()
return
module_mem
class
LoadedModel
:
def
__init__
(
self
,
model
):
self
.
model
=
model
...
...
@@ -296,14 +304,14 @@ class LoadedModel:
if
hasattr
(
m
,
"comfy_cast_weights"
):
m
.
prev_comfy_cast_weights
=
m
.
comfy_cast_weights
m
.
comfy_cast_weights
=
True
module_mem
=
0
sd
=
m
.
state_dict
()
for
k
in
sd
:
t
=
sd
[
k
]
module_mem
+=
t
.
nelement
()
*
t
.
element_size
()
module_mem
=
module_size
(
m
)
if
mem_counter
+
module_mem
<
lowvram_model_memory
:
m
.
to
(
self
.
device
)
mem_counter
+=
module_mem
elif
hasattr
(
m
,
"weight"
):
#only modules with comfy_cast_weights can be set to lowvram mode
m
.
to
(
self
.
device
)
mem_counter
+=
module_size
(
m
)
print
(
"lowvram: loaded module regularly"
,
m
)
self
.
model_accelerated
=
True
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment