Skip to content

[WIP][CodeStyle] use np.testing.assert_allclose instead of assertTrue(np.allclose(...)) in op_test - #46695

Closed
SigureMo wants to merge 4 commits into
PaddlePaddle:developfrom
cattidea:assert_allclose/fix/op_test
Closed

SigureMo wants to merge 4 commits into
PaddlePaddle:developfrom
cattidea:assert_allclose/fix/op_test

Conversation

@SigureMo

@SigureMo SigureMo commented Oct 1, 2022 •

Copy link
Copy Markdown
Collaborator

PR types

Others

PR changes

Others

Describe

一些非 self.assertTrue 开头的「漏网之鱼」,如 self.op_test.assertTrue

做 #46686 时发现报错信息非常不友好,因此修一下

emmm,本地单测运行出了点问题,本地不方便调试,之后再说

@paddle-bot

paddle-bot Bot commented Oct 1, 2022

Copy link
Copy Markdown

你的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 contributor External developers status: proposed labels Oct 1, 2022
@SigureMo SigureMo changed the title [CodeStyle] use np.testing.assert_allclose instead of assertTrue(np.allclose(...)) in op_test [WIP][CodeStyle] use np.testing.assert_allclose instead of assertTrue(np.allclose(...)) in op_test Oct 1, 2022
@SigureMo SigureMo closed this Oct 1, 2022
@paddle-bot

paddle-bot Bot commented Oct 1, 2022

Copy link
Copy Markdown

很抱歉,经过我们的反复讨论,你的PR暂未达到合入标准,请阅读飞桨原生算子开发规范,你可以重新提交新的PR,我们先将此PR关闭,感谢你的贡献。
Sorry to inform you that through our discussion, your PR fails to meet the merging standard (Reference: Paddle Custom Operator Design Doc). You can also submit an new one. Thank you.

@paddle-bot

paddle-bot Bot commented Oct 3, 2022

Copy link
Copy Markdown

很抱歉,经过我们的反复讨论,你的PR暂未达到合入标准,请阅读飞桨原生算子开发规范,你可以重新提交新的PR,我们先将此PR关闭,感谢你的贡献。
Sorry to inform you that through our discussion, your PR fails to meet the merging standard (Reference: Paddle Custom Operator Design Doc). You can also submit an new one. Thank you.

@SigureMo SigureMo reopened this Oct 4, 2022

@SigureMo SigureMo left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

因为本地跑不了单测,利用 CI 解决的一部分问题,其他问题后续逐步解决

完整 log:build.log

不过目测有的问题可能确实解决不了……

rtol=self.rtol,
atol=self.atol,
equal_nan=self.equal_nan)
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

2022-10-01 17:28:28 ======================================================================
2022-10-01 17:28:28 FAIL: test_check_output (test_isclose_op.TestIscloseOpFloat64)
2022-10-01 17:28:28 ----------------------------------------------------------------------
2022-10-01 17:28:28 Traceback (most recent call last):
2022-10-01 17:28:28   File "/workspace/Paddle/build/python/paddle/fluid/tests/unittests/test_isclose_op.py", line 228, in test_check_output
2022-10-01 17:28:28     self.check_output(check_eager=True)
2022-10-01 17:28:28   File "/workspace/Paddle/build/python/op_test.py", line 1799, in check_output
2022-10-01 17:28:28     check_eager=check_eager)
2022-10-01 17:28:28   File "/workspace/Paddle/build/python/op_test.py", line 1664, in check_output_with_place
2022-10-01 17:28:28     static_checker.check()
2022-10-01 17:28:28   File "/workspace/Paddle/build/python/op_test.py", line 1494, in check
2022-10-01 17:28:28     self.compare_outputs_with_expects()
2022-10-01 17:28:28   File "/workspace/Paddle/build/python/op_test.py", line 1484, in compare_outputs_with_expects
2022-10-01 17:28:28     self.compare_single_output_with_expect(out_name, expect)
2022-10-01 17:28:28   File "/workspace/Paddle/build/python/op_test.py", line 1465, in compare_single_output_with_expect
2022-10-01 17:28:28     self._compare_numpy(name, actual_np, expect_np)
2022-10-01 17:28:28   File "/workspace/Paddle/build/python/op_test.py", line 1448, in _compare_numpy
2022-10-01 17:28:28     " in " + self.checker_name)
2022-10-01 17:28:28   File "/opt/_internal/cpython-3.7.0/lib/python3.7/site-packages/numpy/testing/_private/utils.py", line 1531, in assert_allclose
2022-10-01 17:28:28     verbose=verbose, header=header, equal_nan=equal_nan)
2022-10-01 17:28:28   File "/opt/_internal/cpython-3.7.0/lib/python3.7/site-packages/numpy/testing/_private/utils.py", line 763, in assert_array_compare
2022-10-01 17:28:28     raise AssertionError(msg)
2022-10-01 17:28:28 AssertionError: 
2022-10-01 17:28:28 Not equal to tolerance rtol=1e-05, atol=0
2022-10-01 17:28:28 Output (Out) has diff at Place(cpu) in static checker
2022-10-01 17:28:28 (shapes (1,), (1, 1) mismatch)
2022-10-01 17:28:28  x: array([ True])
2022-10-01 17:28:28  y: array([[ True]])
2022-10-01 17:28:28 

