code: def timed(fn, no_grad=True, use_cuda=True):
      def run_fn():
          if no_grad:
              with torch.no_grad():
                  result = fn()
          else:
              result = fn()
          return result
  
      if use_cuda:
          start = torch.cuda.Event(enable_timing=True)
          end = torch.cuda.Event(enable_timing=True)
          start.record()
          result = run_fn()
          end.record()
          torch.cuda.synchronize()
          delta_t = start.elapsed_time(end) / 1000
      else:
          start = time.time()
          result = run_fn()
          end = time.time()
          delta_t = end - start
  
      return result, delta_t
  
file_path: ray/rllib/benchmarks/torch_compile/utils.py
imports: from typing import Union
  import numpy
  import gymnasium
  import time
  import torch
  from ray.rllib.policy.sample_batch import SampleBatch
label_desc: Use image node_id 2 for calling a global function with example usage: timed(fn, no_grad, use_cuda) and returns: result,  delta_t, result