code: def main(args):
      utils.import_user_module(args)
  
      assert (
          args.max_tokens is not None or args.batch_size is not None
      ), "Must specify batch size either with --max-tokens or --batch-size"
  
      metrics.reset()
  
      np.random.seed(args.seed)
      utils.set_torch_seed(args.seed)
  
      if distributed_utils.is_master(args):
          checkpoint_utils.verify_checkpoint_directory(args.save_dir)
  
      # Print args
      logger.info(args)
  
      # Setup task, e.g., translation, language modeling, etc.
      task = tasks.setup_task(args)
  
      # Load valid dataset (we load training data below, based on the latest checkpoint)
      for valid_sub_split in args.valid_subset.split(","):
          task.load_dataset(valid_sub_split, combine=False, epoch=1)
  
      # Build model and criterion
      model = task.build_model(args)
      criterion = task.build_criterion(args)
      logger.info(model)
      logger.info(
          "task: {} ({})".format(args.task, task.__class__.__name__)
      )
      logger.info(
          "model: {} ({})".format(args.arch, model.__class__.__name__)
      )
      logger.info(
          "criterion: {} ({})".format(
              args.criterion, criterion.__class__.__name__
          )
      )
      logger.info(
          "num. model params: {} (num. trained: {})".format(
              sum(p.numel() for p in model.parameters()),
              sum(
                  p.numel()
                  for p in model.parameters()
                  if p.requires_grad
              ),
          )
      )
  
      # (optionally) Configure quantization
      if args.quantization_config_path is not None:
          quantizer = quantization_utils.Quantizer(
              config_path=args.quantization_config_path,
              max_epoch=args.max_epoch,
              max_update=args.max_update,
          )
      else:
          quantizer = None
  
      # Build trainer
      if args.model_parallel_size == 1:
          trainer = Trainer(args, task, model, criterion, quantizer)
      else:
          trainer = MegatronTrainer(args, task, model, criterion)
  
      logger.info(
          "training on {} devices (GPUs/TPUs)".format(
              args.distributed_world_size
          )
      )
      logger.info(
          "max tokens per GPU = {} and max sentences per GPU = {}".format(
              args.max_tokens, args.batch_size
          )
      )
  
      # Load the latest checkpoint if one is available and restore the
      # corresponding train iterator
      extra_state, epoch_itr = checkpoint_utils.load_checkpoint(
          args,
          trainer,
          # don't cache epoch iterators for sharded datasets
          disable_iterator_cache=task.has_sharded_data("train"),
      )
  
      # Train until the learning rate gets too small
      max_epoch = args.max_epoch or math.inf
      lr = trainer.get_lr()
      train_meter = meters.StopwatchMeter()
      train_meter.start()
  
      while lr > args.min_lr and epoch_itr.next_epoch_idx <= max_epoch:
          # train for one epoch
          valid_losses, should_stop = train(
              args, trainer, task, epoch_itr
          )
          if should_stop:
              break
  
          # only use first validation loss to update the learning rate
          lr = trainer.lr_step(epoch_itr.epoch, valid_losses[0])
  
          epoch_itr = trainer.get_train_iterator(
              epoch_itr.next_epoch_idx,
              # sharded data: get train iterator for next epoch
              load_dataset=task.has_sharded_data("train"),
              # don't cache epoch iterators for sharded datasets
              disable_iterator_cache=task.has_sharded_data("train"),
          )
      train_meter.stop()
      logger.info(
          "done training in {:.1f} seconds".format(train_meter.sum)
      )
  
imports: import argparse
  import logging
  import math
  import os
  import random
  import sys
  import numpy
  import torch
  from fairseq import checkpoint_utils, distributed_utils, options, quantization_utils, tasks, utils
  from fairseq.data import iterators
  from fairseq.logging import meters, metrics, progress_bar
  from fairseq.model_parallel.megatron_trainer import MegatronTrainer
  from .ls_fs_gcq_trainer import LSTrainer
label_desc: Use image node_id 1 for calling a global function with example usage: main(args) without return types