code: def main(opt, device_id):
      """Start training on `device_id`."""
      # NOTE: It's important that ``opt`` has been validated and updated
      # at this point.
  
      configure_process(opt, device_id)
      init_logger(opt.log_file)
      checkpoint, vocabs, transforms_cls = _init_train(opt)
      model_opt = _get_model_opts(opt, checkpoint=checkpoint)
  
      # Build model.
      model = build_model(model_opt, opt, vocabs, checkpoint, device_id)
  
      model.count_parameters(log=logger.info)
      trainable = {
          "torch.float32": 0,
          "torch.float16": 0,
          "torch.uint8": 0,
          "torch.int8": 0,
      }
      non_trainable = {
          "torch.float32": 0,
          "torch.float16": 0,
          "torch.uint8": 0,
          "torch.int8": 0,
      }
      for n, p in model.named_parameters():
          if p.requires_grad:
              trainable[str(p.dtype)] += p.numel()
          else:
              non_trainable[str(p.dtype)] += p.numel()
      logger.info("Trainable parameters = %s" % str(trainable))
      logger.info("Non trainable parameters = %s" % str(non_trainable))
      logger.info(" * src vocab size = %d" % len(vocabs["src"]))
      logger.info(" * tgt vocab size = %d" % len(vocabs["tgt"]))
      if "src_feats" in vocabs:
          for i, feat_vocab in enumerate(vocabs["src_feats"]):
              logger.info(
                  f"* src_feat {i} vocab size = {len(feat_vocab)}"
              )
  
      # Build optimizer.
      optim = Optimizer.from_opt(model, opt, checkpoint=checkpoint)
  
      del checkpoint
  
      # Build model saver
      model_saver = build_model_saver(
          model_opt, opt, model, vocabs, optim, device_id
      )
  
      trainer = build_trainer(
          opt, device_id, model, vocabs, optim, model_saver=model_saver
      )
  
      offset = (
          max(0, device_id)
          if opt.parallel_mode == "data_parallel"
          else 0
      )
      stride = (
          max(1, len(opt.gpu_ranks))
          if opt.parallel_mode == "data_parallel"
          else 1
      )
  
      train_iter = build_dynamic_dataset_iter(
          opt,
          transforms_cls,
          vocabs,
          task=CorpusTask.TRAIN,
          copy=opt.copy_attn,
          stride=stride,
          offset=offset,
          device_id=device_id,
      )
  
      valid_iter = build_dynamic_dataset_iter(
          opt,
          transforms_cls,
          vocabs,
          task=CorpusTask.VALID,
          copy=opt.copy_attn,
          device_id=device_id,
      )
  
      if len(opt.gpu_ranks):
          logger.info("Starting training on GPU: %s" % opt.gpu_ranks)
      else:
          logger.info("Starting training on CPU, could be very slow")
      train_steps = opt.train_steps
      if opt.single_pass and train_steps > 0:
          logger.warning(
              "Option single_pass is enabled, ignoring train_steps."
          )
          train_steps = 0
  
      trainer.train(
          train_iter,
          train_steps,
          save_checkpoint_steps=opt.save_checkpoint_steps,
          valid_iter=valid_iter,
          valid_steps=opt.valid_steps,
      )
  
      if trainer.report_manager.tensorboard_writer is not None:
          trainer.report_manager.tensorboard_writer.close()
  
imports: import torch
  import sys
  from onmt.utils.logging import init_logger, logger
  from onmt.utils.parse import ArgumentParser
  from onmt.constants import CorpusTask
  from onmt.transforms import make_transforms, save_transforms, get_specials, get_transforms_cls
  from onmt.inputters import build_vocab
  from onmt.inputters.inputter import dict_to_vocabs, vocabs_to_dict
  from onmt.inputters.dynamic_iterator import build_dynamic_dataset_iter
  from onmt.inputters.text_corpus import save_transformed_sample
  from onmt.model_builder import build_model
  from onmt.models.model_saver import load_checkpoint
  from onmt.utils.optimizers import Optimizer
  from onmt.utils.misc import set_random_seed
  from onmt.trainer import build_trainer
  from onmt.models import build_model_saver
  from onmt.modules.embeddings import prepare_pretrained_embeddings
label_desc: Use image node_id 5 for calling a global function with example usage: main(opt, device_id) without return types