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 operators have mixed inputs. #57774

Merged

Conversation

GhostScreaming
Copy link
Contributor

@GhostScreaming GhostScreaming commented Sep 26, 2023

PR types

Others

PR changes

Others

Description

Pcard-73145

Support operators have mixed inputs like DenseTensor and DistTensor. DenseTensor will be sharded to replicate DistTensor automatically.

Former implementation is deployed in phi APIs: PR 57684. However, inputs are all const reference, which means converting input DenseTensor to DistTensor is an unsafe operation. Meanwhile, there is modification of inputs in AutoGrad level like convert them to continuous Tensors. As a result, modification of phi input like x_tmp in AutoGrad level will not change the real input x, but backward node relies on the real input x information as Tensor metas. It's more properly to implement this sharding strategy in Python-C level.

@paddle-bot
Copy link

paddle-bot bot commented Sep 26, 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.

local_t_2 = paddle.to_tensor(np_array, dtype='float16')
elif np_array.dtype == np.int32:
local_t_1 = paddle.to_tensor(np_array, dtype='int32')
# local_t_2 = paddle.to_tensor(np_array, dtype='float16')
Copy link
Contributor

Choose a reason for hiding this comment

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

这里要新增一个int32的local值吗

Copy link
Contributor Author

Choose a reason for hiding this comment

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

注释忘记删除了,已经恢复

x = np.random.random(size=[4, 4]).astype("float32")
y = np.random.random(size=[4, 4]).astype("float32")
local_x, dist_x = self.create_local_and_dist_tensor_pair(x)
local_y, dist_y = self.create_two_local_tensor_pair(y)
Copy link
Contributor

Choose a reason for hiding this comment

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

local_y, dist_y -> local_y1, local_y2?

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.

@@ -72,6 +72,13 @@ def FindParsingFunctionFromAttributeType(atype):
" auto {} = {}(\"{}\", \"{}\", args, {}, {});\n"
)

CONVERT_INPUT_TENSORS_TO_DIST_TENSOR_TEMPLATE = """
const phi::distributed::ProcessMesh* mesh = nullptr;
auto mesh_ptr = &mesh;
Copy link
Contributor

Choose a reason for hiding this comment

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

这里是不是直接传入&mesh参数即可,不用新增一行赋值

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.

@@ -325,7 +332,9 @@ def GeneratePythonCFunction(self):
inplace_returns_pos_map = {}
# Generate Python-C Tensors Parsing Logic
get_eager_tensor_str = ""
input_names = "mesh_ptr, "
Copy link
Contributor

Choose a reason for hiding this comment

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

这个可以放到上面模板里吗?这样看模板能知道mesh传进去了,inputs则只包含api的输入,语义更准确一些

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.

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

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

@GhostScreaming GhostScreaming merged commit b555415 into PaddlePaddle:develop Sep 27, 2023
27 checks passed
Frida-a pushed a commit to Frida-a/Paddle that referenced this pull request Oct 14, 2023
* [AutoParallel] Support operators have mixed inputs like DenseTensor and DistTensor.

* Polish code with review comments.
jiahy0825 pushed a commit to jiahy0825/Paddle that referenced this pull request Oct 16, 2023
* [AutoParallel] Support operators have mixed inputs like DenseTensor and DistTensor.

* Polish code with review comments.
danleifeng pushed a commit to danleifeng/Paddle that referenced this pull request Nov 14, 2023
* [AutoParallel] Support operators have mixed inputs like DenseTensor and DistTensor.

* Polish code with review comments.
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