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
3b6fe51c
Commit
3b6fe51c
authored
Jul 01, 2023
by
comfyanonymous
Browse files
Leave text_encoder on the CPU when it can handle it.
parent
b6a60fa6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
4 deletions
+10
-4
comfy/model_management.py
comfy/model_management.py
+7
-2
comfy/sd.py
comfy/sd.py
+3
-2
No files found.
comfy/model_management.py
View file @
3b6fe51c
...
...
@@ -333,14 +333,19 @@ def unet_offload_device():
return
torch
.
device
(
"cpu"
)
def
text_encoder_offload_device
():
if
args
.
gpu_only
:
if
args
.
gpu_only
or
vram_state
==
VRAMState
.
SHARED
:
return
get_torch_device
()
else
:
return
torch
.
device
(
"cpu"
)
def
text_encoder_device
():
if
vram_state
==
VRAMState
.
HIGH_VRAM
or
vram_state
==
VRAMState
.
SHARED
or
vram_state
==
VRAMState
.
NORMAL_VRAM
:
if
args
.
gpu_only
or
vram_state
==
VRAMState
.
SHARED
:
return
get_torch_device
()
elif
vram_state
==
VRAMState
.
HIGH_VRAM
or
vram_state
==
VRAMState
.
NORMAL_VRAM
:
if
torch
.
get_num_threads
()
<
8
:
#leaving the text encoder on the CPU is faster than shifting it if the CPU is fast enough.
return
get_torch_device
()
else
:
return
torch
.
device
(
"cpu"
)
else
:
return
torch
.
device
(
"cpu"
)
...
...
comfy/sd.py
View file @
3b6fe51c
...
...
@@ -533,8 +533,9 @@ class CLIP:
load_device
=
model_management
.
text_encoder_device
()
offload_device
=
model_management
.
text_encoder_offload_device
()
self
.
cond_stage_model
=
clip
(
**
(
params
))
if
model_management
.
should_use_fp16
(
load_device
):
self
.
cond_stage_model
.
half
()
#TODO: make sure this doesn't have a quality loss before enabling.
# if model_management.should_use_fp16(load_device):
# self.cond_stage_model.half()
self
.
cond_stage_model
=
self
.
cond_stage_model
.
to
()
...
...
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