code: def create_runtime_profiler(
      enabled: bool,
      use_cpu: bool,
      use_cuda: bool,
      wait: int,
      warmup: int,
      active: int,
      legacy_profiler: bool,
  ):
      """
      Create a runtime profiler with the provided options.
  
      The type of runtime profiler depends on the pytorch version:
      newer version (above 1.8.1) will use "torch.profiler" instead
      of "torch.autograd.profiler".
      """
      if not enabled:
          return null_context()
  
      if is_pytorch_profiler_available() and not legacy_profiler:
          import torch.profiler
  
          profiled_activities = []
          if use_cpu:
              profiled_activities.append(
                  torch.profiler.ProfilerActivity.CPU
              )
          if use_cuda:
              profiled_activities.append(
                  torch.profiler.ProfilerActivity.CUDA
              )
          schedule = torch.profiler.schedule(
              wait=wait, warmup=warmup, active=active
          )
          profiler = torch.profiler.profile(
              activities=profiled_activities, schedule=schedule
          )
          return Profiler(profiler)
      else:
          import torch.autograd.profiler
  
          profiler = torch.autograd.profiler.profile(
              enabled=enabled, use_cuda=use_cuda, profile_memory=False
          )
          return AutoGradProfiler(
              profiler, wait=wait, warmup=warmup, active=active
          )
  
imports: import functools
  import logging
  import os
  from contextlib import contextmanager
  from vissl.utils.layer_memory_tracking import null_context
label_desc: Use image node_id 3 for calling a global function with example usage: create_runtime_profiler(enabled, use_cpu, use_cuda, wait, warmup, active, legacy_profiler) and returns: null_context, Profiler, AutoGradProfiler