From 9a0eedf5d4d32e0aaa80e554f608c56e6d36a798 Mon Sep 17 00:00:00 2001 From: dangqingqing Date: Mon, 14 Aug 2017 21:27:17 +0800 Subject: [PATCH] fix bug. --- python/paddle/v2/framework/tests/gradient_checker.py | 3 ++- python/paddle/v2/framework/tests/test_sigmoid_op.py | 11 +++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/python/paddle/v2/framework/tests/gradient_checker.py b/python/paddle/v2/framework/tests/gradient_checker.py index 5f9e54837e..d251f14b9d 100644 --- a/python/paddle/v2/framework/tests/gradient_checker.py +++ b/python/paddle/v2/framework/tests/gradient_checker.py @@ -156,6 +156,7 @@ class GradientChecker(unittest.TestCase): def compare_grad(self, forward_op, inputs): backward_op = core.Operator.backward(forward_op, set()) + # return if not compile with GPU or not implementing GPU kernel if not (core.is_compile_gpu() and backward_op.support_gpu()): return @@ -239,7 +240,7 @@ class GradientChecker(unittest.TestCase): for place in places: # get analytical gradients according to different device analytic_grads = self.get_grad(forward_op, backward_op, input_vars, - check_grad_names, place) + check_names, place) self.assert_is_close(numeric_grads, analytic_grads, check_names, max_relative_error, "Gradient Check On %s" % str(place)) diff --git a/python/paddle/v2/framework/tests/test_sigmoid_op.py b/python/paddle/v2/framework/tests/test_sigmoid_op.py index 1a6d395be6..c3bd79f5dc 100644 --- a/python/paddle/v2/framework/tests/test_sigmoid_op.py +++ b/python/paddle/v2/framework/tests/test_sigmoid_op.py @@ -17,15 +17,10 @@ class TestSigmoidGradOp(GradientChecker): def test_compare_grad(self): op = create_op("sigmoid") inputs = {"X": np.random.random((11, 17)).astype("float32")} - - # compare gpu and cpu results for backward op + # compare gpu and cpu results for backward op. + # skip this test if only compiling CPU version. self.compare_grad(op, inputs) - - def test_check_grad(self): - op = create_op("sigmoid") - inputs = {"X": np.random.random((11, 17)).astype("float32")} - - # check gradients + # check gradients self.check_grad(op, inputs, set("X"), "Y") -- GitLab