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

Add expand composite rule #50810

Merged
merged 14 commits into from
Mar 13, 2023

Conversation

xysheng-baidu
Copy link
Contributor

PR types

Others

PR changes

Others

Describe

add composite rule for expand

@paddle-bot
Copy link

paddle-bot bot commented Feb 23, 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.

shape_in = x.shape
assert len(shape) >= len(shape_in)
dim_out = len(shape)
dim_in = len(shape_in)
Copy link
Contributor

Choose a reason for hiding this comment

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

polish 3 lines

dim_out = len(shape)
dim_in = len(shape_in)
if dim_out == 0:
return x
Copy link
Contributor

Choose a reason for hiding this comment

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

image

test case does not cover this branch, add relative case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

dim_out can't be 0, remove the code.



# Situation 10: comp case, input x is Bool
class TestExpandV2CompOpBoolean(OpTest):
Copy link
Contributor

Choose a reason for hiding this comment

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

之前没有组合测试的单测可以去掉,例如Shape Tensor类的

@Charles-hit Charles-hit merged commit 559de39 into PaddlePaddle:develop Mar 13, 2023
for i in range(dim_out - dim_in):
shape_in_expand.append(1)
shape_in_expand.extend(shape_in)
x_reshape = reshape(x, shape_in_expand)
Copy link
Contributor

Choose a reason for hiding this comment

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

Add comment to show why we need reshape first

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Under the static graph, the tile op will set the expanded dimension to -1 when expanding the tensor, which will result in failure to pass the shape check. So for tensors that need to expand the dimension, reshape will be used in advance

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

4 participants