code: def test_tracer(device):
      import torch
      from torch.optim import SGD
      from speechbrain.core import Brain
      from speechbrain.utils.profiling import profile, export
  
      @export
      @profile
      class SimpleBrain(Brain):
          def compute_forward(self, batch, stage):
              return self.modules.model(batch[0])
  
          def compute_objectives(self, predictions, batch, stage):
              return torch.nn.functional.l1_loss(predictions, batch[1])
  
      model = torch.nn.Linear(
          in_features=10, out_features=10, device=device
      )
      inputs = torch.rand(10, 10, device=device)
      targets = torch.rand(10, 10, device=device)
      train_set = ([inputs, targets],)
      valid_set = ([inputs, targets],)
      test_set = ([inputs, targets],)
  
      # Profiling: __init__ constructor and model training.
      brain = SimpleBrain(
          {"model": model},
          lambda x: SGD(x, 0.1),
          run_opts={"device": device},
      )
      brain.fit(
          epoch_counter=range(10),
          train_set=train_set,
          valid_set=valid_set,
      )
  
      # Pretrained example.
      class SimpleBrainUntracked(Brain):
          def compute_forward(self, batch, stage):
              return self.modules.model(batch[0])
  
          def compute_objectives(self, predictions, batch, stage):
              return torch.nn.functional.l1_loss(predictions, batch[1])
  
      # No tracing during __init__
      brain_or_pretrained = SimpleBrainUntracked(
          {"model": model},
          lambda x: SGD(x, 0.1),
          run_opts={"device": device},
      )
      profile(
          brain_or_pretrained, on_trace_ready=export(), with_stack=True
      )
      brain_or_pretrained.evaluate(test_set=test_set)
  
      # Set-up the profiler; hook it to the model, and benchmark inference.
      brain_or_pretrained2 = SimpleBrainUntracked(
          {"model": model},
          lambda x: SGD(x, 0.1),
          run_opts={"device": device},
      )
      logged_profiler = export(profile)
      assert brain_or_pretrained2.profiler is None
      logged_profiler(brain_or_pretrained2)
      brain_or_pretrained2.evaluate(test_set=test_set)
  
label_desc: Use image node_id 4 for calling a global function with example usage: test_tracer(device) and returns: self, torch, self, torch