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

Fix the div 0 error of matrix_power #49942

Merged
merged 14 commits into from
Jan 31, 2023
5 changes: 5 additions & 0 deletions paddle/phi/infermeta/unary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1889,6 +1889,11 @@ void MatrixPowerInferMeta(const MetaTensor& x, int n, MetaTensor* out) {
"The Input(X) should have at least 2 dimensions. But "
"received a %d dimension tensor.",
n_dim));
for (int i = 0; i < n_dim; ++i)
PADDLE_ENFORCE_NE(
dims[i],
0,
phi::errors::InvalidArgument("The size of Input(X) should not be 0."));
PADDLE_ENFORCE_EQ(dims[n_dim - 2],
dims[n_dim - 1],
phi::errors::InvalidArgument(
Expand Down
4 changes: 4 additions & 0 deletions python/paddle/fluid/tests/unittests/test_matrix_power_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,10 @@ def test_errors(self):
input = fluid.data(name="input_3", shape=[4, 5], dtype="float32")
self.assertRaises(ValueError, paddle.linalg.matrix_power, input, 2)

# The size of input should not be 0
input = fluid.data(name="input_4", shape=[1, 1, 0, 0], dtype="float32")
self.assertRaises(ValueError, paddle.linalg.matrix_power, input, 2)

Comment on lines +315 to +318
Copy link
Contributor

Choose a reason for hiding this comment

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

这个报错可能不是ValueError。导致你的单测挂了。
你可以在本地先删掉self.assertRaises(ValueError, paddle.linalg.matrix_power, input, 2)。再跑一次单测。这时,单测肯定报错,把PADDLE_ENFORCE_NE的The size of Input(X) should not be 0.给抛出来。
你看看报错的报错类型,应该不是ValueError。是什么,你重新填到self.assertRaises里。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这个报错可能不是ValueError。导致你的单测挂了。 你可以在本地先删掉self.assertRaises(ValueError, paddle.linalg.matrix_power, input, 2)。再跑一次单测。这时,单测肯定报错,把PADDLE_ENFORCE_NE的The size of Input(X) should not be 0.给抛出来。 你看看报错的报错类型,应该不是ValueError。是什么,你重新填到self.assertRaises里。

查出来了~原因是这个报错出现在动态图下面


class TestMatrixPowerSingularAPI(unittest.TestCase):
def setUp(self):
Expand Down