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

[Semi Auto] Refactor Replicated Rule #56839

Merged
merged 19 commits into from
Sep 12, 2023

Conversation

JZ-LIANG
Copy link
Contributor

@JZ-LIANG JZ-LIANG commented Aug 31, 2023

PR types

Function optimization

PR changes

Others

Description

Pcard-70448

  • default_data_parallel rule : hack rule for support hybrid parallel quickly, should be mapped to a specific op on purpose.
  • replicated rule: bottom line rule for all ops that have NO specific rule.
  • Adapt Api for PHI format in dygraph.
  • Adapt Api to distinguish argument of single tensor and argument of vector of single tensor in static graph.

@paddle-bot
Copy link

paddle-bot bot commented Aug 31, 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 Aug 31, 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.

chenwhql
chenwhql previously approved these changes Sep 7, 2023
Copy link
Contributor

@chenwhql chenwhql left a comment

Choose a reason for hiding this comment

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

LGTM overall

@@ -375,6 +376,44 @@ void BindAutoParallel(py::module *m) {
}
return self.InferForward(ctx);
})
.def("infer_forward", /*for op that have vector argument*/
[](const phi::distributed::SpmdRule &self,
const std::vector<std::pair<int, int>> input_ranges,
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.

修改了

paddle::small_vector<phi::distributed::DistMetaTensor,
phi::kInputSmallVectorSize>
ins;
for (auto range : input_ranges) {
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.

修改了, THX~

* all the input and ouput tensors is the batch dimension (broadcast dimension),
* therefore, if any tensor's first dimension is sharded, the sharding would be
* propagating to all the other tensors (for tensor first dimension). All the
*other axes of tensors would be set as unshard (-1).
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


#include "paddle/phi/core/distributed/auto_parallel/dist_meta_tensor.h"
#include "paddle/phi/core/distributed/type_defs.h"
#include "paddle/phi/infermeta/spmd_rules/utils.h"
Copy link
Contributor

@chenwhql chenwhql Sep 7, 2023

Choose a reason for hiding this comment

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

utils.h是不是在.cc中include就可以了

Copy link
Contributor Author

@JZ-LIANG JZ-LIANG Sep 7, 2023

Choose a reason for hiding this comment

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

不太行。因为下面phi 接口方法的定义中,需要把 helper template 实例化,所以必须include helper template 的实现,无法通过 forward declaration 引入 helper。

const std::vector<phi::Attribute> &attrs) {
/*
to distingish between single tensor argument and vector argument of
one tensor: start - end == 0: single tensor start - end == 1:
Copy link
Contributor

Choose a reason for hiding this comment

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

Commonly, the range is [start, end), i.e., start is inclusive and end is exclusive. Maybe wo need another way to distingish between tensor and [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.

Yes,we plan to use PyObject* to deal with variadic arguments Python end and parser them in C++ end in Next PR

Comment on lines 21 to 22
inputs_.emplace_back(std::move(input));
int index = static_cast<int>(inputs_.size());
Copy link
Contributor

Choose a reason for hiding this comment

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

exchange line 21 and 22 to get right index?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed, it is a bug, thx~

Copy link
Contributor

@zhiqiu zhiqiu left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@risemeup1 risemeup1 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@XiaoguangHu01 XiaoguangHu01 left a comment

Choose a reason for hiding this comment

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

LGTM

@JZ-LIANG JZ-LIANG merged commit 29900a0 into PaddlePaddle:develop Sep 12, 2023
danleifeng pushed a commit to danleifeng/Paddle that referenced this pull request Nov 14, 2023
* adapt general spmd rule

* polish details

* add new rules

* bugfix for set_partial

* bugfix

* unitest

* adapt for argument for tensor and vector of tensor

---------

Co-authored-by: Chen Weihang <chenweihang@baidu.com>
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.

5 participants