code: def main(args):
      logger.info(args)
  
      use_cuda = torch.cuda.is_available()
  
      # Load the data
      data = load_data(args.in_file)
      channels = args.channels.split(",")
      unit_sequences = [
          {
              channels[0]: d[channels[0]],
              channels[1]: d[channels[1]],
          }
          for d in data
      ]
      fnames = [d["audio"] for d in data]
      print(f"Found {len(data)} sequences from {args.in_file}")
  
      # Limit the prefix size
      if args.prefix_size is not None:
          print(f"Limit the prefix size to {args.prefix_size}")
          unit_sequences = [
              limit(codes, args.prefix_size) for codes in unit_sequences
          ]
  
      # Load model from ckpt
      print(f"Loading the SpeechDLM model from {args.ckpt}")
      model = SpeechDLM.from_pretrained(
          model_name_or_path=os.path.dirname(args.ckpt),
          checkpoint_file=os.path.basename(args.ckpt),
          data_name_or_path=args.data,
      )
      model.eval()
      if use_cuda:
          model.cuda()
  
      # Set batch sizes
      model.cfg.dataset.max_tokens = args.batch_max_tokens
      model.max_positions = args.batch_max_positions
      if args.batch_max_sentences is not None:
          model.cfg.dataset.batch_size = args.batch_max_sentences
  
      # Set seed (if needed)
      if args.seed is not None:
          utils.set_torch_seed(args.seed)
  
      # Sample from the SpeechDLM model
      print(
          f"Generating {len(unit_sequences)} sequences with SpeechDLM model...\n"
          f"Generation args: sampling={(not args.beam_search)}, "
          f"sampling_topk={args.sampling_topk}, sampling_topp={args.sampling_topp}, "
          f"beam={args.beam_size}, min_len={args.min_len}, "
          f"max_len_a={args.max_len_a}, max_len_b={args.max_len_b}, "
          f"temperature={args.temperature}, dur_temperature={args.dur_temperature}, "
          f"seed={args.seed}"
      )
      generated_units = model.sample(
          unit_sequences,
          sampling=(not args.beam_search),
          sampling_topk=args.sampling_topk,
          sampling_topp=args.sampling_topp,
          beam=args.beam_size,
          max_len_a=args.max_len_a,
          max_len_b=args.max_len_b,
          min_len=args.min_len,
          temperature=args.temperature,
          duration_temperature=args.dur_temperature,
          verbose=args.verbose,
          skip_invalid_size_inputs=args.skip_invalid_size_batch,
      )
  
      # Create the generated sequences
      generated_data = []
      for fname, gen_units in zip(fnames, generated_units):
          d = {"audio": fname + "-generated", **gen_units}
          generated_data.append(d)
  
      # Write the generated sequences
      print(f"Write the generated units to {args.out_file}")
      if args.out_file:
          os.makedirs(os.path.dirname(args.out_file), exist_ok=True)
      write_data(args.out_file, generated_data)
  
file_path: fairseq/examples/textless_nlp/dgslm/sample_speech_dlm.py
imports: import os
  import ast
  import argparse
  import logging
  import torch
  from fairseq import utils
  from fairseq.models.speech_dlm import SpeechDLM
label_desc: Use image node_id 4 for calling a global function with example usage: main(args) without return types