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
57437cb1
Commit
57437cb1
authored
Mar 04, 2021
by
Rewon Child
Browse files
Fix syntax
parent
0aff3629
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
8 deletions
+3
-8
megatron/optimizer/clip_grads.py
megatron/optimizer/clip_grads.py
+3
-8
No files found.
megatron/optimizer/clip_grads.py
View file @
57437cb1
...
@@ -129,20 +129,15 @@ def count_zeros_fp32(parameters):
...
@@ -129,20 +129,15 @@ def count_zeros_fp32(parameters):
# - grad should not be none
# - grad should not be none
# - parameter should not be shared
# - parameter should not be shared
# - should not be a replica due to tensor model parallelism
# - should not be a replica due to tensor model parallelism
grads_to_count
=
[]
total_num_zeros
=
0.0
for
param
in
parameters
:
for
param
in
parameters
:
grad_not_none
=
param
.
grad
is
not
None
grad_not_none
=
param
.
grad
is
not
None
is_not_shared
=
param_is_not_shared
(
param
)
is_not_shared
=
param_is_not_shared
(
param
)
is_not_tp_duplicate
=
param_is_not_tensor_parallel_duplicate
(
param
)
is_not_tp_duplicate
=
param_is_not_tensor_parallel_duplicate
(
param
)
if
grad_not_none
and
is_not_shared
and
is_not_tp_duplicate
:
if
grad_not_none
and
is_not_shared
and
is_not_tp_duplicate
:
grad
=
param
.
grad
.
detach
()
grad
=
param
.
grad
.
detach
()
grads_to_count
.
append
(
grad
)
num_zeros
=
grad
.
numel
()
-
torch
.
count_nonzero
(
grad
)
total_num_zeros
=
num_zeros
+
total_num_zeros
total_num_zeros
=
0.0
for
grad
in
grads_to_count
:
num_zeros
=
grad
.
numel
()
-
torch
.
count_nonzero
(
grad
)
total_num_zeros
=
num_zeros
+
total_num_zeros
# Sum across all model-parallel GPUs.
# Sum across all model-parallel GPUs.
torch
.
distributed
.
all_reduce
(
total_num_zeros
,
torch
.
distributed
.
all_reduce
(
total_num_zeros
,
...
...
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