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
345f5d0d
"...text-generation-inference.git" did not exist on "cef0553d59713a5e5842b9a1d79334d4ffc066b9"
Commit
345f5d0d
authored
Dec 29, 2020
by
mohammad
Browse files
moved grad scaling to multi-tensor-apply
parent
e68ea218
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
5 deletions
+8
-5
megatron/optimizer/optimizer.py
megatron/optimizer/optimizer.py
+8
-5
No files found.
megatron/optimizer/optimizer.py
View file @
345f5d0d
...
@@ -107,13 +107,16 @@ def _clip_grad_norm(parameters, max_norm, norm_type=2):
...
@@ -107,13 +107,16 @@ def _clip_grad_norm(parameters, max_norm, norm_type=2):
torch
.
distributed
.
all_reduce
(
total_norm_cuda
,
torch
.
distributed
.
all_reduce
(
total_norm_cuda
,
op
=
torch
.
distributed
.
ReduceOp
.
SUM
,
op
=
torch
.
distributed
.
ReduceOp
.
SUM
,
group
=
mpu
.
get_model_parallel_group
())
group
=
mpu
.
get_model_parallel_group
())
total_norm
=
total_norm_cuda
[
0
].
item
()
**
(
1.
/
norm_type
)
total_norm
=
total_norm_cuda
[
0
].
item
()
**
(
1.
0
/
norm_type
)
# Scale.
# Scale.
clip_coef
=
max_norm
/
(
total_norm
+
1.0e-6
)
clip_coeff
=
max_norm
/
(
total_norm
+
1.0e-6
)
if
clip_coef
<
1.0
:
if
clip_coeff
<
1.0
:
for
grad
in
grads
:
dummy_overflow_buf
=
torch
.
cuda
.
IntTensor
([
0
])
grad
.
mul_
(
clip_coef
)
multi_tensor_applier
(
amp_C
.
multi_tensor_scale
,
dummy_overflow_buf
,
[
grads
,
grads
],
clip_coeff
)
return
total_norm
return
total_norm
...
...
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