-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SemiAuto] add static branch for shard_tensor #56561
Merged
Merged
Changes from 3 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,9 @@ | |
# limitations under the License. | ||
|
||
import paddle | ||
from paddle.distributed.auto_parallel.interface import ( | ||
shard_tensor as shard_tensor_static, | ||
) | ||
from paddle.distributed.auto_parallel.process_mesh import ProcessMesh | ||
from paddle.framework import core | ||
|
||
|
@@ -55,15 +58,46 @@ def __init__(self, mesh, sharding_specs): | |
for dim_name in sharding_specs | ||
), 'The dimension name in sharding_specs must be an instance of str.' | ||
|
||
self._sharding_specs = sharding_specs | ||
dims_mapping = [ | ||
mesh.dim_names.index(dim_name) if dim_name is not None else -1 | ||
for dim_name in sharding_specs | ||
] | ||
|
||
# 2. init core.TensorDistAttr | ||
core.TensorDistAttr.__init__(self) | ||
self.process_mesh = mesh | ||
self.dims_mapping = dims_mapping | ||
self._process_mesh = mesh | ||
self._dims_mapping = dims_mapping | ||
|
||
@property | ||
def process_mesh(self): | ||
""" | ||
Get process_mesh of the dist_attr | ||
|
||
Returns: | ||
paddle.distributed.ProcessMesh: process_mesh | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 还需要补充下示例吗 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 感觉不加也可以,比较简单的property函数。如果需要,后续我补一下。 |
||
""" | ||
return self._process_mesh | ||
|
||
@property | ||
def dims_mapping(self): | ||
""" | ||
Get dims_mapping of the dist_attr | ||
|
||
Returns: | ||
list[int]: dims_mapping | ||
""" | ||
return self._dims_mapping | ||
|
||
@property | ||
def sharding_specs(self): | ||
""" | ||
Get sharding_specs of the dist_attr | ||
|
||
Returns: | ||
list[str]: sharding_specs | ||
""" | ||
return self._sharding_specs | ||
|
||
|
||
def shard_tensor( | ||
|
@@ -121,6 +155,7 @@ def shard_tensor( | |
if paddle.in_dynamic_mode(): | ||
return paddle.Tensor(data, dist_attr=dist_attr) | ||
else: | ||
raise NotImplementedError( | ||
"The `paddle.distributed.shard_tensor` for static mode will be implemented later." | ||
# TODO(zhiqiu): we need to refine the static shard_tensor | ||
return shard_tensor_static( | ||
data, dist_attr.process_mesh, dist_attr.sharding_specs | ||
) |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the process_mesh field in c++ TensorDistAttr might remain unchanged ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed