-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AutoParallel] adapt for gpt-gen (#46771)
* for gpt-gen * fix reshard * adapt assign and shape op * add dist_assign & unittest * add conditional block unittest * rename unittest
- Loading branch information
1 parent
eee6b3a
commit 31a437b
Showing
11 changed files
with
458 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
python/paddle/distributed/auto_parallel/operators/dist_assign.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from .common import DistributedOperatorImplContainer | ||
from .common import DistributedOperatorImpl | ||
from .common import register_distributed_operator_impl_container | ||
from .common import register_distributed_operator_impl | ||
from .dist_default import DistributedDefaultImpl0 | ||
from ..utils import compute_compatible_and_update_dim_mapping | ||
|
||
|
||
class DistributedAssign(DistributedOperatorImplContainer): | ||
|
||
def __init__(self, op_type): | ||
super(DistributedAssign, self).__init__(op_type) | ||
|
||
|
||
register_distributed_operator_impl_container(DistributedAssign("assign")) | ||
|
||
|
||
class DistributedAssignImpl(DistributedOperatorImpl): | ||
|
||
def __init__(self, name): | ||
super(DistributedAssignImpl, self).__init__(name) | ||
self._forward_implemented = True | ||
self._backward_implemented = True | ||
|
||
def is_input_compatible(self, dist_op): | ||
return True | ||
|
||
def is_output_compatible(self, dist_op): | ||
return True | ||
|
||
def is_auto_compatible(self, dist_op): | ||
if (not self.is_input_compatible(dist_op)) or \ | ||
(not self.is_output_compatible(dist_op)): | ||
return False | ||
|
||
op_desc = dist_op.serial_op.desc | ||
op_dist_attr = dist_op.dist_attr | ||
x_name = op_desc.input('X')[0] | ||
out_name = op_desc.output('Out')[0] | ||
x_dims_mapping = op_dist_attr.get_input_dims_mapping(x_name) | ||
out_dims_mapping = op_dist_attr.get_output_dims_mapping(out_name) | ||
|
||
if x_dims_mapping != out_dims_mapping: | ||
return False | ||
|
||
return True | ||
|
||
def update_dims_mapping(self, dist_op): | ||
changed = False | ||
op_desc = dist_op.serial_op.desc | ||
op_dist_attr = dist_op.dist_attr | ||
x_name = op_desc.input('X')[0] | ||
out_name = op_desc.output('Out')[0] | ||
x_dims_mapping = op_dist_attr.get_input_dims_mapping(x_name) | ||
out_dims_mapping = op_dist_attr.get_output_dims_mapping(out_name) | ||
|
||
for i in range(len(x_dims_mapping)): | ||
dim_changed = compute_compatible_and_update_dim_mapping( | ||
[x_dims_mapping, out_dims_mapping], [i, i]) | ||
if dim_changed: | ||
changed = True | ||
|
||
return changed | ||
|
||
@staticmethod | ||
def forward(ctx, *args, **kwargs): | ||
DistributedDefaultImpl0.forward(ctx, *args, **kwargs) | ||
|
||
@staticmethod | ||
def backward(ctx, *args, **kwargs): | ||
DistributedDefaultImpl0.backward(ctx, *args, **kwargs) | ||
|
||
|
||
register_distributed_operator_impl("assign", DistributedAssignImpl("assign")) |
73 changes: 73 additions & 0 deletions
73
python/paddle/distributed/auto_parallel/operators/dist_shape.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from .common import DistributedOperatorImplContainer | ||
from .common import DistributedOperatorImpl | ||
from .common import register_distributed_operator_impl_container | ||
from .common import register_distributed_operator_impl | ||
from .dist_default import DistributedDefaultImpl0 | ||
from ..utils import is_dim_shard | ||
|
||
|
||
class DistributedShape(DistributedOperatorImplContainer): | ||
|
||
def __init__(self, op_type): | ||
super(DistributedShape, self).__init__(op_type) | ||
|
||
|
||
register_distributed_operator_impl_container(DistributedShape("shape")) | ||
|
||
|
||
class DistributedShapeImpl(DistributedOperatorImpl): | ||
|
||
def __init__(self, name): | ||
super(DistributedShapeImpl, self).__init__(name) | ||
self._forward_implemented = True | ||
self._backward_implemented = True | ||
|
||
def is_input_compatible(self, dist_op): | ||
return True | ||
|
||
def is_output_compatible(self, dist_op): | ||
op_desc = dist_op.serial_op.desc | ||
op_dist_attr = dist_op.dist_attr | ||
out_name = op_desc.output('Out')[0] | ||
out_dims_mapping = op_dist_attr.get_output_dims_mapping(out_name) | ||
|
||
assert len(out_dims_mapping) == 1 | ||
if is_dim_shard(out_dims_mapping[0]): | ||
return False | ||
|
||
return True | ||
|
||
def is_auto_compatible(self, dist_op): | ||
if (not self.is_input_compatible(dist_op)) or \ | ||
(not self.is_output_compatible(dist_op)): | ||
return False | ||
|
||
return True | ||
|
||
def update_dims_mapping(self, dist_op): | ||
return False | ||
|
||
@staticmethod | ||
def forward(ctx, *args, **kwargs): | ||
DistributedDefaultImpl0.forward(ctx, *args, **kwargs) | ||
|
||
@staticmethod | ||
def backward(ctx, *args, **kwargs): | ||
DistributedDefaultImpl0.backward(ctx, *args, **kwargs) | ||
|
||
|
||
register_distributed_operator_impl("shape", DistributedShapeImpl("shape")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.