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
7d401ed1
Commit
7d401ed1
authored
Sep 11, 2023
by
comfyanonymous
Browse files
Add ldm format support to UNETLoader.
parent
9562a6b4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
14 deletions
+20
-14
comfy/sd.py
comfy/sd.py
+20
-14
No files found.
comfy/sd.py
View file @
7d401ed1
...
@@ -454,20 +454,26 @@ def load_unet(unet_path): #load unet in diffusers format
...
@@ -454,20 +454,26 @@ def load_unet(unet_path): #load unet in diffusers format
sd
=
comfy
.
utils
.
load_torch_file
(
unet_path
)
sd
=
comfy
.
utils
.
load_torch_file
(
unet_path
)
parameters
=
comfy
.
utils
.
calculate_parameters
(
sd
)
parameters
=
comfy
.
utils
.
calculate_parameters
(
sd
)
fp16
=
model_management
.
should_use_fp16
(
model_params
=
parameters
)
fp16
=
model_management
.
should_use_fp16
(
model_params
=
parameters
)
if
"input_blocks.0.0.weight"
in
sd
:
#ldm
model_config
=
model_detection
.
model_config_from_diffusers_unet
(
sd
,
fp16
)
model_config
=
model_detection
.
model_config_from_unet
(
sd
,
""
,
fp16
)
if
model_config
is
None
:
if
model_config
is
None
:
print
(
"ERROR UNSUPPORTED UNET"
,
unet_path
)
raise
RuntimeError
(
"ERROR: Could not detect model type of: {}"
.
format
(
unet_path
))
return
None
new_sd
=
sd
diffusers_keys
=
comfy
.
utils
.
unet_to_diffusers
(
model_config
.
unet_config
)
else
:
#diffusers
model_config
=
model_detection
.
model_config_from_diffusers_unet
(
sd
,
fp16
)
new_sd
=
{}
if
model_config
is
None
:
for
k
in
diffusers_keys
:
print
(
"ERROR UNSUPPORTED UNET"
,
unet_path
)
if
k
in
sd
:
return
None
new_sd
[
diffusers_keys
[
k
]]
=
sd
.
pop
(
k
)
else
:
diffusers_keys
=
comfy
.
utils
.
unet_to_diffusers
(
model_config
.
unet_config
)
print
(
diffusers_keys
[
k
],
k
)
new_sd
=
{}
for
k
in
diffusers_keys
:
if
k
in
sd
:
new_sd
[
diffusers_keys
[
k
]]
=
sd
.
pop
(
k
)
else
:
print
(
diffusers_keys
[
k
],
k
)
offload_device
=
model_management
.
unet_offload_device
()
offload_device
=
model_management
.
unet_offload_device
()
model
=
model_config
.
get_model
(
new_sd
,
""
)
model
=
model_config
.
get_model
(
new_sd
,
""
)
model
=
model
.
to
(
offload_device
)
model
=
model
.
to
(
offload_device
)
...
...
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