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
fairscale
Commits
e1f36346
Unverified
Commit
e1f36346
authored
Sep 09, 2021
by
Benjamin Lefaudeux
Committed by
GitHub
Sep 09, 2021
Browse files
capture default device when refreshing the params (#786)
parent
e00dfd95
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
1 deletion
+6
-1
fairscale/optim/oss.py
fairscale/optim/oss.py
+3
-1
tests/optim/test_oss.py
tests/optim/test_oss.py
+3
-0
No files found.
fairscale/optim/oss.py
View file @
e1f36346
...
...
@@ -462,10 +462,12 @@ class OSS(Optimizer):
of some parameters changed.
"""
# Make sure that we capture the current default device
self
.
_default_device
=
list
(
self
.
_per_device_params
.
keys
())[
0
]
# Create the optim which will work on the param shard
if
not
hasattr
(
self
,
"optim"
):
self
.
_clear_cache
()
self
.
_default_device
=
list
(
self
.
_per_device_params
.
keys
())[
0
]
self
.
optim
=
self
.
_optim_constructor
(
self
.
partition_parameters
()[
self
.
rank
],
**
self
.
_optim_defaults
)
OSS
.
_sync_param_groups
(
self
.
optim
.
param_groups
,
self
.
param_groups
)
...
...
tests/optim/test_oss.py
View file @
e1f36346
...
...
@@ -151,6 +151,9 @@ class TestSingleRank(unittest.TestCase):
# Check that OSS detects that the device changed
o
.
step
()
# Check that the default device has been updated
assert
o
.
_default_device
.
type
==
DEVICE
def
test_step_with_extra_inner_key
(
self
):
class
SGDWithNewKey
(
torch
.
optim
.
SGD
):
# Dummy optimizer which adds a new key to the 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