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
b0b8ad28
Commit
b0b8ad28
authored
Jul 05, 2023
by
ver217
Committed by
Hongxin Liu
Aug 15, 2023
Browse files
[pipeline] update shardformer docstring
parent
59f6f573
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
2 deletions
+7
-2
colossalai/shardformer/shard/shardformer.py
colossalai/shardformer/shard/shardformer.py
+7
-2
No files found.
colossalai/shardformer/shard/shardformer.py
View file @
b0b8ad28
from
typing
import
Dict
,
List
,
Tuple
import
torch.nn
as
nn
from
torch
import
Tensor
from
colossalai.cluster
import
DistCoordinator
...
...
@@ -24,7 +27,7 @@ class ShardFormer:
org_model = BertForMaskedLM.from_pretrained('bert-base-uncased')
shard_config = ShardConfig()
shard_former = ShardFormer(shard_config=shard_config)
model = shard_former.optimize(org_model)
model
, shared_params
= shard_former.optimize(org_model)
```
"""
...
...
@@ -32,7 +35,7 @@ class ShardFormer:
self
.
coordinator
=
DistCoordinator
()
self
.
shard_config
=
shard_config
def
optimize
(
self
,
model
:
nn
.
Module
,
policy
:
Policy
=
None
):
def
optimize
(
self
,
model
:
nn
.
Module
,
policy
:
Policy
=
None
)
->
Tuple
[
nn
.
Module
,
List
[
Dict
[
int
,
Tensor
]]]
:
r
"""
This method will optimize the model based on the given policy.
...
...
@@ -40,6 +43,8 @@ class ShardFormer:
model (`torch.nn.Model`): the origin huggingface model
shard_config (`ShardConfig`): the config for distribute information
policy (`Policy`): the custom policy for sharding
Returns: the sharded model and the shared parameters
"""
sharder
=
ModelSharder
(
model
=
model
,
shard_config
=
self
.
shard_config
,
policy
=
policy
)
shared_params
=
sharder
.
shard
()
...
...
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