-
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 output 0D for is_empty/as_complex/inner/dot/rank/tensordot/squeeze_/static.accuracy/static.auc/metric.accuracy, test=allcase #52850
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
…ensordot/squeeze_/static.accuracy/static.auc/metric.accuracy, test=allcase
…ueeze_/static.accuracy/static.auc/metric.accuracy
paddle/phi/infermeta/binary.cc
Outdated
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); |
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.
这个对1D时也是通用的吧,是不是不用加这个判断了
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.
已将修改为(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): |
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.
当时debug的时候忘改了,已修改
out.backward() | ||
|
||
self.assertEqual(out.shape, []) | ||
self.assertEqual(out.grad.shape, []) |
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.
需要测下x.grad的shape
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.
已添加测试样例
out1.backward() | ||
|
||
self.assertEqual(out1.shape, [2]) | ||
self.assertEqual(out1.grad.shape, [2]) |
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.
需要测下x.grad的shape
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.
done
out.retain_grads() | ||
out.backward() | ||
|
||
self.assertEqual(out.shape, []) |
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.
需要测下x.grad的shape
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.
已添加测试样例
out.retain_grads() | ||
out.backward() | ||
|
||
self.assertEqual(out.shape, []) |
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.
需要测下x.grad的shape
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.
已添加测试样例
out.retain_grads() | ||
out.backward() | ||
|
||
self.assertEqual(out.shape, []) |
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.
需要测下x.grad的shape
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.
已添加测试样例
prog = paddle.static.default_main_program() | ||
res = self.exe.run( | ||
prog, | ||
fetch_list=[out, out.grad_name], |
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.
静态图也需要fetch下x.grad_name,测下x的grad
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.
已添加测试样例
PR-CI-Kunlun-R200-Test是一个test_rnn_op挂,你可以看下其他PR也挂这里了。因此和你这个PR没有关系 |
好的 |
paddle/phi/infermeta/binary.cc
Outdated
@@ -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; |
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.
这个判断过于hard code了
判断 x.numel() == 0 是不是就不会改变0-Size Tensor的逻辑了
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.
done
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
@@ -511,4 +508,5 @@ def test_check_grad_ingore_y(self): | |||
|
|||
if __name__ == '__main__': | |||
paddle.enable_static() | |||
paddle.device.set_device('cpu') |
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.
已修改
self.assertEqual(out.grad.shape, []) | ||
|
||
def test_tensordot(self): | ||
x = paddle.arange(10, dtype='float64') |
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,axes=2,并且tensordot输入2D的情况
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(out.shape, []) | ||
self.assertEqual(out.grad.shape, []) | ||
|
||
# 1) input is 1D |
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,inner x ,y输入2D,输出此时应为x y的第一维拼接而形成的2D
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(res[2].shape, ()) | ||
self.assertEqual(res[3].shape, ()) | ||
|
||
# 0) input is 2D |
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.
2) input is 2D
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(res[3].shape, (2, 2)) | ||
|
||
@prog_scope() | ||
def test_tensordot(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.
和动态图一样加个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.
已修改
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
…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
PR types
New features
PR changes
APIs
Description
card-69703
支持API输出0D Tensor: