-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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 std/var #49735
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
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.
这两个直接加到reduce_api_list应该可以
out.backward() | ||
|
||
# checkout shape of out | ||
self.assertEqual(out.shape, []) |
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.
需要对反向进行测试,梯度为0.
def test_std(self): | ||
x = paddle.rand([]) | ||
x.stop_gradient = False | ||
out = paddle.std(x) |
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.
再加一种 paddle.std(x, []) 的情形
# checkout value of out | ||
self.assertEqual(out, 0) | ||
|
||
def test_var(self): |
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.
同std
@@ -1708,6 +1732,26 @@ def test_median(self): | |||
self.assertEqual(res[2].shape, ()) | |||
np.testing.assert_allclose(res[2], 1.0) | |||
|
|||
@prog_scope() |
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.
与动态图问题一致
python/paddle/tensor/stat.py
Outdated
@@ -146,20 +146,24 @@ def var(x, axis=None, unbiased=True, keepdim=False, name=None): | |||
""" | |||
if not in_dygraph_mode(): | |||
check_variable_and_dtype(x, 'x', ['float32', 'float64'], 'var') | |||
if len(x.shape) == 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.
LGTM
PR types
New features
PR changes
APIs
Describe
[Zero-Dim] support input 0D Tensor for std/var:
为以下API支持输入0D Tensor,不修改其输出端行为,属于新增功能,无不兼容影响:
paddle.std
paddle.var