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
ColossalAI
Commits
7a053671
Unverified
Commit
7a053671
authored
Jul 15, 2022
by
ver217
Committed by
GitHub
Jul 15, 2022
Browse files
[hotfix] shared model returns cpu state_dict (#1328)
parent
b2475d8c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
3 additions
and
2 deletions
+3
-2
colossalai/zero/sharded_model/sharded_model_v2.py
colossalai/zero/sharded_model/sharded_model_v2.py
+2
-1
tests/test_zero/test_state_dict.py
tests/test_zero/test_state_dict.py
+1
-1
No files found.
colossalai/zero/sharded_model/sharded_model_v2.py
View file @
7a053671
...
...
@@ -439,7 +439,8 @@ class ShardedModelV2(nn.Module):
for
p
in
sharded_params
:
p
.
data
=
p
.
colo_attr
.
data_payload
module_to_load
=
module_to_load
or
self
gathered_state_dict
=
deepcopy
(
state_dict_func
(
module_to_load
,
destination
,
prefix
,
keep_vars
))
gathered_state_dict
=
state_dict_func
(
module_to_load
,
destination
,
prefix
,
keep_vars
)
gathered_state_dict
=
{
k
:
v
.
cpu
()
if
isinstance
(
v
,
torch
.
Tensor
)
else
v
for
k
,
v
in
gathered_state_dict
.
items
()}
if
shard_strategy
is
not
None
:
shard_strategy
.
shard
([
p
.
colo_attr
.
sharded_data_tensor
for
p
in
sharded_params
],
process_group
)
for
p
in
sharded_params
:
...
...
tests/test_zero/test_state_dict.py
View file @
7a053671
...
...
@@ -39,7 +39,7 @@ def run_zero_state_dict(shard_strategy_class):
zero_state_dict
=
zero_model
.
state_dict
()
for
key
,
val
in
model
.
state_dict
().
items
():
assert
torch
.
equal
(
val
,
zero_state_dict
[
key
])
assert
torch
.
equal
(
val
,
zero_state_dict
[
key
]
.
to
(
val
.
device
)
)
def
run_dist
(
rank
,
world_size
,
port
):
...
...
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