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
Fairseq
Commits
08a74a32
Commit
08a74a32
authored
Jan 09, 2018
by
Myle Ott
Browse files
Fix gradient clipping when --clip-norm=0
parent
fd28c880
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
1 deletion
+4
-1
fairseq/multiprocessing_trainer.py
fairseq/multiprocessing_trainer.py
+4
-1
No files found.
fairseq/multiprocessing_trainer.py
View file @
08a74a32
...
@@ -265,7 +265,10 @@ class MultiprocessingTrainer(MultiprocessingEventLoop):
...
@@ -265,7 +265,10 @@ class MultiprocessingTrainer(MultiprocessingEventLoop):
self
.
_all_reduce_and_rescale_grads
(
grad_denom
)
self
.
_all_reduce_and_rescale_grads
(
grad_denom
)
# clip grads
# clip grads
grad_norm
=
torch
.
nn
.
utils
.
clip_grad_norm
(
self
.
model
.
parameters
(),
self
.
args
.
clip_norm
)
if
self
.
args
.
clip_norm
>
0
:
grad_norm
=
torch
.
nn
.
utils
.
clip_grad_norm
(
self
.
model
.
parameters
(),
self
.
args
.
clip_norm
)
else
:
grad_norm
=
math
.
sqrt
(
sum
([
p
.
grad
.
data
.
norm
()
**
2
for
p
in
self
.
model
.
parameters
()]))
# take an optimization step
# take an optimization step
self
.
optimizer
.
step
()
self
.
optimizer
.
step
()
...
...
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