Skip to content

Commit 26f1b77

Browse files
committed
fix unittests error,test=kunlun
1 parent eeaf534 commit 26f1b77

File tree

3 files changed

+45
-15
lines changed

3 files changed

+45
-15
lines changed

python/paddle/fluid/tests/unittests/op_test.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import collections
2727
from collections import defaultdict
2828

29+
import paddle
2930
import paddle.fluid as fluid
3031
import paddle.fluid.core as core
3132
from paddle.fluid.backward import append_backward
@@ -1133,8 +1134,10 @@ def find_actual(target_name, fetch_list):
11331134
)
11341135
# Check inplace for given op, its grad op, its grad_grad op, etc.
11351136
# No effect on original OpTest
1136-
self.check_inplace_output_with_place(
1137-
place, no_check_set=no_check_set, inplace_atol=inplace_atol)
1137+
# Currently not support ParallelExecutor on XPUPlace.
1138+
if not paddle.is_compiled_with_xpu():
1139+
self.check_inplace_output_with_place(
1140+
place, no_check_set=no_check_set, inplace_atol=inplace_atol)
11381141

11391142
if check_dygraph:
11401143
return outs, dygraph_outs, fetch_list

python/paddle/fluid/tests/unittests/xpu/test_mean_op_xpu.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,21 @@ def test_errors(self):
6060
fluid.layers.softmax(input3)
6161

6262

63-
@unittest.skipIf(not paddle.is_compiled_with_xpu(),
64-
"core is not compiled with XPU")
6563
class TestXPUMeanOp(TestMeanOp):
6664
def init_dtype_type(self):
6765
self.dtype = np.float32
6866

6967
def test_check_output(self):
70-
place = paddle.XPUPlace(0)
71-
self.check_output_with_place(place, atol=1e-1)
68+
if paddle.is_compiled_with_xpu():
69+
paddle.enable_static()
70+
place = paddle.XPUPlace(0)
71+
self.check_output_with_place(place)
7272

7373
def test_checkout_grad(self):
74-
place = paddle.XPUPlace(0)
75-
self.check_grad_with_place(place, ['X'], 'Out', max_relative_error=0.8)
74+
if paddle.is_compiled_with_xpu():
75+
paddle.enable_static()
76+
place = paddle.XPUPlace(0)
77+
self.check_grad_with_place(place, ['X'], 'Out')
7678

7779

7880
class TestMeanAPI(unittest.TestCase):

python/paddle/fluid/tests/unittests/xpu/test_softmax_with_cross_entropy_op_xpu.py

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,19 @@ def setUp(self):
9393
self.attrs['axis'] = self.axis
9494

9595
def test_check_output(self):
96-
self.check_output()
96+
if paddle.is_compiled_with_xpu():
97+
paddle.enable_static()
98+
place = paddle.XPUPlace(0)
99+
self.check_output_with_place(place, atol=1e-2)
97100

98101
def test_check_grad(self):
99-
self.check_grad(["Logits"], "Loss", max_relative_error=0.05)
102+
if paddle.is_compiled_with_xpu():
103+
paddle.enable_static()
104+
place = paddle.XPUPlace(0)
105+
self.check_grad_with_place(
106+
place, ["Logits"], "Loss", max_relative_error=0.1)
100107

101108

102-
@unittest.skipIf(not paddle.is_compiled_with_xpu(),
103-
"core is not compiled with XPU")
104109
class TestXPUSoftmaxWithCrossEntropyOp(TestSoftmaxWithCrossEntropyOp):
105110
def initParams(self):
106111
self.op_type = "softmax_with_cross_entropy"
@@ -111,6 +116,19 @@ def initParams(self):
111116
self.ignore_index = -1
112117
self.dtype = np.float32
113118

119+
def test_check_output(self):
120+
if paddle.is_compiled_with_xpu():
121+
paddle.enable_static()
122+
place = paddle.XPUPlace(0)
123+
self.check_output_with_place(place, atol=1e-2)
124+
125+
def test_check_grad(self):
126+
if paddle.is_compiled_with_xpu():
127+
paddle.enable_static()
128+
place = paddle.XPUPlace(0)
129+
self.check_grad_with_place(
130+
place, ["Logits"], "Loss", max_relative_error=0.1)
131+
114132

115133
class TestXPUSoftmaxWithCrossEntropyOp2(TestXPUSoftmaxWithCrossEntropyOp):
116134
"""
@@ -127,10 +145,17 @@ def initParams(self):
127145
self.shape = [41, 37]
128146

129147
def test_check_output(self):
130-
self.check_output()
148+
if paddle.is_compiled_with_xpu():
149+
paddle.enable_static()
150+
place = paddle.XPUPlace(0)
151+
self.check_output_with_place(place, atol=1e-2)
131152

132153
def test_check_grad(self):
133-
self.check_grad(["Logits"], "Loss")
154+
if paddle.is_compiled_with_xpu():
155+
paddle.enable_static()
156+
place = paddle.XPUPlace(0)
157+
self.check_grad_with_place(
158+
place, ["Logits"], "Loss", max_relative_error=0.1)
134159

135160

136161
class TestXPUSoftmaxWithCrossEntropyOp3(TestXPUSoftmaxWithCrossEntropyOp):
@@ -230,7 +255,7 @@ def initParams(self):
230255

231256

232257
class TestXPUSoftmaxWithCrossEntropyOpSoftLabelAxis1(
233-
TestXPUSoftmaxWithCrossEntropyOp2):
258+
TestXPUSoftmaxWithCrossEntropyOp):
234259
def initParams(self):
235260
self.op_type = "softmax_with_cross_entropy"
236261
self.numeric_stable_mode = True

0 commit comments

Comments
 (0)