Pow operator will failed if we have negative input
Created by: QiJune
Please refer to #5197 I add another unit test case to test pow operator in GPU, the test case is
class TestPow1(OpTest):
def setUp(self):
self.op_type = "pow"
self.inputs = {
'X': np.random.uniform(-2, 2, [11, 17]).astype("float32")
}
self.attrs = {'factor': 2.0}
self.outputs = {'Y': np.power(self.inputs['X'], 2)}
def test_check_output(self):
self.check_output()
def test_check_grad(self):
self.check_grad(['X'], 'Y', max_relative_error=0.02)
And it will get nan in GPU:
[22:36:10] : [Step 1/1] 145/248 Test #149: test_activation_op ..........................***Failed 3.36 sec
[22:36:10] : [Step 1/1] ................../paddle/python/paddle/v2/framework/tests/op_test.py:328: RuntimeWarning: invalid value encountered in greater
[22:36:10] : [Step 1/1] offset = np.argmax(diff_mat > max_relative_error)
[22:36:10] : [Step 1/1] FF............................
[22:36:10] : [Step 1/1] ======================================================================
[22:36:10] : [Step 1/1] FAIL: test_check_grad (__main__.TestPow1)
[22:36:10] : [Step 1/1] ----------------------------------------------------------------------
[22:36:10] : [Step 1/1] Traceback (most recent call last):
[22:36:10] : [Step 1/1] File "test_activation_op.py", line 329, in test_check_grad
[22:36:10] : [Step 1/1] self.check_grad(['X'], 'Y', max_relative_error=0.02)
[22:36:10] : [Step 1/1] File "/paddle/python/paddle/v2/framework/tests/op_test.py", line 382, in check_grad
[22:36:10] : [Step 1/1] "Gradient Check On %s" % str(gpu_place))
[22:36:10] : [Step 1/1] File "/paddle/python/paddle/v2/framework/tests/op_test.py", line 334, in __assert_is_close
[22:36:10] : [Step 1/1] self.assertLessEqual(max_diff, max_relative_error, err_msg())
[22:36:10] : [Step 1/1] AssertionError: Gradient Check On GPUPlace(0) Variable X max gradient diff nan over limit 0.020000, the first error element is 0, 0.008404, 0.008405