Skip to content
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

[AutoParallel] Support disttensor for Tensor.copy_ #58369

Merged

Conversation

wanghuancoder
Copy link
Contributor

@wanghuancoder wanghuancoder commented Oct 25, 2023

PR types

Others

PR changes

Others

Description

Tensor.copy_是典型的PHI api逻辑,会传入DistTensor。需要补充DistTensor分支。
PCard-70444

@paddle-bot
Copy link

paddle-bot bot commented Oct 25, 2023

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot
Copy link

paddle-bot bot commented Oct 25, 2023

❌ The PR is not created using PR's template. You can refer to this Demo.
Please use PR's template, it helps save our maintainers' time so that more developers get helped.

@wanghuancoder wanghuancoder changed the title Support disttensor copy [AutoParallel] Support disttensor for Tensor.copy_ Oct 25, 2023
@@ -128,6 +136,60 @@ void Tensor::copy_(const Tensor &src,
auto *dev_ctx = pool.GetMutable(
place.GetType() == target_place.GetType() ? target_place : place);

#ifdef PADDLE_WITH_DISTRIBUTE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auto parallel可以放在DenseTensor kernel的分支,是DenseTensor Kernel的一个扩展机制

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, thx!


// 1. InferSpmd (Infer DistAttr of Inputs&Outputs)
auto meta_dist_input_x = MakeDistMetaTensor(*src.impl());
auto spmd_info = phi::distributed::ElementwiseUnaryInferSpmd(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里咱们是不是直接创建一个输出,把输入的设置上去就行,不用走InferSpmd,这个elementwise的逻辑还挺多的

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里不会出现:这个Tensor不需要在这个卡上计算的情况吗?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

哦,我理解错了

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, thx!

// 4. Select Kernel

// 5. Reshard Input
auto dist_input_x = ReshardApiInputToKernelInput(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好像也不需要reshard,原先的值给输出copy过去就行

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, thx!

phi::Copy(*dev_ctx, *input_x, target_place, blocking, dense_out);

// 9. Reshard Partial Output to Replicated (Temporary)
ReshardOutputPartialAxisToReplicated(dev_ctx, dist_out);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里也可以省略

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, thx!

@paddle-bot paddle-bot bot added the contributor External developers label Oct 25, 2023
Copy link
Contributor

@LiYuRio LiYuRio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

phi::UnchangedInferMeta(MakeMetaTensor(*(src.impl_)), &meta_dist_out);

if (rank_is_in_current_mesh) {
// 4. Select Kernel
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的注释感觉和代码对不上,是不是可以删一删

// API `copy_` does not need to set DistAttr for output.
return;
}
#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的条件宏是不是没必要呀

@wanghuancoder wanghuancoder merged commit 61af39b into PaddlePaddle:develop Oct 26, 2023
28 checks passed
@paddle-bot paddle-bot bot removed the contributor External developers label Nov 3, 2023
danleifeng pushed a commit to danleifeng/Paddle that referenced this pull request Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants