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
apex
Commits
99495376
Commit
99495376
authored
Mar 06, 2019
by
Deyu Fu
Browse files
make norm compatible with pytorch version <= 1.0.1
parent
94667417
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
1 deletion
+5
-1
apex/optimizers/fp16_optimizer.py
apex/optimizers/fp16_optimizer.py
+5
-1
No files found.
apex/optimizers/fp16_optimizer.py
View file @
99495376
...
...
@@ -116,7 +116,11 @@ class FP16_Optimizer(object):
"""
# TODO: Not most efficient with copy to cpu and sync
# only support 2-norm now
norm
=
float
(
torch
.
norm
(
fp16_grads_flat
,
2.0
,
dtype
=
torch
.
float32
))
# for torch version <= 1.0.1, torch.norm with dtype will fail and fall back to cast
try
:
norm
=
float
(
torch
.
norm
(
fp16_grads_flat
,
2.0
,
dtype
=
torch
.
float32
))
except
TypeError
as
err
:
norm
=
float
(
torch
.
norm
(
fp16_grads_flat
.
float
(),
2.0
))
if
norm
==
float
(
'inf'
)
or
norm
==
-
float
(
'inf'
)
or
norm
!=
norm
:
return
-
1
else
:
...
...
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