-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Add flatten composite rule #50672
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
a828cc1
to
d9ffe5e
Compare
|
||
@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""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
记录拆分逻辑
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里语法确认一下
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
子类的CINN测试都过不了吗
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是的,没有能过的。
… composite_rule_flatten
… composite_rule_flatten
LGTM |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The yaml defineition :
Paddle/paddle/phi/api/yaml/legacy_ops.yaml
Line 644 in 6786c01
output : Tensor(out), Tensor(xshape) |
There was a problem hiding this comment.
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
There was a problem hiding this 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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
… composite_rule_flatten
fe21b3a
@JiabinYang remove xshape and return none, passed the test. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
PR types
Others
PR changes
Others
Describe
add composite rule for flatten