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
f560bd0b
"docs/vscode:/vscode.git/clone" did not exist on "8096c1b5c9775aed3710fbd81d635e06924cc094"
Commit
f560bd0b
authored
May 02, 2020
by
Kexin Yu
Browse files
save a sync when calculating global gradient norm
parent
ac4ef2d6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
4 deletions
+6
-4
apex/optimizers/fused_lamb.py
apex/optimizers/fused_lamb.py
+6
-4
No files found.
apex/optimizers/fused_lamb.py
View file @
f560bd0b
import
torch
import
math
from
apex.multi_tensor_apply
import
multi_tensor_applier
class
FusedLAMB
(
torch
.
optim
.
Optimizer
):
...
...
@@ -123,14 +122,17 @@ class FusedLAMB(torch.optim.Optimizer):
if
len
(
g_all_32
)
>
0
:
g_norm_32
=
multi_tensor_applier
(
self
.
multi_tensor_l2norm
,
self
.
_dummy_overflow_buf
,
[
g_all_32
],
False
)[
0
]
.
item
()
[
g_all_32
],
False
)[
0
]
if
len
(
g_all_16
)
>
0
:
g_norm_16
=
multi_tensor_applier
(
self
.
multi_tensor_l2norm
,
self
.
_dummy_overflow_buf
,
[
g_all_16
],
False
)[
0
]
.
item
()
[
g_all_16
],
False
)[
0
]
# blend two grad norms to get global grad norm
global_grad_norm
=
math
.
sqrt
(
g_norm_32
*
g_norm_32
+
g_norm_16
*
g_norm_16
)
global_grad_norm
=
multi_tensor_applier
(
self
.
multi_tensor_l2norm
,
self
.
_dummy_overflow_buf
,
[[
g_norm_32
,
g_norm_16
]],
False
)[
0
].
item
()
max_grad_norm
=
self
.
defaults
[
'max_grad_norm'
]
for
group
in
self
.
param_groups
:
...
...
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