Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
fairscale
Commits
1a636557
Unverified
Commit
1a636557
authored
Feb 11, 2021
by
Benjamin Lefaudeux
Committed by
GitHub
Feb 11, 2021
Browse files
[minor] ShardGradScaler - only wait for the last handle (#382)
* super minor, opportunistic micro optim
parent
ce9e7e48
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
7 deletions
+8
-7
fairscale/optim/grad_scaler.py
fairscale/optim/grad_scaler.py
+8
-7
No files found.
fairscale/optim/grad_scaler.py
View file @
1a636557
...
...
@@ -49,10 +49,11 @@ class ShardedGradScaler(TorchGradScaler):
# Synchronize the detected inf across the ranks
optimizer_state
=
self
.
_per_optimizer_states
[
id
(
optimizer
)]
handles
=
[
dist
.
all_reduce
(
v
,
async_op
=
True
,
group
=
self
.
group
)
for
v
in
optimizer_state
[
"found_inf_per_device"
].
values
()
]
# Make sure that the calls are done before moving out
_
=
list
(
map
(
lambda
x
:
x
.
wait
(),
handles
))
last_handle
=
None
for
v
in
optimizer_state
[
"found_inf_per_device"
].
values
():
last_handle
=
dist
.
all_reduce
(
v
,
async_op
=
True
,
group
=
self
.
group
)
# Make sure that the calls are done before moving out.
# The calls are executed in sequence, waiting for the last one is enough
if
last_handle
is
not
None
:
last_handle
.
wait
()
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