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
renzhc
diffusers_dcu
Commits
099d3eab
Commit
099d3eab
authored
Jul 01, 2022
by
patil-suraj
Browse files
add conversion script for LatentDiffusionUncondPipeline
parent
23904d54
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
13 deletions
+56
-13
scripts/conversion_ldm_uncond.py
scripts/conversion_ldm_uncond.py
+56
-0
src/diffusers/pipelines/latent_diffusion_uncond/convert_ldm_to_diffusers.py
...lines/latent_diffusion_uncond/convert_ldm_to_diffusers.py
+0
-13
No files found.
scripts/conversion_ldm_uncond.py
0 → 100644
View file @
099d3eab
import
argparse
import
OmegaConf
import
torch
from
diffusers
import
UNetLDMModel
,
VQModel
,
LatentDiffusionUncondPipeline
,
DDIMScheduler
def
convert_ldm_original
(
checkpoint_path
,
config_path
,
output_path
):
config
=
OmegaConf
.
load
(
config_path
)
state_dict
=
torch
.
load
(
checkpoint_path
,
map_location
=
"cpu"
)[
"model"
]
keys
=
list
(
state_dict
.
keys
())
# extract state_dict for VQVAE
first_stage_dict
=
{}
first_stage_key
=
"first_stage_model."
for
key
in
keys
:
if
key
.
startswith
(
first_stage_key
):
first_stage_dict
[
key
.
replace
(
first_stage_key
,
""
)]
=
state_dict
[
key
]
# extract state_dict for UNetLDM
unet_state_dict
=
{}
unet_key
=
"model.diffusion_model."
for
key
in
keys
:
if
key
.
startswith
(
unet_key
):
unet_state_dict
[
key
.
replace
(
unet_key
,
""
)]
=
state_dict
[
key
]
vqvae_init_args
=
config
.
model
.
params
.
first_stage_config
.
params
unet_init_args
=
config
.
model
.
params
.
unet_config
.
params
vqvae
=
VQModel
(
**
vqvae_init_args
).
eval
()
vqvae
.
load_state_dict
(
first_stage_dict
)
unet
=
UNetLDMModel
(
**
unet_init_args
).
eval
()
unet
.
load_state_dict
(
unet_state_dict
)
noise_scheduler
=
DDIMScheduler
(
timesteps
=
config
.
model
.
params
.
timesteps
,
beta_schedule
=
"scaled_linear"
,
beta_start
=
config
.
model
.
params
.
linear_start
,
beta_end
=
config
.
model
.
params
.
linear_end
,
clip_sample
=
False
,
)
pipeline
=
LatentDiffusionUncondPipeline
(
vqvae
,
unet
,
noise_scheduler
)
pipeline
.
save_pretrained
(
output_path
)
if
__name__
==
"__main__"
:
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"--checkpoint_path"
,
type
=
str
,
required
=
True
)
parser
.
add_argument
(
"--config_path"
,
type
=
str
,
required
=
True
)
parser
.
add_argument
(
"--output_path"
,
type
=
str
,
required
=
True
)
args
=
parser
.
parse_args
()
convert_ldm_original
(
args
.
checkpoint_path
,
args
.
config_path
,
args
.
output_path
)
src/diffusers/pipelines/latent_diffusion_uncond/convert_ldm_to_diffusers.py
deleted
100644 → 0
View file @
23904d54
import
argparse
import
torch
from
diffusers
import
UNetLDMModel
,
VQModel
if
__name__
==
"__main__"
:
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"--checkpoint_path"
,
type
=
str
,
required
=
True
)
parser
.
add_argument
(
"--config_path"
,
type
=
str
,
required
=
True
)
parser
.
add_argument
(
"--output_path"
,
type
=
str
,
required
=
True
)
args
=
parser
.
parse_args
()
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