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
62db1168
Commit
62db1168
authored
Jun 29, 2023
by
comfyanonymous
Browse files
Move unet to device right after loading on highvram mode.
parent
e7ed507d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
4 deletions
+9
-4
comfy/model_management.py
comfy/model_management.py
+8
-4
comfy/sd.py
comfy/sd.py
+1
-0
No files found.
comfy/model_management.py
View file @
62db1168
...
...
@@ -216,6 +216,11 @@ current_gpu_controlnets = []
model_accelerated
=
False
def
unet_offload_device
():
if
vram_state
==
VRAMState
.
HIGH_VRAM
or
vram_state
==
VRAMState
.
SHARED
:
return
get_torch_device
()
else
:
return
torch
.
device
(
"cpu"
)
def
unload_model
():
global
current_loaded_model
...
...
@@ -228,10 +233,9 @@ def unload_model():
accelerate
.
hooks
.
remove_hook_from_submodules
(
current_loaded_model
.
model
)
model_accelerated
=
False
#never unload models from GPU on high vram
if
vram_state
!=
VRAMState
.
HIGH_VRAM
:
current_loaded_model
.
model
.
cpu
()
current_loaded_model
.
model_patches_to
(
"cpu"
)
current_loaded_model
.
model
.
to
(
unet_offload_device
())
current_loaded_model
.
model_patches_to
(
unet_offload_device
())
current_loaded_model
.
unpatch_model
()
current_loaded_model
=
None
...
...
comfy/sd.py
View file @
62db1168
...
...
@@ -1142,6 +1142,7 @@ def load_checkpoint_guess_config(ckpt_path, output_vae=True, output_clip=True, o
clipvision
=
clip_vision
.
load_clipvision_from_sd
(
sd
,
model_config
.
clip_vision_prefix
,
True
)
model
=
model_config
.
get_model
(
sd
)
model
=
model
.
to
(
model_management
.
unet_offload_device
())
model
.
load_model_weights
(
sd
,
"model.diffusion_model."
)
if
output_vae
:
...
...
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