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
OpenDAS
diffusers
Commits
e0d8c9ef
Unverified
Commit
e0d8c9ef
authored
Mar 23, 2023
by
Haofan Wang
Committed by
GitHub
Mar 23, 2023
Browse files
Support for Offset Noise in examples (#2753)
* add noise offset * make style
parent
92e1164e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
0 deletions
+14
-0
examples/text_to_image/train_text_to_image.py
examples/text_to_image/train_text_to_image.py
+7
-0
examples/text_to_image/train_text_to_image_lora.py
examples/text_to_image/train_text_to_image_lora.py
+7
-0
No files found.
examples/text_to_image/train_text_to_image.py
View file @
e0d8c9ef
...
@@ -297,6 +297,7 @@ def parse_args():
...
@@ -297,6 +297,7 @@ def parse_args():
parser
.
add_argument
(
parser
.
add_argument
(
"--enable_xformers_memory_efficient_attention"
,
action
=
"store_true"
,
help
=
"Whether or not to use xformers."
"--enable_xformers_memory_efficient_attention"
,
action
=
"store_true"
,
help
=
"Whether or not to use xformers."
)
)
parser
.
add_argument
(
"--noise_offset"
,
type
=
float
,
default
=
0
,
help
=
"The scale of noise offset."
)
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
env_local_rank
=
int
(
os
.
environ
.
get
(
"LOCAL_RANK"
,
-
1
))
env_local_rank
=
int
(
os
.
environ
.
get
(
"LOCAL_RANK"
,
-
1
))
...
@@ -705,6 +706,12 @@ def main():
...
@@ -705,6 +706,12 @@ def main():
# Sample noise that we'll add to the latents
# Sample noise that we'll add to the latents
noise
=
torch
.
randn_like
(
latents
)
noise
=
torch
.
randn_like
(
latents
)
if
args
.
noise_offset
:
# https://www.crosslabs.org//blog/diffusion-with-offset-noise
noise
+=
args
.
noise_offset
*
torch
.
randn
(
(
latents
.
shape
[
0
],
latents
.
shape
[
1
],
1
,
1
),
device
=
latents
.
device
)
bsz
=
latents
.
shape
[
0
]
bsz
=
latents
.
shape
[
0
]
# Sample a random timestep for each image
# Sample a random timestep for each image
timesteps
=
torch
.
randint
(
0
,
noise_scheduler
.
num_train_timesteps
,
(
bsz
,),
device
=
latents
.
device
)
timesteps
=
torch
.
randint
(
0
,
noise_scheduler
.
num_train_timesteps
,
(
bsz
,),
device
=
latents
.
device
)
...
...
examples/text_to_image/train_text_to_image_lora.py
View file @
e0d8c9ef
...
@@ -333,6 +333,7 @@ def parse_args():
...
@@ -333,6 +333,7 @@ def parse_args():
parser
.
add_argument
(
parser
.
add_argument
(
"--enable_xformers_memory_efficient_attention"
,
action
=
"store_true"
,
help
=
"Whether or not to use xformers."
"--enable_xformers_memory_efficient_attention"
,
action
=
"store_true"
,
help
=
"Whether or not to use xformers."
)
)
parser
.
add_argument
(
"--noise_offset"
,
type
=
float
,
default
=
0
,
help
=
"The scale of noise offset."
)
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
env_local_rank
=
int
(
os
.
environ
.
get
(
"LOCAL_RANK"
,
-
1
))
env_local_rank
=
int
(
os
.
environ
.
get
(
"LOCAL_RANK"
,
-
1
))
...
@@ -718,6 +719,12 @@ def main():
...
@@ -718,6 +719,12 @@ def main():
# Sample noise that we'll add to the latents
# Sample noise that we'll add to the latents
noise
=
torch
.
randn_like
(
latents
)
noise
=
torch
.
randn_like
(
latents
)
if
args
.
noise_offset
:
# https://www.crosslabs.org//blog/diffusion-with-offset-noise
noise
+=
args
.
noise_offset
*
torch
.
randn
(
(
latents
.
shape
[
0
],
latents
.
shape
[
1
],
1
,
1
),
device
=
latents
.
device
)
bsz
=
latents
.
shape
[
0
]
bsz
=
latents
.
shape
[
0
]
# Sample a random timestep for each image
# Sample a random timestep for each image
timesteps
=
torch
.
randint
(
0
,
noise_scheduler
.
num_train_timesteps
,
(
bsz
,),
device
=
latents
.
device
)
timesteps
=
torch
.
randint
(
0
,
noise_scheduler
.
num_train_timesteps
,
(
bsz
,),
device
=
latents
.
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