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
d66415c0
Commit
d66415c0
authored
Feb 17, 2023
by
comfyanonymous
Browse files
Low vram mode for controlnets.
parent
220a72d3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
0 deletions
+21
-0
comfy/model_management.py
comfy/model_management.py
+19
-0
comfy/sd.py
comfy/sd.py
+2
-0
No files found.
comfy/model_management.py
View file @
d66415c0
...
...
@@ -102,6 +102,12 @@ def load_model_gpu(model):
def
load_controlnet_gpu
(
models
):
global
current_gpu_controlnets
global
vram_state
if
vram_state
==
LOW_VRAM
or
vram_state
==
NO_VRAM
:
#don't load controlnets like this if low vram because they will be loaded right before running and unloaded right after
return
for
m
in
current_gpu_controlnets
:
if
m
not
in
models
:
m
.
cpu
()
...
...
@@ -111,6 +117,19 @@ def load_controlnet_gpu(models):
current_gpu_controlnets
.
append
(
m
.
cuda
())
def
load_if_low_vram
(
model
):
global
vram_state
if
vram_state
==
LOW_VRAM
or
vram_state
==
NO_VRAM
:
return
model
.
cuda
()
return
model
def
unload_if_low_vram
(
model
):
global
vram_state
if
vram_state
==
LOW_VRAM
or
vram_state
==
NO_VRAM
:
return
model
.
cpu
()
return
model
def
get_free_memory
():
dev
=
torch
.
cuda
.
current_device
()
stats
=
torch
.
cuda
.
memory_stats
(
dev
)
...
...
comfy/sd.py
View file @
d66415c0
...
...
@@ -349,7 +349,9 @@ class ControlNet:
precision_scope
=
contextlib
.
nullcontext
with
precision_scope
(
self
.
device
):
self
.
control_model
=
model_management
.
load_if_low_vram
(
self
.
control_model
)
control
=
self
.
control_model
(
x
=
x_noisy
,
hint
=
self
.
cond_hint
,
timesteps
=
t
,
context
=
cond_txt
)
self
.
control_model
=
model_management
.
unload_if_low_vram
(
self
.
control_model
)
out
=
[]
autocast_enabled
=
torch
.
is_autocast_enabled
()
for
x
in
control
:
...
...
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