code: def inference(
      output_dir: str,
      batch_size: int,
      dtype: str,
      ngpu: int,
      seed: int,
      num_workers: int,
      log_level: Union[int, str],
      data_path_and_name_and_type: Sequence[Tuple[str, str, str]],
      key_file: Optional[str],
      train_config: Optional[str],
      model_file: Optional[str],
      use_teacher_forcing: bool,
      noise_scale: float,
      noise_scale_dur: float,
      allow_variable_data_keys: bool,
      vocoder_config: Optional[str] = None,
      vocoder_checkpoint: Optional[str] = None,
      vocoder_tag: Optional[str] = None,
  ):
      """Perform SVS model decoding."""
      assert check_argument_types()
      if batch_size > 1:
          raise NotImplementedError("batch decoding is not implemented")
      if ngpu > 1:
          raise NotImplementedError(
              "only single GPU decoding is supported"
          )
      logging.basicConfig(
          level=log_level,
          format="%(asctime)s (%(module)s:%(lineno)d) %(levelname)s: %(message)s",
      )
  
      if ngpu >= 1:
          device = "cuda"
      else:
          device = "cpu"
  
      # 1. Set random-seed
      set_all_random_seed(seed)
  
      # 2. Build model
      singingGenerate = SingingGenerate(
          train_config=train_config,
          model_file=model_file,
          use_teacher_forcing=use_teacher_forcing,
          noise_scale=noise_scale,
          noise_scale_dur=noise_scale_dur,
          vocoder_config=vocoder_config,
          vocoder_checkpoint=vocoder_checkpoint,
          dtype=dtype,
          device=device,
      )
  
      # 3. Build data-iterator
      loader = SVSTask.build_streaming_iterator(
          data_path_and_name_and_type,
          dtype=dtype,
          batch_size=batch_size,
          key_file=key_file,
          num_workers=num_workers,
          preprocess_fn=SVSTask.build_preprocess_fn(
              singingGenerate.train_args, False
          ),
          collate_fn=SVSTask.build_collate_fn(
              singingGenerate.train_args, False
          ),
          allow_variable_data_keys=allow_variable_data_keys,
          inference=True,
      )
  
      # 4. Start for-loop
      output_dir = Path(output_dir)
      (output_dir / "norm").mkdir(parents=True, exist_ok=True)
      (output_dir / "denorm").mkdir(parents=True, exist_ok=True)
      (output_dir / "speech_shape").mkdir(parents=True, exist_ok=True)
      (output_dir / "wav").mkdir(parents=True, exist_ok=True)
      (output_dir / "att_ws").mkdir(parents=True, exist_ok=True)
      (output_dir / "probs").mkdir(parents=True, exist_ok=True)
      (output_dir / "durations").mkdir(parents=True, exist_ok=True)
      (output_dir / "focus_rates").mkdir(parents=True, exist_ok=True)
  
      # Lazy load to avoid the backend error
      import matplotlib
  
      matplotlib.use("Agg")
      import matplotlib.pyplot as plt
      from matplotlib.ticker import MaxNLocator
  
      with NpyScpWriter(
          output_dir / "norm",
          output_dir / "norm/feats.scp",
      ) as norm_writer, NpyScpWriter(
          output_dir / "denorm", output_dir / "denorm/feats.scp"
      ) as denorm_writer, open(
          output_dir / "speech_shape/speech_shape", "w"
      ) as shape_writer, open(
          output_dir / "durations/durations", "w"
      ) as duration_writer, open(
          output_dir / "focus_rates/focus_rates", "w"
      ) as focus_rate_writer:
          for idx, (keys, batch) in enumerate(loader, 1):
              assert isinstance(batch, dict), type(batch)
              assert all(isinstance(s, str) for s in keys), keys
              _bs = len(next(iter(batch.values())))
              assert _bs == 1, _bs
  
              # Change to single sequence and remove *_length
              # because inference() requires 1-seq, not mini-batch.
              batch = {
                  k: v[0]
                  for k, v in batch.items()
                  if not k.endswith("_lengths")
              }
  
              logging.info(f"batch: {batch}")
              logging.info(f"keys: {keys}")
  
              start_time = time.perf_counter()
              output_dict = singingGenerate(**batch)
  
              key = keys[0]
              insize = next(iter(batch.values())).size(0) + 1
              if output_dict.get("feat_gen") is not None:
                  # standard text2mel model case
                  feat_gen = output_dict["feat_gen"]
                  logging.info(
                      "inference speed = {:.1f} frames / sec.".format(
                          int(feat_gen.size(0))
                          / (time.perf_counter() - start_time)
                      )
                  )
                  logging.info(
                      f"{key} (size:{insize}->{feat_gen.size(0)})"
                  )
  
                  norm_writer[key] = (
                      output_dict["feat_gen"].cpu().numpy()
                  )
                  shape_writer.write(
                      f"{key} "
                      + ",".join(
                          map(str, output_dict["feat_gen"].shape)
                      )
                      + "\n"
                  )
                  if output_dict.get("feat_gen_denorm") is not None:
                      denorm_writer[key] = (
                          output_dict["feat_gen_denorm"].cpu().numpy()
                      )
              else:
                  # end-to-end text2wav model case
                  wav = output_dict["wav"]
                  logging.info(
                      "inference speed = {:.1f} points / sec.".format(
                          int(wav.size(0))
                          / (time.perf_counter() - start_time)
                      )
                  )
                  logging.info(f"{key} (size:{insize}->{wav.size(0)})")
  
              if output_dict.get("duration") is not None:
                  # Save duration and fucus rates
                  duration_writer.write(
                      f"{key} "
                      + " ".join(
                          map(
                              str,
                              output_dict["duration"]
                              .long()
                              .cpu()
                              .numpy(),
                          )
                      )
                      + "\n"
                  )
  
              if output_dict.get("focus_rate") is not None:
                  focus_rate_writer.write(
                      f"{key} {float(output_dict['focus_rate']):.5f}\n"
                  )
  
              if output_dict.get("att_w") is not None:
                  # Plot attention weight
                  att_w = output_dict["att_w"].cpu().numpy()
  
                  if att_w.ndim == 2:
                      att_w = att_w[None][None]
                  elif att_w.ndim != 4:
                      raise RuntimeError(
                          f"Must be 2 or 4 dimension: {att_w.ndim}"
                      )
  
                  w, h = plt.figaspect(att_w.shape[0] / att_w.shape[1])
                  fig = plt.Figure(
                      figsize=(
                          w * 1.3 * min(att_w.shape[0], 2.5),
                          h * 1.3 * min(att_w.shape[1], 2.5),
                      )
                  )
                  fig.suptitle(f"{key}")
                  axes = fig.subplots(att_w.shape[0], att_w.shape[1])
                  if len(att_w) == 1:
                      axes = [[axes]]
                  for ax, att_w in zip(axes, att_w):
                      for ax_, att_w_ in zip(ax, att_w):
                          ax_.imshow(
                              att_w_.astype(np.float32), aspect="auto"
                          )
                          ax_.set_xlabel("Input")
                          ax_.set_ylabel("Output")
                          ax_.xaxis.set_major_locator(
                              MaxNLocator(integer=True)
                          )
                          ax_.yaxis.set_major_locator(
                              MaxNLocator(integer=True)
                          )
  
                  fig.set_tight_layout({"rect": [0, 0.03, 1, 0.95]})
                  fig.savefig(output_dir / f"att_ws/{key}.png")
                  fig.clf()
  
              if output_dict.get("prob") is not None:
                  # Plot stop token prediction
                  prob = output_dict["prob"].cpu().numpy()
  
                  fig = plt.Figure()
                  ax = fig.add_subplot(1, 1, 1)
                  ax.plot(prob)
                  ax.set_title(f"{key}")
                  ax.set_xlabel("Output")
                  ax.set_ylabel("Stop probability")
                  ax.set_ylim(0, 1)
                  ax.grid(which="both")
  
                  fig.set_tight_layout(True)
                  fig.savefig(output_dir / f"probs/{key}.png")
                  fig.clf()
              # TODO(kamo): Write scp
              if output_dict.get("wav") is not None:
                  sf.write(
                      f"{output_dir}/wav/{key}.wav",
                      output_dict["wav"].cpu().numpy(),
                      singingGenerate.fs,
                      "PCM_16",
                  )
  
      # remove files if those are not included in output dict
      if output_dict.get("feat_gen") is None:
          shutil.rmtree(output_dir / "norm")
      if output_dict.get("feat_gen_denorm") is None:
          shutil.rmtree(output_dir / "denorm")
      if output_dict.get("att_w") is None:
          shutil.rmtree(output_dir / "att_ws")
      if output_dict.get("duration") is None:
          shutil.rmtree(output_dir / "durations")
      if output_dict.get("focus_rate") is None:
          shutil.rmtree(output_dir / "focus_rates")
      if output_dict.get("prob") is None:
          shutil.rmtree(output_dir / "probs")
      if output_dict.get("wav") is None:
          shutil.rmtree(output_dir / "wav")
  
imports: import argparse
  import logging
  import shutil
  import sys
  import time
  from pathlib import Path
  from typing import Any, Dict, Optional, Sequence, Tuple, Union
  import numpy
  import soundfile
  import torch
  from typeguard import check_argument_types
  from espnet2.fileio.npy_scp import NpyScpWriter
  from espnet2.gan_svs.vits import VITS
  from espnet2.svs.singing_tacotron.singing_tacotron import singing_tacotron
  from espnet2.tasks.svs import SVSTask
  from espnet2.torch_utils.device_funcs import to_device
  from espnet2.torch_utils.set_all_random_seed import set_all_random_seed
  from espnet2.tts.utils import DurationCalculator
  from espnet2.utils import config_argparse
  from espnet2.utils.types import str2bool, str2triple_str, str_or_none
  from espnet.utils.cli_utils import get_commandline_args
label_desc: Use image node_id 1 for calling a global function with example usage: inference(output_dir, batch_size, dtype, ngpu, seed, num_workers, log_level, data_path_and_name_and_type, key_file, train_config, model_file, use_teacher_forcing, noise_scale, noise_scale_dur, allow_variable_data_keys, vocoder_config, vocoder_checkpoint, vocoder_tag) without return types