所有的 expect 都比 actual 多一个维度,因此删掉外层 np.array([...])

(2, 5, 3, 2, 2, 3, 4, 2)).astype("bool")
}
self.attrs = {'reduce_all': True, 'dim': (2, 3, 4)}
self.attrs = {'dim': (2, 3, 4)}

@SigureMo SigureMo Oct 4, 2022 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

2022-10-01 17:31:33 ======================================================================
2022-10-01 17:31:33 FAIL: test_check_output (test_reduce_op.TestAll8DOp)
2022-10-01 17:31:33 ----------------------------------------------------------------------
2022-10-01 17:31:33 Traceback (most recent call last):
2022-10-01 17:31:33   File "/workspace/Paddle/build/python/paddle/fluid/tests/unittests/test_reduce_op.py", line 365, in test_check_output
2022-10-01 17:31:33     self.check_output(check_eager=True)
2022-10-01 17:31:33   File "/workspace/Paddle/build/python/op_test.py", line 1799, in check_output
2022-10-01 17:31:33     check_eager=check_eager)
2022-10-01 17:31:33   File "/workspace/Paddle/build/python/op_test.py", line 1664, in check_output_with_place
2022-10-01 17:31:33     static_checker.check()
2022-10-01 17:31:33   File "/workspace/Paddle/build/python/op_test.py", line 1494, in check
2022-10-01 17:31:33     self.compare_outputs_with_expects()
2022-10-01 17:31:33   File "/workspace/Paddle/build/python/op_test.py", line 1484, in compare_outputs_with_expects
2022-10-01 17:31:33     self.compare_single_output_with_expect(out_name, expect)
2022-10-01 17:31:33   File "/workspace/Paddle/build/python/op_test.py", line 1465, in compare_single_output_with_expect
2022-10-01 17:31:33     self._compare_numpy(name, actual_np, expect_np)
2022-10-01 17:31:33   File "/workspace/Paddle/build/python/op_test.py", line 1448, in _compare_numpy
2022-10-01 17:31:33     " in " + self.checker_name)
2022-10-01 17:31:33   File "/opt/_internal/cpython-3.7.0/lib/python3.7/site-packages/numpy/testing/_private/utils.py", line 1531, in assert_allclose
2022-10-01 17:31:33     verbose=verbose, header=header, equal_nan=equal_nan)
2022-10-01 17:31:33   File "/opt/_internal/cpython-3.7.0/lib/python3.7/site-packages/numpy/testing/_private/utils.py", line 763, in assert_array_compare
2022-10-01 17:31:33     raise AssertionError(msg)
2022-10-01 17:31:33 AssertionError: 
2022-10-01 17:31:33 Not equal to tolerance rtol=1e-05, atol=1e-05
2022-10-01 17:31:33 Output (Out) has diff at Place(cpu) in static checker
2022-10-01 17:31:33 (shapes (1,), (2, 5, 3, 4, 2) mismatch)
2022-10-01 17:31:33  x: array([False])
2022-10-01 17:31:33  y: array([[[[[False, False],
2022-10-01 17:31:33           [False, False],
2022-10-01 17:31:33           [False, False],...

reduce_all 会使维度为 [1]

std::vector<int64_t> out_dim_vector;
if (keep_dim) {
for (int64_t i = 0; i < x.dims().size(); ++i) {
if (reduce_all || dims_set.find(i) != dims_set.end()) {
out_dim_vector.push_back(1);
} else {
out_dim_vector.push_back(x.dims().at(i));
}
}
} else {
for (int64_t i = 0; i < x.dims().size(); ++i) {
if (reduce_all || dims_set.find(i) != dims_set.end()) {
continue;
} else {
out_dim_vector.push_back(x.dims().at(i));
}
}
if (out_dim_vector.size() == 0) {
out_dim_vector.push_back(1);
}
}

因此这里需要移除 reduce_all 参数(或者设为默认值 False)才能与 NumPy 计算的 expect 一致

@paddle-bot

paddle-bot Bot commented Oct 5, 2022

Copy link
Copy Markdown

很抱歉,经过我们的反复讨论,你的PR暂未达到合入标准,请阅读飞桨原生算子开发规范,你可以重新提交新的PR,我们先将此PR关闭,感谢你的贡献。
Sorry to inform you that through our discussion, your PR fails to meet the merging standard (Reference: Paddle Custom Operator Design Doc). You can also submit an new one. Thank you.

@SigureMo
SigureMo deleted the assert_allclose/fix/op_test branch December 28, 2023 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor External developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant