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
ab946575
Commit
ab946575
authored
Jul 01, 2022
by
patil-suraj
Browse files
add conversion script for BDDMPipeline
parent
a1b5ef5d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
0 deletions
+40
-0
scripts/conversion_bddm.py
scripts/conversion_bddm.py
+40
-0
No files found.
scripts/conversion_bddm.py
0 → 100644
View file @
ab946575
import
argparse
import
torch
from
diffusers.pipelines.bddm
import
DiffWave
,
BDDMPipeline
from
diffusers
import
DDPMScheduler
def
convert_bddm_orginal
(
checkpoint_path
,
noise_scheduler_checkpoint_path
,
output_path
):
sd
=
torch
.
load
(
checkpoint_path
,
map_location
=
"cpu"
)[
"model_state_dict"
]
noise_scheduler_sd
=
torch
.
load
(
noise_scheduler_checkpoint_path
,
map_location
=
"cpu"
)
model
=
DiffWave
()
model
.
load_state_dict
(
sd
,
strict
=
False
)
ts
,
_
,
betas
,
_
=
noise_scheduler_sd
ts
,
betas
=
list
(
ts
.
numpy
().
tolist
()),
list
(
betas
.
numpy
().
tolist
())
noise_scheduler
=
DDPMScheduler
(
timesteps
=
12
,
trained_betas
=
betas
,
timestep_values
=
ts
,
clip_sample
=
False
,
tensor_format
=
"np"
,
)
pipeline
=
BDDMPipeline
(
model
,
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
(
"--noise_scheduler_checkpoint_path"
,
type
=
str
,
required
=
True
)
parser
.
add_argument
(
"--output_path"
,
type
=
str
,
required
=
True
)
args
=
parser
.
parse_args
()
convert_bddm_orginal
(
args
.
checkpoint_path
,
args
.
noise_scheduler_checkpoint_path
,
args
.
output_path
)
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