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
fa9e35fc
Unverified
Commit
fa9e35fc
authored
May 04, 2023
by
Isamu Isozaki
Committed by
GitHub
May 04, 2023
Browse files
Added input pretubation (#3292)
* Added input pretubation * Fixed spelling
parent
4bae76e4
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
2 deletions
+9
-2
examples/text_to_image/train_text_to_image.py
examples/text_to_image/train_text_to_image.py
+9
-2
No files found.
examples/text_to_image/train_text_to_image.py
View file @
fa9e35fc
...
...
@@ -112,6 +112,9 @@ def log_validation(vae, text_encoder, tokenizer, unet, args, accelerator, weight
def
parse_args
():
parser
=
argparse
.
ArgumentParser
(
description
=
"Simple example of a training script."
)
parser
.
add_argument
(
"--input_pertubation"
,
type
=
float
,
default
=
0
,
help
=
"The scale of input pretubation. Recommended 0.1."
)
parser
.
add_argument
(
"--pretrained_model_name_or_path"
,
type
=
str
,
...
...
@@ -801,7 +804,8 @@ def main():
noise
+=
args
.
noise_offset
*
torch
.
randn
(
(
latents
.
shape
[
0
],
latents
.
shape
[
1
],
1
,
1
),
device
=
latents
.
device
)
if
args
.
input_pertubation
:
new_noise
=
noise
+
args
.
input_pertubation
*
torch
.
randn_like
(
noise
)
bsz
=
latents
.
shape
[
0
]
# Sample a random timestep for each image
timesteps
=
torch
.
randint
(
0
,
noise_scheduler
.
config
.
num_train_timesteps
,
(
bsz
,),
device
=
latents
.
device
)
...
...
@@ -809,6 +813,9 @@ def main():
# Add noise to the latents according to the noise magnitude at each timestep
# (this is the forward diffusion process)
if
args
.
input_pertubation
:
noisy_latents
=
noise_scheduler
.
add_noise
(
latents
,
new_noise
,
timesteps
)
else
:
noisy_latents
=
noise_scheduler
.
add_noise
(
latents
,
noise
,
timesteps
)
# Get the text embedding for conditioning
...
...
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