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
272ebfb5
Commit
272ebfb5
authored
Mar 10, 2022
by
Jiarui Fang
Committed by
Frank Lee
Mar 11, 2022
Browse files
[bug] shard param during initializing the ShardedModelV2 (#381)
parent
8c18eb09
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
3 additions
and
2 deletions
+3
-2
colossalai/zero/init_ctx/init_context.py
colossalai/zero/init_ctx/init_context.py
+1
-1
colossalai/zero/sharded_model/sharded_model_v2.py
colossalai/zero/sharded_model/sharded_model_v2.py
+2
-1
No files found.
colossalai/zero/init_ctx/init_context.py
View file @
272ebfb5
...
...
@@ -139,7 +139,7 @@ class ZeroInitContext(InsertPostInitMethodToModuleSubClasses):
if
self
.
convert_fp16
:
param
.
data
=
param
.
data
.
to
(
torch
.
half
)
if
param
.
grad
is
not
None
:
param
.
grad
=
param
.
grad
.
to
(
torch
.
half
)
.
to
(
target_device
)
param
.
grad
=
param
.
grad
.
to
(
torch
.
half
)
# move torch parameters to the target device
param
.
data
=
param
.
data
.
to
(
target_device
)
...
...
colossalai/zero/sharded_model/sharded_model_v2.py
View file @
272ebfb5
from
ast
import
Try
import
functools
from
collections
import
OrderedDict
from
typing
import
Any
,
Optional
...
...
@@ -54,7 +55,7 @@ class ShardedModelV2(nn.Module):
# In case user didn't use ZeroInitContext
for
param
in
self
.
module
.
parameters
():
if
not
hasattr
(
param
,
'col_attr'
):
param
.
col_attr
=
ShardedParamV2
(
param
,
process_group
)
param
.
col_attr
=
ShardedParamV2
(
param
,
process_group
,
rm_torch_payload
=
True
)
if
self
.
shard_param
:
self
.
shard_strategy
.
shard
([
param
.
col_attr
.
data
])
...
...
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