code: def gpu_time(lmb, name, r=100):
      b = torch.cuda.Event(enable_timing=True)
      e = torch.cuda.Event(enable_timing=True)
      # with magic_trace(name + ".fxt"):
      for _ in range(r):
          lmb()
      b.record()
      for _ in range(r):
          lmb()
      e.record()
      e.synchronize()
      elapsed = b.elapsed_time(e)
      # with torch.profiler.profile(schedule=torch.profiler.schedule(
      #     wait=0,
      #     warmup=1,
      #     active=2), on_trace_ready=tensorboard_trace_handler(name), with_stack=True) as profiler:
      #     for _ in range(3):
      #         lmb()
      #         profiler.step()
      print(name, elapsed / r)
      return elapsed / r
  
imports: from functorch.dim import Tensor, Dim, dims, dimlists, stack, DimensionBindError, DimList
  from attn_ft import BertSelfAttention, Linear
  from attn_positional import BertSelfAttention
  from torch.testing._internal.common_utils import TestCase, run_tests, TEST_CUDA
  from unittest import skip, skipIf
  import torch
  import gc
  from functorch._C import dim
  from contextlib import contextmanager
  from time import perf_counter
label_desc: Use image node_id 3 for calling a global function with example usage: gpu_time(lmb, name, r) and returns: unknown