code: def benchmark_backward(
      fn,
      *inputs,
      grad=None,
      repeats=10,
      desc="",
      verbose=True,
      **kwinputs,
  ):
      """Use Pytorch Benchmark on the backward pass of an arbitrary function."""
      if verbose:
          print(desc, "- Backward pass")
      y = fn(*inputs, **kwinputs)
      if type(y) is tuple:
          y = y[0]
      if grad is None:
          grad = torch.randn_like(y)
      else:
          if grad.shape != y.shape:
              raise RuntimeError(
                  "Grad shape does not match output shape"
              )
      t = benchmark.Timer(
          stmt="y.backward(grad, retain_graph=True)",
          globals={"y": y, "grad": grad},
          num_threads=torch.get_num_threads(),
      )
      m = t.timeit(repeats)
      if verbose:
          print(m)
      return t, m
  
imports: import torch
  import torch.utils.benchmark
label_desc: Use image node_id 2 for calling a global function with example usage: benchmark_backward(fn) and returns: t,  m