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

[Zero-Dim] support output 0D for is_empty/as_complex/inner/dot/rank/tensordot/squeeze_/static.accuracy/static.auc/metric.accuracy, test=allcase #52850

Merged
merged 36 commits into from
Apr 22, 2023

Conversation

ROckDog22
Copy link
Contributor

@ROckDog22 ROckDog22 commented Apr 12, 2023

PR types

New features

PR changes

APIs

Description

card-69703
支持API输出0D Tensor:

is_empty
as_complex
inner
dot
rank
tensordot
squeeze_
static.accuracy
static.auc
metric.accuracy

@paddle-bot
Copy link

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

if (x_dims.size() == 2 && x_dims[0] != 0) {
std::vector<int64_t> x_dims_vec = phi::vectorize(x_dims);
std::vector<int64_t> x_dims_vec_cut(x_dims_vec.begin(),
x_dims_vec.end() - 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

这个对1D时也是通用的吧,是不是不用加这个判断了

Copy link
Contributor Author

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.

已将修改为(0, 1)的单测

self.grad_x = self.grad_out * np.conj(self.y)
self.grad_y = self.grad_out * np.conj(self.x)

def test_check_output(self):
self.check_output()
# def test_check_output(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.

当时debug的时候忘改了,已修改

out.backward()

self.assertEqual(out.shape, [])
self.assertEqual(out.grad.shape, [])
Copy link
Contributor

Choose a reason for hiding this comment

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

需要测下x.grad的shape

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已添加测试样例

out1.backward()

self.assertEqual(out1.shape, [2])
self.assertEqual(out1.grad.shape, [2])
Copy link
Contributor

Choose a reason for hiding this comment

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

需要测下x.grad的shape

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

out.retain_grads()
out.backward()

self.assertEqual(out.shape, [])
Copy link
Contributor

Choose a reason for hiding this comment

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

需要测下x.grad的shape

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已添加测试样例

out.retain_grads()
out.backward()

self.assertEqual(out.shape, [])
Copy link
Contributor

Choose a reason for hiding this comment

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

需要测下x.grad的shape

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已添加测试样例

out.retain_grads()
out.backward()

self.assertEqual(out.shape, [])
Copy link
Contributor

Choose a reason for hiding this comment

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

需要测下x.grad的shape

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已添加测试样例

prog = paddle.static.default_main_program()
res = self.exe.run(
prog,
fetch_list=[out, out.grad_name],
Copy link
Contributor

Choose a reason for hiding this comment

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

静态图也需要fetch下x.grad_name,测下x的grad

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已添加测试样例

@zhwesky2010
Copy link
Contributor

PR-CI-Kunlun-R200-Test是一个test_rnn_op挂,你可以看下其他PR也挂这里了。因此和你这个PR没有关系

@ROckDog22
Copy link
Contributor Author

PR-CI-Kunlun-R200-Test是一个test_rnn_op挂,你可以看下其他PR也挂这里了。因此和你这个PR没有关系

好的

@@ -1153,7 +1153,14 @@ void DotInferMeta(const MetaTensor& x, const MetaTensor& y, MetaTensor* out) {
x_dims.to_str(),
y_dims.to_str()));

x_dims[x_dims.size() - 1] = 1;
if (x_dims.size() == 2 && x_dims[0] == 0 && x_dims[1] == 0) {
x_dims[x_dims.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.

这个判断过于hard code了
判断 x.numel() == 0 是不是就不会改变0-Size Tensor的逻辑了

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

zhwesky2010
zhwesky2010 previously approved these changes Apr 19, 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.

LGTM

@@ -511,4 +508,5 @@ def test_check_grad_ingore_y(self):

if __name__ == '__main__':
paddle.enable_static()
paddle.device.set_device('cpu')
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.

已修改

self.assertEqual(out.grad.shape, [])

def test_tensordot(self):
x = paddle.arange(10, dtype='float64')
Copy link
Contributor

Choose a reason for hiding this comment

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

可以再加个case,axes=2,并且tensordot输入2D的情况

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(out.shape, [])
self.assertEqual(out.grad.shape, [])

# 1) input is 1D
Copy link
Contributor

Choose a reason for hiding this comment

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

可以加个case,inner x ,y输入2D,输出此时应为x y的第一维拼接而形成的2D

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(res[2].shape, ())
self.assertEqual(res[3].shape, ())

# 0) input is 2D
Copy link
Contributor

Choose a reason for hiding this comment

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

2) input is 2D

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(res[3].shape, (2, 2))

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

Choose a reason for hiding this comment

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

和动态图一样加个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.

已修改

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 b406a7d into PaddlePaddle:develop Apr 22, 2023
lijialin03 pushed a commit to lijialin03/Paddle that referenced this pull request Apr 25, 2023
…ensordot/squeeze_/static.accuracy/static.auc/metric.accuracy, test=allcase (PaddlePaddle#52850)

* [Zero-Dim] support output 0D for is_empty/as_complex/, test=allcase

* [Zero-Dim] support output 0D for is_empty/as_complex/, test=allcase

* add test case

* modify dot/metric.accuracy/static.accuracy/static.auc

* modfiy inner/tensordot bug

* test 9 api

* [Zero-Dim] support output 0D for is_empty/as_complex/inner/dot/rank/tensordot/squeeze_/static.accuracy/static.auc/metric.accuracy, test=allcase

* fix bug

* support output 0D for is_empty/as_complex/inner/dot/rank/tensordot/squeeze_/static.accuracy/static.auc/metric.accuracy

* code style

* fix bug

* fix test_dot_op bug

* fix accuracy bug

* fix bug

* fix bug

* fix bug

* fix bug

* codestyle

* fix dot bug

* fix dot bug

* fix dot bug

* code style

* fix dot bug

* fix dot bug

* fix dot bug

* fix dot bug

* fix dot bug

* fix dot bug

* modify code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants