code: def report_memory(handler: object, verbose=False):
      """Summary reporting of total time - see: torch.autograd.profiler_util"""
      # Aggregate CPU & CUDA time.
      """
      if isinstance(handler, FunctionEvent):
          events = handler
      elif
      """
      if isinstance(handler, profiler.profile):
          events = handler.events()
      elif hasattr(
          handler, "profiler"
      ):  # assumes speechbrain.core.Brain
          events = handler.profiler.events()
      else:
          raise TypeError(
              "Expected a FunctionEvent; profiler.profile, or a SpeechBrain."
          )
  
      """memory allocation during each time step is of relevance, e.g. for visualisation - time intensive for lots events
      mem_times = np.unique(
          [[x.time_range.start, x.time_range.end] for x in events]
      )
      cpu_memory = np.zeros_like(mem_times)
      cuda_memory = np.zeros_like(mem_times)
      for x in events:
          idx = (x.time_range.start <= mem_times) & (
              x.time_range.end >= mem_times
          )
          cpu_memory[idx] += x.cpu_memory_usage
          cuda_memory[idx] += x.cuda_memory_usage
  
      # variable names instead of labeling pandas' columns
      cpu_mem = np.max(cpu_memory)
      cuda_mem = np.max(cuda_memory)
      """
  
      cpu_mem = cuda_mem = 0
      for e in events:
          if len(e.cpu_children) == 0:
              leaf_cpu_mem = e.cpu_memory_usage
              leaf_cuda_mem = e.cuda_memory_usage
              parent = e.cpu_parent
              while parent is not None:
                  leaf_cpu_mem += parent.cpu_memory_usage
                  leaf_cuda_mem += parent.cuda_memory_usage
                  parent = parent.cpu_parent
              if leaf_cpu_mem > cpu_mem:
                  cpu_mem = leaf_cpu_mem
              if leaf_cuda_mem > cuda_mem:
                  cuda_mem = leaf_cuda_mem
  
      """
      if verbose:
          print("Peak CPU Mem: {}".format(_format_memory(cpu_mem)))
          if cuda_mem > 0:
              print("Peak CUDA Mem: {}".format(_format_memory(cuda_mem)))
      """
  
      return cpu_mem, cuda_mem
  
file_path: speechbrain/speechbrain/utils/profiling.py
imports: import numpy
  from copy import deepcopy
  from torch import profiler
  from functools import wraps
  from typing import Any, Callable, Iterable, Optional
label_desc: Use image node_id 11 for calling a global function with example usage: report_memory(handler, verbose) and returns: cpu_mem,  cuda_mem