Skip to content

Conversation

@PolaKuma
Copy link
Contributor

PR Category

User Experience

PR Types

Others

Description

单测可以通过0-size的输入,但是array_api_tests可能存在配置问题(在@pytest.mark.xp_extension('linalg')语句报错),先跑个CI看看。
Screenshot 2024-12-31 at 15 12 04

@paddle-bot paddle-bot bot added the contributor External developers label Dec 31, 2024
@luotao1 luotao1 added the HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务 label Jan 2, 2025
Comment on lines +202 to +205
if (y_dims.size() == 1) {
out_dims =
std::vector<int>(x_dims.Get(), x_dims.Get() + x_dims.size() - 2);
out_dims.push_back(y_dims[y_dims.size() - 1]);
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.

这个分支有测试到吗?

这个好像测不到,python层solve函数有一个检查输入格式的函数了,如果y_dims.size() == 1会raise ValueError,已经添加单测了)

Comment on lines 213 to 215
int x_dim = (x_it != x_shape.rend()) ? *x_it : 1;
int y_dim = (y_it != y_shape.rend()) ? *y_it : 1;
out_dims.push_back(std::max(x_dim, y_dim));
Copy link
Contributor

Choose a reason for hiding this comment

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

这里有个问题,广播时如果 xdim=1,ydim=0,那么结果的outdim应该是0而不是1

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


def test_dygraph(self):
def run(place, x_shape, y_shape):
paddle.disable_static(place)
Copy link
Contributor

Choose a reason for hiding this comment

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

改用with xxguard代替disable/enable static

Comment on lines +198 to +228
if (x.numel() == 0 || y.numel() == 0) {
auto x_dims = x.dims();
auto y_dims = y.dims();
std::vector<int> out_dims;
if (y_dims.size() == 1) {
out_dims =
std::vector<int>(x_dims.Get(), x_dims.Get() + x_dims.size() - 2);
out_dims.push_back(y_dims[y_dims.size() - 1]);
} else {
// broadcast
std::vector<int> x_shape(x_dims.Get(), x_dims.Get() + x_dims.size() - 2);
std::vector<int> y_shape(y_dims.Get(), y_dims.Get() + y_dims.size() - 2);
auto x_it = x_shape.rbegin();
auto y_it = y_shape.rbegin();
while (x_it != x_shape.rend() || y_it != y_shape.rend()) {
int x_dim = (x_it != x_shape.rend()) ? *x_it : 1;
int y_dim = (y_it != y_shape.rend()) ? *y_it : 1;
if (x_dim == 0 || y_dim == 0) {
out_dims.push_back(0);
} else {
out_dims.push_back(std::max(x_dim, y_dim));
}
if (x_it != x_shape.rend()) ++x_it;
if (y_it != y_shape.rend()) ++y_it;
}
std::reverse(out_dims.begin(), out_dims.end());
out_dims.insert(out_dims.end(),
y_dims.Get() + y_dims.size() - 2,
y_dims.Get() + y_dims.size());
}
out->Resize(phi::make_ddim(out_dims));
Copy link
Contributor

Choose a reason for hiding this comment

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

这段代码能移动到solve的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.

这段代码能移动到solve的infermeta里面吗?

好像不太行诶,移到binary.cc里面输入0-size tensor就报错了

Copy link
Contributor

Choose a reason for hiding this comment

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

这段代码能移动到solve的infermeta里面吗?

好像不太行诶,移到binary.cc里面输入0-size tensor就报错了

好的

Copy link
Contributor

@HydrogenSulfate HydrogenSulfate left a comment

Choose a reason for hiding this comment

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

LGTM

@HydrogenSulfate HydrogenSulfate merged commit 1cb0114 into PaddlePaddle:develop Jan 8, 2025
30 of 31 checks passed
@PolaKuma PolaKuma deleted the solve_0size branch March 20, 2025 04:41
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