-
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 dist/cov/det output 0D #52857
[Zero-Dim] support dist/cov/det output 0D #52857
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
… support_OD_output
… support_0d_output_for_linalg.norm_and_slogdet
unique支持float16和bfloat16数据类型,并完善相关单测。
… add_0d_output_support_for_det
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.
norm/cond的case先打开吧,但是如果因为依赖sum/mean的地方,可以先写成老版本的shape: (1,) 来跑,但是加个TODO: after sum/mean output 0D, will change to []
# 1D input, p = fro ,axis = None, using reduceInferMeta | ||
x_1 = paddle.arange(24, dtype="float32") - 12 | ||
x_1.stop_gradient = False | ||
# using frobenius_norm, depends on reduce inferMeta support 0d output |
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 inferMeta 已经修改了,可以打开
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.
已打开
self.assertEqual(x_2_fro.grad.shape, [24]) | ||
|
||
# 2D input, p = 1, axis = [0, 1] | ||
# using p_matrix_norm ,depends on abs, pow, sum |
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.
abs/pow都是已经支持0D输入并输出0D的。就依赖sum就可以了。
我修改sum时,再把这个case打开
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.
修改为仅依赖sum
# self.assertEqual(x_4.grad.shape, [4, 6]) | ||
|
||
# 2D input, p = inf, axis = None | ||
# using p_matrix_norm, depends on paddle.max, paddle.min |
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.
max/min都支持了,可以打开
# self.assertEqual(x_5.grad.shape, [4, 6]) | ||
|
||
# 2D input, p = -inf, axis = [0, 1] | ||
# using inf_norm, depends on paddle.max, paddle.min, paddle.abs |
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.
max/min都支持了,可以打开
abs也支持
|
||
# x = paddle.to_tensor([[1.0, 0, -1], [0, 1, 0], [1, 0, 1]]) | ||
# x.stop_gradient = False | ||
# p = 2 : use paddle.sum, paddle.max, paddle.min |
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.
max/min支持了,可以去掉
sum我修改时再打开这个case
# out_fro = paddle.linalg.cond(x, p='fro') | ||
# assert_shape(out_fro) | ||
|
||
# p = nuc : use paddle.sum, paddle.max, paddle.min |
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.
max/min支持了,可以去掉
sum我修改时再打开这个case
# out_minus_1 = paddle.linalg.cond(x, p=-1) | ||
# assert_shape(out_minus_1) | ||
|
||
# p in (-2, 2) :use paddle.max, paddle.min |
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.
max/min支持了,可以打开这个case
# out_minus_inf.backward() | ||
# self.assertTrue(x.grad.shape, [3, 3]) | ||
|
||
# a = paddle.randn([2, 4, 4]) |
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.
这个有其他的依赖吗,不然可以打开这个case,如果有依赖需要说明
@@ -3747,6 +3928,156 @@ def test_multi_dot(self): | |||
self.assertEqual(res[2].shape, (4, 5)) | |||
self.assertEqual(res[3].shape, (5,)) | |||
|
|||
@prog_scope() | |||
def test_linalg_norm(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.
静态图同动态图问题一致
np.testing.assert_array_equal(res[0], np.array(2).astype(np.float32)) | ||
|
||
@prog_scope() | ||
def test_cond(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.
与动态图问题一致
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.
除依赖sum以外的case全部打开,剩下也标明依赖sum
… add_0d_output_support_for_det
…/Paddle into add_0d_output_support_for_det
55b8046
to
8138ce6
Compare
out_2.retain_grads() | ||
out_2.backward() | ||
|
||
self.assertEqual(out_2.shape, [1]) |
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.
这个就是行为不一样了,我们的多了一个as_vector参数,如果不指定axis,as_vector=True,就会返回1D
指定了axis,as_vector=False 返回了0D 可以看下面那个case
ad5e97e
to
fff8e6e
Compare
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已合入Paddle库,请关注后续测试结果。 |
PR types
Others
PR changes
Others
Description
Pcard-66984
Support the following api 0D output