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
a6e2c1fe
Unverified
Commit
a6e2c1fe
authored
Dec 30, 2022
by
Pedro Cuenca
Committed by
GitHub
Dec 30, 2022
Browse files
Fix ema decay (#1868)
* Fix ema decay and clarify nomenclature. * Rename var.
parent
b28ab302
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
10 deletions
+5
-10
examples/text_to_image/train_text_to_image.py
examples/text_to_image/train_text_to_image.py
+5
-10
No files found.
examples/text_to_image/train_text_to_image.py
View file @
a6e2c1fe
...
...
@@ -278,24 +278,19 @@ class EMAModel:
self
.
decay
=
decay
self
.
optimization_step
=
0
def
get_decay
(
self
,
optimization_step
):
"""
Compute the decay factor for the exponential moving average.
"""
value
=
(
1
+
optimization_step
)
/
(
10
+
optimization_step
)
return
1
-
min
(
self
.
decay
,
value
)
@
torch
.
no_grad
()
def
step
(
self
,
parameters
):
parameters
=
list
(
parameters
)
self
.
optimization_step
+=
1
self
.
decay
=
self
.
get_decay
(
self
.
optimization_step
)
# Compute the decay factor for the exponential moving average.
value
=
(
1
+
self
.
optimization_step
)
/
(
10
+
self
.
optimization_step
)
one_minus_decay
=
1
-
min
(
self
.
decay
,
value
)
for
s_param
,
param
in
zip
(
self
.
shadow_params
,
parameters
):
if
param
.
requires_grad
:
tmp
=
self
.
decay
*
(
s_param
-
param
)
s_param
.
sub_
(
tmp
)
s_param
.
sub_
(
one_minus_decay
*
(
s_param
-
param
))
else
:
s_param
.
copy_
(
param
)
...
...
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