class_docstr: A gradient checker in Python.
  
  This is not the most efficient way to check gradients, as the Python
  interface will involve a lot of copies back and forth operations. Use at your
  own risk.
code: def _assertInferTensorChecks(self, op, grad_ops):
      tmp_net = caffe2_pb2.NetDef()
      tmp_net.op.extend([op])
      tmp_net.op.extend(grad_ops)
      inferred_shapes, inferred_types = workspace.InferShapesAndTypes(
          [tmp_net],
          nets_proto=True,
      )
  
      outputs = set()
      for grad_op in grad_ops:
          outputs.update(grad_op.output)
  
      for output in outputs:
          if output not in inferred_shapes:
              raise Exception(
                  "expected output {} to be inferred".format(output)
              )
          blob = workspace.FetchBlob(output)
          correct_shape = list(blob.shape)
          inferred_shape = list(inferred_shapes[output])
          if correct_shape != inferred_shape:
              raise Exception(
                  "Mismatched inferred shape: want({}), got({})".format(
                      correct_shape, inferred_shape
                  )
              )
  
          if type(blob) is np.ndarray:
              if blob.dtype == np.dtype("float64"):
                  correct_type = caffe2_pb2.TensorProto.DOUBLE
              elif blob.dtype == np.dtype("float32"):
                  correct_type = caffe2_pb2.TensorProto.FLOAT
              elif blob.dtype == np.dtype("int32"):
                  correct_type = caffe2_pb2.TensorProto.INT32
              elif blob.dtype == np.dtype("int64"):
                  correct_type = caffe2_pb2.TensorProto.INT64
              else:
                  correct_type = "unknown {}".format(np.dtype)
          else:
              correct_type = str(type(blob))
          inferred_type = inferred_types[output]
          if correct_type != inferred_type:
              raise Exception(
                  "Mismatched inferred type: want({}), got({})".format(
                      correct_type, inferred_type
                  )
              )
  
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 4 for calling the GradientChecker obj's underlying member method code with example usage: obj._assertInferTensorChecks(op, grad_ops) without return types