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
b0c3fe1e
Unverified
Commit
b0c3fe1e
authored
Jul 25, 2022
by
Min Xu
Committed by
GitHub
Jul 25, 2022
Browse files
[minor] add a checking around local_state_dict (#1040)
Co-authored-by:
Min Xu
<
min.xu.public@gmail.com
>
parent
16fba4c0
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
0 deletions
+10
-0
fairscale/nn/data_parallel/fully_sharded_data_parallel.py
fairscale/nn/data_parallel/fully_sharded_data_parallel.py
+10
-0
No files found.
fairscale/nn/data_parallel/fully_sharded_data_parallel.py
View file @
b0c3fe1e
...
...
@@ -962,6 +962,11 @@ class FullyShardedDataParallel(nn.Module):
so the resulting state_dict can only be loaded after the Module has been
wrapped with FSDP.
"""
# Check state, specifically, we shouldn't be in SUMMON_FULL_PARAMS since
# that will produce full state, not sharded state.
self
.
assert_state
(
[
TrainingState
.
IDLE
,
TrainingState
.
FORWARD
,
TrainingState
.
BACKWARD_PRE
,
TrainingState
.
BACKWARD_POST
]
)
with
contextlib
.
ExitStack
()
as
stack
:
# Tell any nested FSDP instances not to auto summon full params.
for
module
in
self
.
modules
():
# includes self
...
...
@@ -1025,6 +1030,11 @@ class FullyShardedDataParallel(nn.Module):
self
,
state_dict
:
Union
[
Dict
[
str
,
torch
.
Tensor
],
"OrderedDict[str, torch.Tensor]"
],
strict
:
bool
=
True
)
->
NamedTuple
:
"""Load a local (sharded) state_dict."""
# Check state, specifically, we shouldn't be in SUMMON_FULL_PARAMS since
# that will load full state, not sharded state.
self
.
assert_state
(
[
TrainingState
.
IDLE
,
TrainingState
.
FORWARD
,
TrainingState
.
BACKWARD_PRE
,
TrainingState
.
BACKWARD_POST
]
)
with
contextlib
.
ExitStack
()
as
stack
:
# Tell any nested FSDP instances not to auto summon full params.
for
module
in
self
.
modules
():
# includes self
...
...
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