code: def benchmark_combined(
      fn,
      *inputs,
      grad=None,
      repeats=10,
      desc="",
      verbose=True,
      **kwinputs,
  ):
      """Use Pytorch Benchmark on the forward+backward pass of an arbitrary function."""
      if verbose:
          print(desc, "- Forward + Backward pass")
  
      # y = fn(*inputs, **kwinputs)
      # if grad is None:
      #     grad = torch.randn_like(y)
      # else:
      #     if grad.shape != y.shape:
      #         raise RuntimeError('Grad shape does not match output shape')
      # del y
      def f(grad, *inputs, **kwinputs):
          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"
                  )
          y.backward(grad, retain_graph=True)
  
      t = benchmark.Timer(
          stmt="f(grad, *inputs, **kwinputs)",
          globals={
              "f": f,
              "fn": fn,
              "inputs": inputs,
              "grad": grad,
              "kwinputs": kwinputs,
          },
          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 3 for calling a global function with example usage: benchmark_combined(fn) and returns: t,  m