From 133541ee41624e8b25b885fb1a2f11cbdd17299e Mon Sep 17 00:00:00 2001 From: Yu Yang Date: Thu, 3 Aug 2017 15:00:21 +0800 Subject: [PATCH] Merge codes --- python/paddle/v2/framework/tests/gradient_checker.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/python/paddle/v2/framework/tests/gradient_checker.py b/python/paddle/v2/framework/tests/gradient_checker.py index 0ee7e8fb49..4022de1c40 100644 --- a/python/paddle/v2/framework/tests/gradient_checker.py +++ b/python/paddle/v2/framework/tests/gradient_checker.py @@ -10,7 +10,7 @@ def get_numeric_gradient(op, input_values, output_name, input_to_check, - delta=1e-5, + delta=1e-2, local_scope=None): """ Get Numeric Gradient for an operator's input. @@ -34,8 +34,8 @@ def get_numeric_gradient(op, var = local_scope.new_var(var_name) tensor = var.get_tensor() tensor.set_dims(input_values[var_name].shape) - tensor.alloc_float() - tensor.set(input_values[var_name]) + tensor.alloc_float(core.CPUPlace()) + tensor.set(input_values[var_name], core.CPUPlace()) # Create all output variable in local_scope for output in op.outputs(): @@ -46,10 +46,10 @@ def get_numeric_gradient(op, # allocate output memory for output in op.outputs(): - local_scope.find_var(output).get_tensor().alloc_float() + local_scope.find_var(output).get_tensor().alloc_float(core.CPUPlace()) # TODO(yuyang18): Only CPU is support now. - cpu_ctx = core.DeviceContext.cpu_context() + cpu_ctx = core.DeviceContext.create(core.CPUPlace()) def get_output(): op.run(local_scope, cpu_ctx) @@ -85,7 +85,6 @@ if __name__ == '__main__': y = numpy.random.random((10, 1)).astype("float32") arr = get_numeric_gradient(add_op, {'X': x, "Y": y}, 'Z', 'X') - self.assertAlmostEqual(arr.mean(), 1.0, delta=1e-2) unittest.main() -- GitLab