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

[Zero-Dim] support input 0D Tensor for distribution transform api #47677

Merged
merged 2 commits into from
Nov 8, 2022

Conversation

zhwesky2010
Copy link
Contributor

@zhwesky2010 zhwesky2010 commented Nov 4, 2022

PR types

New features

PR changes

APIs

Describe

为Distribution Transform类API支持输入0D Tensor,如下:

paddle.distribution.AbsTransform
paddle.distribution.AffineTransform
paddle.distribution.ChainTransform
paddle.distribution.ExpTransform
paddle.distribution.PowerTransform
paddle.distribution.ReshapeTransform
paddle.distribution.SigmoidTransform
paddle.distribution.TanhTransform
paddle.distribution.Transform
paddle.distribution.TransformedDistribution

@paddle-bot
Copy link

paddle-bot bot commented Nov 4, 2022

你的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.

@zhwesky2010 zhwesky2010 changed the title [Zero-Dim] support input 0D Tensor for distribution api [Zero-Dim] support input 0D Tensor for distribution api and judgement api Nov 4, 2022
@zhwesky2010 zhwesky2010 force-pushed the 0d_distribution branch 2 times, most recently from 04e0d6e to 043ceae Compare November 4, 2022 10:54
@zhwesky2010 zhwesky2010 changed the title [Zero-Dim] support input 0D Tensor for distribution api and judgement api [Zero-Dim] support input 0D Tensor for distribution api Nov 4, 2022
raise ValueError(
f"The numel of 'in_event_shape' should be 'out_event_shape', "
f"but got {functools.reduce(operator.mul, in_event_shape)}!={functools.reduce(operator.mul, out_event_shape)}"
f"but got {in_size}!={out_size}"
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

@zhwesky2010 zhwesky2010 Nov 8, 2022

Choose a reason for hiding this comment

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

0D Tensor的shape为[],numel为1,用functools.reduce无法实现,会报空列表的错误,所以就自行实现了

if shape[-len(self._in_event_shape) :] != self._in_event_shape:
if list(shape[-len(self._in_event_shape) :]) != list(
self._in_event_shape
):
Copy link
Contributor

Choose a reason for hiding this comment

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

建议只读类型用tuple

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

if shape[-len(self._out_event_shape) :] != self._out_event_shape:
if list(shape[-len(self._out_event_shape) :]) != list(
self._out_event_shape
):
raise ValueError(
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

Copy link
Contributor

@cxxly cxxly left a comment

Choose a reason for hiding this comment

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

LGTM

@PaddlePaddle PaddlePaddle deleted a comment from cxxly Nov 8, 2022
@zhwesky2010 zhwesky2010 changed the title [Zero-Dim] support input 0D Tensor for distribution api [Zero-Dim] support input 0D Tensor for distribution transform api Nov 8, 2022
Comment on lines +106 to 109
# original patching object as well as re-constrfucted patches.
delete_patches_if_need(f)

f.__test__ = False

Choose a reason for hiding this comment

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

貌似有 typo

@zhwesky2010 zhwesky2010 merged commit dc85b39 into PaddlePaddle:develop Nov 8, 2022
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