@@ -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" )
104109class 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
115133class 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
136161class TestXPUSoftmaxWithCrossEntropyOp3 (TestXPUSoftmaxWithCrossEntropyOp ):
@@ -230,7 +255,7 @@ def initParams(self):
230255
231256
232257class 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