code: def main(args):  # pylint: disable=redefined-outer-name
      # pylint: disable=global-variable-undefined
      global meta_data_train, meta_data_eval, symbols, phonemes, speaker_mapping
      # Audio processor
      ap = AudioProcessor(**c.audio)
      if "characters" in c.keys():
          symbols, phonemes = make_symbols(**c.characters)
  
      # DISTRUBUTED
      if num_gpus > 1:
          init_distributed(
              args.rank,
              num_gpus,
              args.group_id,
              c.distributed["backend"],
              c.distributed["url"],
          )
      num_chars = len(phonemes) if c.use_phonemes else len(symbols)
  
      # load data instances
      meta_data_train, meta_data_eval = load_meta_data(c.datasets)
  
      # set the portion of the data used for training
      if "train_portion" in c.keys():
          meta_data_train = meta_data_train[
              : int(len(meta_data_train) * c.train_portion)
          ]
      if "eval_portion" in c.keys():
          meta_data_eval = meta_data_eval[
              : int(len(meta_data_eval) * c.eval_portion)
          ]
  
      # parse speakers
      (
          num_speakers,
          speaker_embedding_dim,
          speaker_mapping,
      ) = parse_speakers(c, args, meta_data_train, OUT_PATH)
  
      # setup model
      model = setup_model(
          num_chars,
          num_speakers,
          c,
          speaker_embedding_dim=speaker_embedding_dim,
      )
      optimizer = RAdam(
          model.parameters(),
          lr=c.lr,
          weight_decay=0,
          betas=(0.9, 0.98),
          eps=1e-9,
      )
      criterion = GlowTTSLoss()
  
      if args.restore_path:
          checkpoint = torch.load(args.restore_path, map_location="cpu")
          try:
              # TODO: fix optimizer init, model.cuda() needs to be called before
              # optimizer restore
              optimizer.load_state_dict(checkpoint["optimizer"])
              if c.reinit_layers:
                  raise RuntimeError
              model.load_state_dict(checkpoint["model"])
          except:  # pylint: disable=bare-except
              print(" > Partial model initialization.")
              model_dict = model.state_dict()
              model_dict = set_init_dict(
                  model_dict, checkpoint["model"], c
              )
              model.load_state_dict(model_dict)
              del model_dict
  
          for group in optimizer.param_groups:
              group["initial_lr"] = c.lr
          print(
              " > Model restored from step %d" % checkpoint["step"],
              flush=True,
          )
          args.restore_step = checkpoint["step"]
      else:
          args.restore_step = 0
  
      if use_cuda:
          model.cuda()
          criterion.cuda()
  
      # DISTRUBUTED
      if num_gpus > 1:
          model = DDP_th(model, device_ids=[args.rank])
  
      if c.noam_schedule:
          scheduler = NoamLR(
              optimizer,
              warmup_steps=c.warmup_steps,
              last_epoch=args.restore_step - 1,
          )
      else:
          scheduler = None
  
      num_params = count_parameters(model)
      print(
          "\n > Model has {} parameters".format(num_params), flush=True
      )
  
      if "best_loss" not in locals():
          best_loss = float("inf")
  
      # define dataloaders
      train_loader = setup_loader(ap, 1, is_val=False, verbose=True)
      eval_loader = setup_loader(ap, 1, is_val=True, verbose=True)
  
      global_step = args.restore_step
      model = data_depended_init(train_loader, model, ap)
      for epoch in range(0, c.epochs):
          c_logger.print_epoch_start(epoch, c.epochs)
          train_avg_loss_dict, global_step = train(
              train_loader,
              model,
              criterion,
              optimizer,
              scheduler,
              ap,
              global_step,
              epoch,
          )
          eval_avg_loss_dict = evaluate(
              eval_loader, model, criterion, ap, global_step, epoch
          )
          c_logger.print_epoch_end(epoch, eval_avg_loss_dict)
          target_loss = train_avg_loss_dict["avg_loss"]
          if c.run_eval:
              target_loss = eval_avg_loss_dict["avg_loss"]
          best_loss = save_best_model(
              target_loss,
              best_loss,
              model,
              optimizer,
              global_step,
              epoch,
              c.r,
              OUT_PATH,
          )
  
imports: import argparse
  import glob
  import os
  import sys
  import time
  import traceback
  from random import randrange
  import torch
  from torch.nn.parallel import DistributedDataParallel
  from torch.utils.data import DataLoader
  from torch.utils.data.distributed import DistributedSampler
  from TTS.tts.datasets.preprocess import load_meta_data
  from TTS.tts.datasets.TTSDataset import MyDataset
  from TTS.tts.layers.losses import GlowTTSLoss
  from TTS.tts.utils.generic_utils import check_config_tts, setup_model
  from TTS.tts.utils.io import save_best_model, save_checkpoint
  from TTS.tts.utils.measures import alignment_diagonal_score
  from TTS.tts.utils.speakers import parse_speakers
  from TTS.tts.utils.synthesis import synthesis
  from TTS.tts.utils.text.symbols import make_symbols, phonemes, symbols
  from TTS.tts.utils.visual import plot_alignment, plot_spectrogram
  from TTS.utils.audio import AudioProcessor
  from TTS.utils.console_logger import ConsoleLogger
  from TTS.utils.distribute import init_distributed, reduce_tensor
  from TTS.utils.generic_utils import KeepAverage, count_parameters, create_experiment_folder, get_git_branch, remove_experiment_folder, set_init_dict
  from TTS.utils.io import copy_model_files, load_config
  from TTS.utils.radam import RAdam
  from TTS.utils.tensorboard_logger import TensorboardLogger
  from TTS.utils.training import NoamLR, setup_torch_training_env
label_desc: Use image node_id 6 for calling a global function with example usage: main(args) without return types