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

【BUPT】【Paddle Tensor 第二期 API支持 0-size Tensor】paddle.matrix_norm 支持 0-size tensor #70186

Closed
wants to merge 12 commits into from

Conversation

ZHOU05030
Copy link
Contributor

@ZHOU05030 ZHOU05030 commented Dec 12, 2024

PR Category

User Experience

PR Types

Bug fixes

Description

解决存在matrix_norm 0 size tensor的报错
image

Copy link

paddle-bot bot commented Dec 12, 2024

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

@paddle-bot paddle-bot bot added the contributor External developers label Dec 12, 2024
@luotao1 luotao1 added the HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务 label Dec 13, 2024
}
auto dim_x = x.dims();
Copy link
Contributor

Choose a reason for hiding this comment

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

用xdim即可

Comment on lines +74 to +79
for (int i = 0; i < dim_x.size() - 2; ++i) {
out_dims_vec[i] = dim_x[i];
}
out->Resize(phi::make_ddim(out_dims_vec));
dev_ctx.template Alloc<int64_t>(out);
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

被删除的axis不一定是最后两个吧?
axis (list|tuple,可选) - 使用范数计算的轴。axis 为 [-2,-1],否则 axis 必须为长度为 2 的 list|tuple。

Comment on lines +85 to +86
out_dims_vec[dim_x.size() - 2] = 1;
out_dims_vec[dim_x.size() - 1] = 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

同上,不一定是最后两个axis

Comment on lines +1384 to +1417
x1 = paddle.full((0, 0), 1.0, dtype='float32')
y1_p = paddle.linalg.matrix_norm(x1, p=1, axis=[0, -1])
self.assertRaises(
ValueError, paddle.linalg.matrix_norm, x1, p=2, axis=[0, -1]
)
y1_fro_keepdimfalse = paddle.linalg.matrix_norm(
x1, p='fro', axis=[0, -1], keepdim=False
)
y1_fro_keepdimtrue = paddle.linalg.matrix_norm(
x1, p='fro', axis=[0, -1], keepdim=True
)
x2 = paddle.full((2, 2, 0), 1.0, dtype='float32')
y2_fro_keepdimfalse = paddle.linalg.matrix_norm(
x2, p='fro', keepdim=False
)
y2_fro_keepdimtrue = paddle.linalg.matrix_norm(
x2, p='fro', keepdim=True
)
y2_p_keepdimfalse = paddle.linalg.matrix_norm(
x2, p=1, axis=[0, -1], keepdim=False
)
y2_p_keepdimtrue = paddle.linalg.matrix_norm(
x2, p=1, axis=[0, -1], keepdim=True
)
self.assertRaises(
ValueError, paddle.linalg.matrix_norm, x2, p=2, axis=[0, -1]
)
self.assertEqual(y1_fro_keepdimfalse.shape, [])
self.assertEqual(y1_fro_keepdimtrue.shape, [1, 1])
self.assertEqual(y2_fro_keepdimfalse.shape, x2.shape[:-2])
self.assertEqual(y2_fro_keepdimtrue.shape, [2, 1, 1])
self.assertEqual(y2_p_keepdimfalse.shape, [])
self.assertEqual(y2_p_keepdimtrue.shape, [2, 1, 1])
self.assertEqual(y1_p.shape, [])
Copy link
Contributor

Choose a reason for hiding this comment

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

可以增加一个单测,[3,0,2,0], axis=[1,-1]

Copy link

paddle-ci-bot bot commented Dec 26, 2024

Sorry to inform you that a6845c9's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants