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
3092317b
Commit
3092317b
authored
Mar 04, 2022
by
ver217
Committed by
Frank Lee
Mar 11, 2022
Browse files
polish code
parent
36f9a74a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
3 deletions
+3
-3
colossalai/zero/sharded_optim/sharded_optim_v2.py
colossalai/zero/sharded_optim/sharded_optim_v2.py
+3
-3
No files found.
colossalai/zero/sharded_optim/sharded_optim_v2.py
View file @
3092317b
...
...
@@ -25,7 +25,7 @@ class OptimState(Enum):
class
ShardedOptimizerV2
(
ColossalaiOptimizer
):
def
__init__
(
self
,
adam_
optim
:
Optimizer
,
optim
izer
:
Optimizer
,
sharded_model
:
Union
[
nn
.
Module
,
ShardedModelV2
],
cpu_offload
:
bool
=
False
,
initial_scale
:
float
=
2
**
32
,
...
...
@@ -37,7 +37,7 @@ class ShardedOptimizerV2(ColossalaiOptimizer):
max_scale
:
int
=
2
**
32
,
dp_process_group
:
Optional
[
ProcessGroup
]
=
None
,
mp_process_group
:
Optional
[
ProcessGroup
]
=
None
)
->
None
:
super
().
__init__
(
adam_
optim
)
super
().
__init__
(
optim
izer
)
self
.
model
:
Union
[
nn
.
Module
,
ShardedModelV2
]
=
sharded_model
self
.
model_is_sharded
=
isinstance
(
sharded_model
,
ShardedModelV2
)
self
.
device
=
torch
.
cuda
.
current_device
()
if
not
cpu_offload
else
torch
.
device
(
'cpu'
)
...
...
@@ -57,7 +57,7 @@ class ShardedOptimizerV2(ColossalaiOptimizer):
# Store fp32 params
self
.
master_params
:
Dict
[
Parameter
,
Tensor
]
=
{}
for
group
in
adam_
optim
.
param_groups
:
for
group
in
optim
izer
.
param_groups
:
for
p
in
group
[
'params'
]:
if
hasattr
(
p
,
'ca_attr'
):
assert
p
.
ca_attr
.
is_sharded
,
'ShardedAdam can be only used with sharded model'
...
...
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