code: def get_funcs_to_profile(
      pretrained_type,
      source,
      save_dir,
      example_audio=None,
      example=None,
  ):
      """Creates per pretrained interface:
  
      pretrained - loaded model, to device
      prepare(batch_size, duration, sampling_rate=16000) - function handle to create dimensioned batch input
      call(model, **kwargs) - function handle to the inference function to be profiled
      """
  
      # Put all data directly to cpu/cuda
      device = torch.device(
          "cuda" if torch.cuda.is_available() else "cpu"
      )
  
      # Create prepare() and call() functions depending on model type
      if pretrained_type == "EncoderDecoderASR":
          return get_funcs_to_unary_input_classifier(
              cls=EncoderDecoderASR,
              source=source,
              save_dir=save_dir,
              call_func="transcribe_batch",
              example_audio=example_audio,
              device=device,
          )
  
      elif pretrained_type == "EncoderASR":
          return get_funcs_to_unary_input_classifier(
              cls=EncoderASR,
              source=source,
              save_dir=save_dir,
              call_func="transcribe_batch",
              example_audio=example_audio,
              device=device,
          )
  
      elif pretrained_type == "EndToEndSLU":  # untested
          return get_funcs_to_unary_input_classifier(
              cls=EndToEndSLU,
              source=source,
              save_dir=save_dir,
              call_func="decode_batch",
              example_audio=example_audio,
              device=device,
          )
  
      elif pretrained_type == "EncoderClassifier":  # untested
          return get_funcs_to_unary_input_classifier(
              cls=EncoderClassifier,
              source=source,
              save_dir=save_dir,
              call_func="classify_batch",
              example_audio=example_audio,
              device=device,
          )
  
      elif pretrained_type == "SpeakerRecognition":  # untested
          pretrained = SpeakerRecognition.from_hparams(
              source=source,
              savedir=save_dir,
              run_opts={"device": device},
          )
          if example_audio:
              example = pretrained.load_audio(example_audio)
  
          def prepare(
              batch_size, duration, num_wavs2=10, sampling_rate=16000
          ):
              """Prepares input data."""
              return {
                  "wavs1": torch.rand(
                      (batch_size, duration * sampling_rate),
                      device=device,
                  ),
                  "wavs2": torch.rand(
                      (num_wavs2, duration * sampling_rate),
                      device=device,
                  ),
                  "wav1_lens": torch.ones(batch_size),
                  "wav2_lens": torch.ones(num_wavs2),
              }
  
          def call(model, **kwargs):
              """Calls verify_batch."""
              model.verify_batch(**kwargs)
  
      elif pretrained_type == "VAD":  # untested
          # VAD boundary post-processing can introduce slightly more load (ignored here)
          return get_funcs_to_unary_input_classifier(
              cls=VAD,
              source=source,
              save_dir=save_dir,
              call_func="get_speech_prob_chunk",
              example_audio=example_audio,
              device=device,
          )
  
      elif pretrained_type == "SepformerSeparation":  # untested
          return get_funcs_to_unary_input_classifier(
              cls=SepformerSeparation,
              source=source,
              save_dir=save_dir,
              call_func="separate_batch",
              example_audio=example_audio,
              device=device,
              batch_label="mix",
              lengths_label=None,
          )
  
      elif pretrained_type == "SpectralMaskEnhancement":  # untested
          return get_funcs_to_unary_input_classifier(
              cls=SpectralMaskEnhancement,
              source=source,
              save_dir=save_dir,
              call_func="enhance_batch",
              example_audio=example_audio,
              device=device,
              batch_label="noisy",
              lengths_label="lengths",
          )
  
      elif pretrained_type == "SNREstimator":  # untested
          pretrained = SNREstimator.from_hparams(
              source=source,
              savedir=save_dir,
              run_opts={"device": device},
          )
          if example_audio:
              example = pretrained.load_audio(example_audio)
  
          def prepare(
              batch_size, duration, num_spks=2, sampling_rate=16000
          ):
              """Prepares input data."""
              return {
                  "mix": example[: duration * sampling_rate].repeat(
                      batch_size, 1
                  )
                  if example is not None
                  else torch.rand(
                      (batch_size, duration * sampling_rate),
                      device=device,
                  ),
                  "predictions": torch.rand(
                      (batch_size, duration * sampling_rate, num_spks),
                      device=device,
                  ),
              }
  
          def call(model, **kwargs):
              """Calls estimate_batch"""
              model.estimate_batch(**kwargs)
  
      else:  # pretrained_type must be part of SpeechBrain
          raise TypeError("Unknown pretrained model.")
  
      return prepare, call, pretrained
  
file_path: speechbrain/tools/profiling/profile.py
imports: import sys
  import torch
  import speechbrain
  from hyperpyyaml import load_hyperpyyaml
  from speechbrain.utils.profiling import profile_report, export, report_time, report_memory
  from speechbrain.inference import Pretrained, EncoderDecoderASR, EncoderASR, EndToEndSLU, EncoderClassifier, SpeakerRecognition, VAD, SepformerSeparation, SpectralMaskEnhancement, SNREstimator
  from typing import Optional, List
label_desc: Use image node_id 2 for calling a global function with example usage: get_funcs_to_profile(pretrained_type, source, save_dir, example_audio, example) and returns: prepare,  call,  pretrained, get_funcs_to_unary_input_classifier, get_funcs_to_unary_input_classifier, get_funcs_to_unary_input_classifier, get_funcs_to_unary_input_classifier, dict, get_funcs_to_unary_input_classifier, get_funcs_to_unary_input_classifier, get_funcs_to_unary_input_classifier, dict