From 239b2ac7186f7dbcb14736e7dbbb825576be0a33 Mon Sep 17 00:00:00 2001 From: 103yiran <1039105206@qq.com> Date: Fri, 12 Oct 2018 12:04:54 -0700 Subject: [PATCH] make the variable declaration closer to usage Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/9262 Differential Revision: D10363576 Pulled By: ezyang fbshipit-source-id: 05c8eb12f3b389caf562cca9e338cc91b0e9acc1 --- caffe2/python/gradient_checker.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/caffe2/python/gradient_checker.py b/caffe2/python/gradient_checker.py index f4aaf9297d3..703df9bd5ee 100644 --- a/caffe2/python/gradient_checker.py +++ b/caffe2/python/gradient_checker.py @@ -264,7 +264,7 @@ class GradientChecker: # hack. grad_ops, g_input = getGradientForOp(op) - dims_to_check = inputs[input_to_check].size + _input_device_options = input_device_options or \ core.InferOpBlobDevicesAsDict(op)[0] # First, feed in the input. @@ -285,7 +285,8 @@ class GradientChecker: raise Exception( "Mismatched gradient shapes: estimated ({}), grad ({})".format( grad_estimate.shape, grad.shape)) - + + dims_to_check = inputs[input_to_check].size for current_dim in range(dims_to_check): # Positive gradient inputs[input_to_check].flat[current_dim] += self._stepsize