code: def profile_optimiser(
      func: Optional[object] = None,
      class_hooks: Optional[Iterable[str]] = None,
  ):  # to diverge, define parameters from scratch: @schedule; @export & @profile
      """Pre-configured profiling for a detailed benchmark (better suitable for speed-optimisation than @profile_analyst)."""
      profiler_kwargs = {
          "schedule": schedule(),
          "on_trace_ready": None,
          "record_shapes": False,  # avoid: overheads
          "profile_memory": True,
          "with_stack": False,  # avoid: overheads
          "with_flops": False,  # only for: matrix multiplication & 2D conv; see: torch.autograd.profiler.profile
          "with_modules": True,
          "class_hooks": class_hooks,
      }
      wrapped_func = profile(func, **profiler_kwargs)
      # Polymorph: func is pretrained or an instance of Brain (assumed case)
      if hasattr(func, "HPARAMS_NEEDED") or not callable(func):
          return wrapped_func
      else:  # callable(func) - polymorph: __init__ Brain constructor -or- function to be wrapped
  
          @wraps(func)
          def wrapper(*args, **kwargs):
              """Implementation of the wrapper."""
              return wrapped_func(*args, **kwargs)
  
          return wrapper
  
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 8 for calling a global function with example usage: profile_optimiser(func, class_hooks) and returns: wrapped_func, wrapper, wrapped_func