code: def profile_pretrained(
      pretrained_type,
      source,
      save_dir,
      audio_mockup_secs,
      batch_sizes,
      triangle_only=True,
      example_audio=None,
      export_logs=False,
  ):
      """Loops through the profiler settings and benchmarks the inference of a pretrained model.
  
      Reporting:
      - real time factor
      - peak memory (inference only)
  
      Logs:
      - shell w/ tabular profiler summary and targeted reporting
      - if export_logs: traces are stored in `log` folder
      - benchmark_real_time (file output)
      - memory_peaks (file output)
      """
      # Pretrained interface
      create_batch_data, call, pretrained = get_funcs_to_profile(
          pretrained_type, source, save_dir, example_audio
      )
  
      # Prepare table to write out profiling information
      realtime_factor = []
      memory_peaks = []
      us_in_s = 1000.0**2
      byte_in_GB = 1024.0**3
  
      # Comprehensive benchmarking
      for d, duration in enumerate(audio_mockup_secs):
          realtime_factor_row = []
          memory_peaks_row = []
          for b, bs in enumerate(batch_sizes):
              # skip expected heavy-loads
              if (
                  triangle_only
              ):  # this is a protection mechanism, since configs might explore exponentially
                  if (
                      (
                          b + d
                          >= (len(audio_mockup_secs) + len(batch_sizes))
                          / 2
                      )
                      and (d > 0)
                      and (b > 0)
                  ):
                      print(
                          f"\tskipped - duration: {duration:d}, batch_size: {bs:d}"
                      )
                      realtime_factor_row.append("_skip_")
                      memory_peaks_row.append("_skip_")
                      continue
  
              # where are we :)
              print(f"\nDuration: {duration:d}, batch_size: {bs:d}")
  
              # benchmarking
              kwargs = create_batch_data(
                  batch_size=bs, duration=duration
              )
              realtime = (
                  bs * us_in_s * duration
              )  # batches recorded x conversion factor x secs
  
              # Simulating batching and profiling it
              prof = (
                  export(profile_report())
                  if export_logs
                  else profile_report()
              )
              num_steps = 10  # profile_report scheduler needs 10 steps for seven recordings
              for _ in range(num_steps):
                  call(model=pretrained, **kwargs)
                  prof.step()
  
              # Gathering time and memory reports
              print(
                  prof.key_averages().table(
                      sort_by="cpu_time_total", row_limit=10
                  )
              )
  
              cpu_time, cuda_time = report_time(
                  prof, verbose=True, upper_control_limit=True
              )  # no need to avg #records
              cpu_mem, cuda_mem = report_memory(prof, verbose=True)
  
              if cuda_time == 0:  # CPU values only
                  realtime_factor_row.append(
                      f"{cpu_time / realtime:.2E}"
                  )
                  memory_peaks_row.append(
                      f"{cpu_mem / byte_in_GB:.2f} Gb"
                  )
              else:  # CPU + GPU values
                  realtime_factor_row.append(
                      f"{cpu_time / realtime:.2E} + {cuda_time / realtime:.2E}"
                  )
                  memory_peaks_row.append(
                      f"{cpu_mem / byte_in_GB:.2f} + {cuda_mem / byte_in_GB:.2f} Gb"
                  )
          realtime_factor.append(realtime_factor_row)
          memory_peaks.append(memory_peaks_row)
  
      # Store tables
      print("\n\tReal-time factor")
      with open("bechmark_realtime_factors.md", "w") as f:
          f.write(
              benchmark_to_markdown(
                  benchmark=realtime_factor,
                  columns=batch_sizes,
                  rows=audio_mockup_secs,
              )
          )
  
      print("\n\tPeak memory")
      with open("bechmark_memory_peaks.md", "w") as f:
          f.write(
              benchmark_to_markdown(
                  benchmark=memory_peaks,
                  columns=batch_sizes,
                  rows=audio_mockup_secs,
              )
          )
  
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 4 for calling a global function with example usage: profile_pretrained(pretrained_type, source, save_dir, audio_mockup_secs, batch_sizes, triangle_only, example_audio, export_logs) without return types