code: def main(args, config):
      # Global flags
      torch.manual_seed(0)
      set_image_backend(args.image_backend)
      set_video_backend(args.video_backend)
  
      task = build_task(config)
  
      # Load checkpoint, if available.
      if args.checkpoint_load_path:
          task.set_checkpoint(args.checkpoint_load_path)
  
      # Load a checkpoint contraining a pre-trained model. This is how we
      # implement fine-tuning of existing models.
      if args.pretrained_checkpoint_path:
          assert isinstance(
              task, FineTuningTask
          ), "Can only use a pretrained checkpoint for fine tuning tasks"
          task.set_pretrained_checkpoint(
              args.pretrained_checkpoint_path
          )
  
      # Configure hooks to do tensorboard logging, checkpoints and so on.
      # `configure_hooks` adds default hooks, while extra hooks can be specified
      # in config file and stored in `task.hooks`. Here, we merge them when we
      # set the final hooks of the task.
      task.set_hooks(configure_hooks(args, config) + task.hooks)
  
      # LocalTrainer is used for a single replica. DistributedTrainer will setup
      # training to use PyTorch's DistributedDataParallel.
      trainer_class = {"none": LocalTrainer, "ddp": DistributedTrainer}[
          args.distributed_backend
      ]
  
      trainer = trainer_class()
  
      logging.info(
          f"Starting training on rank {get_rank()} worker. "
          f"World size is {get_world_size()}"
      )
      # That's it! When this call returns, training is done.
      trainer.train(task)
  
      output_folder = Path(args.checkpoint_folder).resolve()
      logging.info("Training successful!")
      logging.info(
          f'Results of this training run are available at: "{output_folder}"'
      )
  
file_path: ClassyVision/classy_train.py
imports: import logging
  import os
  from datetime import datetime
  from pathlib import Path
  import torch
  from classy_vision.generic.distributed_util import get_rank, get_world_size
  from classy_vision.generic.opts import check_generic_args, parse_train_arguments
  from classy_vision.generic.registry_utils import import_all_packages_from_directory
  from classy_vision.generic.util import load_json
  from classy_vision.hooks import CheckpointHook, LossLrMeterLoggingHook, ModelComplexityHook, ProfilerHook, ProgressBarHook, TensorboardPlotHook, VisdomHook
  from classy_vision.tasks import build_task, FineTuningTask
  from classy_vision.trainer import DistributedTrainer, LocalTrainer
  from torchvision import set_image_backend, set_video_backend
label_desc: Use image node_id 1 for calling a global function with example usage: main(args, config) without return types