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 flatten composite rule #50672

Merged
merged 20 commits into from
Feb 28, 2023

Conversation

xysheng-baidu
Copy link
Contributor

PR types

Others

PR changes

Others

Describe

add composite rule for flatten

@paddle-bot
Copy link

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


@REGISTER_COMPOSITE('flatten_contiguous_range')
def flatten_contiguous_range_composite(x, start_axis, stop_axis):
"""define composite rule of op flatten, flatten_contiguous_range -> flatten"""
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.

已添加拆分逻辑。

out = reshape(x, shape=shape_out), xshape
"""
shape_in = x.shape
shape_x_out: List[int] = [0]
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.

@cyber-pioneer 改成通用写法了,测试通过。

self.start_axis = 0
self.stop_axis = -1
self.init_test_case()
self.inputs = {"X": np.random.random(self.in_shape).astype("float64")}
self.init_attrs()
self.enable_cinn = False
Copy link
Contributor

Choose a reason for hiding this comment

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

子类的CINN测试都过不了吗

Copy link
Contributor Author

Choose a reason for hiding this comment

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

是的,没有能过的。

cyber-pioneer
cyber-pioneer previously approved these changes Feb 27, 2023
@cyber-pioneer
Copy link
Contributor

LGTM

Copy link
Contributor

@JiabinYang JiabinYang left a comment

Choose a reason for hiding this comment

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

one comment

shape_out.append(slice_numel)
for i in range(end_dim + 1, len(shape_in)):
shape_out.append(shape_in[i])
return reshape(x, shape=shape_out), xshape
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this op doesn't return xshape?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is xshape in the yaml definition, and need to use xshape when calculate grad.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The yaml defineition :

output : Tensor(out), Tensor(xshape)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, but for this case, which is a little special, CINN can't optimize xshape and actually it doesn't need xshape for backward pass. So, it's better to remove xshape usage if it's possible

JiabinYang

This comment was marked as resolved.

Copy link
Contributor

@JiabinYang JiabinYang left a comment

Choose a reason for hiding this comment

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

one comment

shape_out.append(slice_numel)
for i in range(end_dim + 1, len(shape_in)):
shape_out.append(shape_in[i])
return reshape(x, shape=shape_out), xshape
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, but for this case, which is a little special, CINN can't optimize xshape and actually it doesn't need xshape for backward pass. So, it's better to remove xshape usage if it's possible

JiabinYang
JiabinYang previously approved these changes Feb 27, 2023
Copy link
Contributor

@JiabinYang JiabinYang left a comment

Choose a reason for hiding this comment

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

LGTM

@xysheng-baidu
Copy link
Contributor Author

@JiabinYang remove xshape and return none, passed the test.

Copy link
Contributor

@JiabinYang JiabinYang left a comment

Choose a reason for hiding this comment

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

LGTM

@JiabinYang JiabinYang merged commit 8220771 into PaddlePaddle:develop Feb 28, 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.

4 participants