code: def Check(
      net,
      outputs_with_grad,
      input_values,
      input_to_check,
      step_size=0.0001,
      threshold=0.05,
      print_net=True,
  ):
      net_results, net_grads, full_net = _get_grad(
          net, [], outputs_with_grad, input_values, [input_to_check]
      )
      analytic_grad = net_grads[input_to_check]
  
      def GetLoss(new_value):
          workspace.blobs[input_to_check] = new_value
          workspace.RunNetOnce(full_net)
          return sum(
              [workspace.blobs[output] for output in outputs_with_grad]
          ).sum()
  
      def GetValue(dim, delta):
          input_value = input_values[input_to_check].copy()
          input_value.flat[dim] += delta
          return input_value
  
      grad_estimate = np.zeros_like(input_values[input_to_check])
      for dim in range(input_values[input_to_check].size):
          pos_loss = GetLoss(GetValue(dim, step_size))
          neg_loss = GetLoss(GetValue(dim, -step_size))
          grad_estimate.flat[dim] = (
              (pos_loss - neg_loss) / step_size / 2
          )
  
      err_msg = "Error in gradient check for net_copy {}".format(
          net.Name()
      )
      if print_net:
          err_msg += ": {}".format(net.Proto())
  
      return _assert_close(
          analytic_grad, grad_estimate, threshold, err_msg
      )
  
file_path: pytorch/caffe2/python/gradient_checker.py
imports: import os
  import numpy
  from caffe2.python import core, workspace, net_drawer
  from caffe2.proto import caffe2_pb2
label_desc: Use image node_id 2 for calling the NetGradientChecker obj's underlying member method code with example usage: obj.Check(net, outputs_with_grad, input_values, input_to_check, step_size, threshold, print_net) and returns: _assert_close, sum, input_value