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
Megatron-LM
Commits
03ba8eb1
Commit
03ba8eb1
authored
Mar 29, 2022
by
Lawrence McAfee
Browse files
commented clip_grads.py.
parent
087cbff1
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
0 deletions
+4
-0
megatron/optimizer/clip_grads.py
megatron/optimizer/clip_grads.py
+4
-0
No files found.
megatron/optimizer/clip_grads.py
View file @
03ba8eb1
...
@@ -38,6 +38,8 @@ def clip_grad_norm_fp32(parameters, grads_for_norm,
...
@@ -38,6 +38,8 @@ def clip_grad_norm_fp32(parameters, grads_for_norm,
Arguments:
Arguments:
parameters (Iterable[Tensor] or Tensor): an iterable of Tensors or a
parameters (Iterable[Tensor] or Tensor): an iterable of Tensors or a
single Tensor that will have gradients normalized
single Tensor that will have gradients normalized
grads_for_norm (Iterable[Tensor]): an iterable of Tensors or a single
Tensor that will be used for calculating the grad norm.
max_norm (float or int): max norm of the gradients
max_norm (float or int): max norm of the gradients
norm_type (float or int): type of the used p-norm. Can be ``'inf'`` for
norm_type (float or int): type of the used p-norm. Can be ``'inf'`` for
infinity norm.
infinity norm.
...
@@ -50,6 +52,8 @@ def clip_grad_norm_fp32(parameters, grads_for_norm,
...
@@ -50,6 +52,8 @@ def clip_grad_norm_fp32(parameters, grads_for_norm,
if
isinstance
(
parameters
,
torch
.
Tensor
):
if
isinstance
(
parameters
,
torch
.
Tensor
):
parameters
=
[
parameters
]
parameters
=
[
parameters
]
if
isinstance
(
grads_for_norm
,
torch
.
Tensor
):
grads_for_norm
=
[
grads_for_norm
]
# Grads.
# Grads.
grads
=
[
p
.
grad
.
detach
()
for
p
in
parameters
if
p
.
grad
is
not
None
]
grads
=
[
p
.
grad
.
detach
()
for
p
in
parameters
if
p
.
grad
is
not
None
]
...
...
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