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
2629f971
Unverified
Commit
2629f971
authored
May 06, 2023
by
YH
Committed by
GitHub
May 06, 2023
Browse files
[tensor] Refactor handle_trans_spec in DistSpecManager
parent
2da5d81d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
6 deletions
+14
-6
colossalai/tensor/dist_spec_mgr.py
colossalai/tensor/dist_spec_mgr.py
+14
-6
No files found.
colossalai/tensor/dist_spec_mgr.py
View file @
2629f971
...
...
@@ -4,10 +4,8 @@ import torch
import
torch.distributed
as
dist
# from colossalai.nn.layer.utils import divide
from
numpy
import
prod
from
packaging
import
version
from
colossalai.logging
import
get_dist_logger
from
colossalai.tensor.distspec
import
_DistSpec
from
colossalai.tensor.distspec
import
DistPlacementPattern
,
_DistSpec
from
colossalai.tensor.process_group
import
ProcessGroup
...
...
@@ -171,11 +169,21 @@ class DistSpecManager:
pg
:
ProcessGroup
)
->
torch
.
Tensor
:
assert
isinstance
(
old_dist_spec
,
_DistSpec
),
f
"
{
type
(
old_dist_spec
)
}
should be _DistSpec"
assert
isinstance
(
dist_spec
,
_DistSpec
),
f
"
{
type
(
dist_spec
)
}
should be _DistSpec"
forward_trans_handle
=
getattr
(
DistSpecManager
,
f
'_
{
old_dist_spec
.
placement
.
value
}
2
{
dist_spec
.
placement
.
value
}
'
)
trans_func_key
=
(
old_dist_spec
.
placement
,
dist_spec
.
placement
)
trans_funcs
=
{
(
DistPlacementPattern
.
REPLICATE
,
DistPlacementPattern
.
REPLICATE
):
DistSpecManager
.
_r2r
,
(
DistPlacementPattern
.
REPLICATE
,
DistPlacementPattern
.
SHARD
):
DistSpecManager
.
_r2s
,
(
DistPlacementPattern
.
SHARD
,
DistPlacementPattern
.
REPLICATE
):
DistSpecManager
.
_s2r
,
(
DistPlacementPattern
.
SHARD
,
DistPlacementPattern
.
SHARD
):
DistSpecManager
.
_s2s
}
forward_trans_handle
=
trans_funcs
[
trans_func_key
]
if
not
DistSpecManager
.
_use_autograd_function
:
return
forward_trans_handle
(
tensor
,
old_dist_spec
,
dist_spec
,
pg
)
backward_trans_handle
=
getattr
(
DistSpecManager
,
f
'_
{
dist_spec
.
placement
.
value
}
2
{
old_dist_spec
.
placement
.
value
}
'
)
backward_trans_handle
=
trans_funcs
[(
dist_spec
.
placement
,
old_dist_spec
.
placement
)]
return
TransformDistSpec
.
apply
(
tensor
,
old_dist_spec
,
dist_spec
,
pg
,
forward_trans_handle
,
backward_trans_handle
)
...
...
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