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
c28db1f3
"git@developer.sourcefind.cn:wangsen/paddle_dbnet.git" did not exist on "dbb2cfed3a68fede89963a2c6204c160955d3b45"
Commit
c28db1f3
authored
Aug 17, 2023
by
comfyanonymous
Browse files
Fix potential issues with patching models when saving checkpoints.
parent
1498f1a3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
20 deletions
+9
-20
comfy/sd.py
comfy/sd.py
+9
-20
No files found.
comfy/sd.py
View file @
c28db1f3
...
@@ -574,7 +574,7 @@ class CLIP:
...
@@ -574,7 +574,7 @@ class CLIP:
else
:
else
:
self
.
cond_stage_model
.
reset_clip_layer
()
self
.
cond_stage_model
.
reset_clip_layer
()
model_management
.
load_model_gpu
(
self
.
patcher
)
self
.
load_model
(
)
cond
,
pooled
=
self
.
cond_stage_model
.
encode_token_weights
(
tokens
)
cond
,
pooled
=
self
.
cond_stage_model
.
encode_token_weights
(
tokens
)
if
return_pooled
:
if
return_pooled
:
return
cond
,
pooled
return
cond
,
pooled
...
@@ -590,11 +590,9 @@ class CLIP:
...
@@ -590,11 +590,9 @@ class CLIP:
def
get_sd
(
self
):
def
get_sd
(
self
):
return
self
.
cond_stage_model
.
state_dict
()
return
self
.
cond_stage_model
.
state_dict
()
def
patch_model
(
self
):
def
load_model
(
self
):
self
.
patcher
.
patch_model
()
model_management
.
load_model_gpu
(
self
.
patcher
)
return
self
.
patcher
def
unpatch_model
(
self
):
self
.
patcher
.
unpatch_model
()
def
get_key_patches
(
self
):
def
get_key_patches
(
self
):
return
self
.
patcher
.
get_key_patches
()
return
self
.
patcher
.
get_key_patches
()
...
@@ -922,8 +920,8 @@ def load_controlnet(ckpt_path, model=None):
...
@@ -922,8 +920,8 @@ def load_controlnet(ckpt_path, model=None):
if
pth
:
if
pth
:
if
'difference'
in
controlnet_data
:
if
'difference'
in
controlnet_data
:
if
model
is
not
None
:
if
model
is
not
None
:
m
=
model
.
patch_model
(
)
m
odel_management
.
load_models_gpu
([
model
]
)
model_sd
=
m
.
state_dict
()
model_sd
=
m
odel
.
model_
state_dict
()
for
x
in
controlnet_data
:
for
x
in
controlnet_data
:
c_m
=
"control_model."
c_m
=
"control_model."
if
x
.
startswith
(
c_m
):
if
x
.
startswith
(
c_m
):
...
@@ -931,7 +929,6 @@ def load_controlnet(ckpt_path, model=None):
...
@@ -931,7 +929,6 @@ def load_controlnet(ckpt_path, model=None):
if
sd_key
in
model_sd
:
if
sd_key
in
model_sd
:
cd
=
controlnet_data
[
x
]
cd
=
controlnet_data
[
x
]
cd
+=
model_sd
[
sd_key
].
type
(
cd
.
dtype
).
to
(
cd
.
device
)
cd
+=
model_sd
[
sd_key
].
type
(
cd
.
dtype
).
to
(
cd
.
device
)
model
.
unpatch_model
()
else
:
else
:
print
(
"WARNING: Loaded a diff controlnet without a model. It will very likely not work."
)
print
(
"WARNING: Loaded a diff controlnet without a model. It will very likely not work."
)
...
@@ -1279,14 +1276,6 @@ def load_unet(unet_path): #load unet in diffusers format
...
@@ -1279,14 +1276,6 @@ def load_unet(unet_path): #load unet in diffusers format
return
ModelPatcher
(
model
,
load_device
=
model_management
.
get_torch_device
(),
offload_device
=
offload_device
)
return
ModelPatcher
(
model
,
load_device
=
model_management
.
get_torch_device
(),
offload_device
=
offload_device
)
def
save_checkpoint
(
output_path
,
model
,
clip
,
vae
,
metadata
=
None
):
def
save_checkpoint
(
output_path
,
model
,
clip
,
vae
,
metadata
=
None
):
try
:
model_management
.
load_models_gpu
([
model
,
clip
.
load_model
()])
model
.
patch_model
()
sd
=
model
.
model
.
state_dict_for_saving
(
clip
.
get_sd
(),
vae
.
get_sd
())
clip
.
patch_model
()
utils
.
save_torch_file
(
sd
,
output_path
,
metadata
=
metadata
)
sd
=
model
.
model
.
state_dict_for_saving
(
clip
.
get_sd
(),
vae
.
get_sd
())
utils
.
save_torch_file
(
sd
,
output_path
,
metadata
=
metadata
)
model
.
unpatch_model
()
clip
.
unpatch_model
()
except
Exception
as
e
:
model
.
unpatch_model
()
clip
.
unpatch_model
()
raise
e
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