code: def benchmark_train(args):
      cfg = setup(args)
      model = build_model(cfg)
      logger.info("Model:\n{}".format(model))
      if comm.get_world_size() > 1:
          model = DistributedDataParallel(
              model,
              device_ids=[comm.get_local_rank()],
              broadcast_buffers=False,
          )
      optimizer = build_optimizer(cfg, model)
      checkpointer = DetectionCheckpointer(model, optimizer=optimizer)
      checkpointer.load(cfg.MODEL.WEIGHTS)
  
      cfg.defrost()
      cfg.DATALOADER.NUM_WORKERS = 2
      data_loader = build_detection_train_loader(cfg)
      dummy_data = list(itertools.islice(data_loader, 100))
  
      def f():
          data = DatasetFromList(
              dummy_data, copy=False, serialize=False
          )
          while True:
              yield from data
  
      max_iter = 400
      trainer = (
          AMPTrainer if cfg.SOLVER.AMP.ENABLED else SimpleTrainer
      )(model, f(), optimizer)
      trainer.register_hooks(
          [
              hooks.IterationTimer(),
              hooks.PeriodicWriter([CommonMetricPrinter(max_iter)]),
              hooks.TorchProfiler(
                  lambda trainer: trainer.iter == max_iter - 1,
                  cfg.OUTPUT_DIR,
                  save_tensorboard=True,
              ),
          ]
      )
      trainer.train(1, max_iter)
  
imports: import itertools
  import logging
  import psutil
  import torch
  import tqdm
  from fvcore.common.timer import Timer
  from torch.nn.parallel import DistributedDataParallel
  from detectron2.checkpoint import DetectionCheckpointer
  from detectron2.config import LazyConfig, get_cfg, instantiate
  from detectron2.data import DatasetFromList, build_detection_test_loader, build_detection_train_loader
  from detectron2.data.benchmark import DataLoaderBenchmark
  from detectron2.engine import AMPTrainer, SimpleTrainer, default_argument_parser, hooks, launch
  from detectron2.modeling import build_model
  from detectron2.solver import build_optimizer
  from detectron2.utils import comm
  from detectron2.utils.collect_env import collect_env_info
  from detectron2.utils.events import CommonMetricPrinter
  from detectron2.utils.logger import setup_logger
label_desc: Use image node_id 6 for calling a global function with example usage: benchmark_train(args) without return types