code: def main(args):
      assert (
          args.dump_features
          or args.dump_waveforms
          or args.dump_attentions
          or args.dump_eos_probs
          or args.dump_plots
      )
      if args.max_tokens is None and args.batch_size is None:
          args.max_tokens = 8000
      logger.info(args)
  
      use_cuda = torch.cuda.is_available() and not args.cpu
      task = tasks.setup_task(args)
      (
          models,
          saved_cfg,
          task,
      ) = checkpoint_utils.load_model_ensemble_and_task(
          [args.path],
          task=task,
          arg_overrides=ast.literal_eval(args.model_overrides),
      )
      model = models[0].cuda() if use_cuda else models[0]
      # use the original n_frames_per_step
      task.args.n_frames_per_step = saved_cfg.task.n_frames_per_step
      task.load_dataset(args.gen_subset, task_cfg=saved_cfg.task)
  
      data_cfg = task.data_cfg
      sample_rate = data_cfg.config.get("features", {}).get(
          "sample_rate", 22050
      )
      resample_fn = {
          False: lambda x: x,
          True: lambda x: torchaudio.sox_effects.apply_effects_tensor(
              x.detach().cpu().unsqueeze(0),
              sample_rate,
              [["rate", str(args.output_sample_rate)]],
          )[0].squeeze(0),
      }.get(args.output_sample_rate != sample_rate)
      if args.output_sample_rate != sample_rate:
          logger.info(f"resampling to {args.output_sample_rate}Hz")
  
      generator = task.build_generator([model], args)
      itr = task.get_batch_iterator(
          dataset=task.dataset(args.gen_subset),
          max_tokens=args.max_tokens,
          max_sentences=args.batch_size,
          max_positions=(sys.maxsize, sys.maxsize),
          ignore_invalid_inputs=args.skip_invalid_size_inputs_valid_test,
          required_batch_size_multiple=args.required_batch_size_multiple,
          num_shards=args.num_shards,
          shard_id=args.shard_id,
          num_workers=args.num_workers,
          data_buffer_size=args.data_buffer_size,
      ).next_epoch_itr(shuffle=False)
  
      Path(args.results_path).mkdir(exist_ok=True, parents=True)
      is_na_model = getattr(model, "NON_AUTOREGRESSIVE", False)
      dataset = task.dataset(args.gen_subset)
      vocoder = task.args.vocoder
      with progress_bar.build_progress_bar(args, itr) as t:
          for sample in t:
              sample = (
                  utils.move_to_cuda(sample) if use_cuda else sample
              )
              hypos = generator.generate(
                  model, sample, has_targ=args.dump_target
              )
              for result in postprocess_results(
                  dataset, sample, hypos, resample_fn, args.dump_target
              ):
                  dump_result(is_na_model, args, vocoder, *result)
  
file_path: fairseq/examples/speech_synthesis/generate_waveform.py
imports: import ast
  import logging
  import matplotlib.pyplot
  import numpy
  from pathlib import Path
  import soundfile
  import sys
  import torch
  import torchaudio
  from fairseq import checkpoint_utils, options, tasks, utils
  from fairseq.logging import progress_bar
  from fairseq.tasks.text_to_speech import plot_tts_output
  from fairseq.data.audio.text_to_speech_dataset import TextToSpeechDataset
label_desc: Use image node_id 4 for calling a global function with example usage: main(args) without return types