Skip to content

Conversation

@GGBond8488
Copy link
Contributor

@GGBond8488 GGBond8488 commented Apr 13, 2023

PR types

Others

PR changes

Others

Description

Pcard-66984
Support the following api 0D output

paddle.dist
paddle.linalg.cov
paddle.linalg.det

@paddle-bot
Copy link

paddle-bot bot commented Apr 13, 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.

@GGBond8488 GGBond8488 changed the title 【0D output】add_0d_output_support_for_det 【0D output】add_0d_output_support Apr 20, 2023
@GGBond8488 GGBond8488 changed the title 【0D output】add_0d_output_support 【0D output】add_0D_output_support Apr 20, 2023
Copy link
Contributor

@zhwesky2010 zhwesky2010 left a 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
Copy link
Contributor

Choose a reason for hiding this comment

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

reduce inferMeta 已经修改了,可以打开

Copy link
Contributor Author

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
Copy link
Contributor

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打开

Copy link
Contributor Author

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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])
Copy link
Contributor

Choose a reason for hiding this comment

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

这个有其他的依赖吗,不然可以打开这个case,如果有依赖需要说明

self.assertEqual(res[3].shape, (5,))

@prog_scope()
def test_linalg_norm(self):
Copy link
Contributor

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):
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.

除依赖sum以外的case全部打开,剩下也标明依赖sum

@GGBond8488 GGBond8488 force-pushed the add_0d_output_support_for_det branch from 55b8046 to 8138ce6 Compare April 25, 2023 09:48
Copy link
Contributor

Choose a reason for hiding this comment

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

这个的shape应该是[]吧
infoflow 2023-04-26 15-02-57

Copy link
Contributor Author

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

@GGBond8488 GGBond8488 force-pushed the add_0d_output_support_for_det branch from ad5e97e to fff8e6e Compare April 27, 2023 02:57
Copy link
Contributor

@zhwesky2010 zhwesky2010 left a comment

Choose a reason for hiding this comment

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

LGTM

@zhwesky2010 zhwesky2010 merged commit ef6e8d0 into PaddlePaddle:develop Apr 28, 2023
@paddle-bot
Copy link

paddle-bot bot commented Apr 28, 2023

你的PR已合入Paddle库,请关注后续测试结果。
Your PR has been merged into the repository. An official integration test will be conducted later. Stay tuned.

@zhwesky2010 zhwesky2010 changed the title 【0D output】add_0D_output_support 【Zero-Dim】support dist/cov/det output 0D Apr 28, 2023
@zhwesky2010 zhwesky2010 changed the title 【Zero-Dim】support dist/cov/det output 0D [Zero-Dim] support dist/cov/det output 0D May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants