code: def test_profile_class(device):
      import torch
      from torch.optim import SGD
      from speechbrain.core import Brain
      from speechbrain.utils.profiling import profile
  
      @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],)
  
      # Profiling: __init__ constructor.
      brain = SimpleBrain(
          {"model": model},
          lambda x: SGD(x, 0.1),
          run_opts={"device": device},
      )
      assert brain.profiler is not None
      assert brain.profiler.profiler is not None
      # assert len(brain.profiler.key_averages()) == 2
      # assert (brain.profiler.events().total_average().count >= 4)  # == 6  # before; config dependent: 7
      assert (
          len(brain.profiler.speechbrain_event_traces) == 1
      )  # set & filled by the @profile decorator
      """print(brain.profiler.key_averages().table(sort_by="cpu_time_total", row_limit=10))
      -------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------
                                             Name    Self CPU %      Self CPU   CPU total %     CPU total  CPU time avg    # of Calls
      -------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------
          aten::_has_compatible_shallow_copy_type        73.33%      11.000us        73.33%      11.000us       2.750us             4
                                         aten::to        26.67%       4.000us        26.67%       4.000us       2.000us             2
      -------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------
      Self CPU time total: 15.000us
      """
  
      # Profiling: fit() for train operations.
      # By default, @profile should also annotate fit & evaluate functions; here the fit function is tested only.
      brain.fit(
          epoch_counter=range(10),
          train_set=train_set,
          valid_set=valid_set,
      )
      assert brain.profiler is not None
      # assert len(brain.profiler.key_averages()) >= 60  # 72 with torch==1.10.1
      # assert brain.profiler.events().total_average().count >= 2000  # 2832 with torch==1.10.1
      assert len(brain.profiler.speechbrain_event_traces) == 2
      # assert len(brain.profiler.speechbrain_event_traces[0]) >= 4  # == 6  # before; config dependent: 7
      # assert len(brain.profiler.speechbrain_event_traces[1]) >= 2000  # 2862 with torch==1.10.1
      """print(brain.profiler.key_averages().table(sort_by="cpu_time_total", row_limit=10))
      -------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------
                                                         Name    Self CPU %      Self CPU   CPU total %     CPU total  CPU time avg    # of Calls
      -------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------
                                                aten::l1_loss         2.60%     443.000us        26.15%       4.460ms     111.500us            40
      enumerate(DataLoader)#_SingleProcessDataLoaderIter._...        12.97%       2.212ms        20.28%       3.459ms      86.475us            40
                                                 aten::linear         1.28%     219.000us        12.97%       2.212ms     110.600us            20
                                                     aten::to         1.88%     320.000us        10.68%       1.822ms      11.387us           160
                                               aten::isfinite         1.98%     338.000us         9.82%       1.674ms      55.800us            30
                                                   aten::mean         1.10%     188.000us         9.31%       1.587ms      79.350us            20
                                               aten::_to_copy         5.65%     964.000us         8.99%       1.533ms      15.330us           100
                                                  aten::stack         2.23%     380.000us         8.67%       1.479ms      29.580us            50
                                                 aten::matmul         1.62%     277.000us         7.63%       1.301ms      65.050us            20
                                       aten::l1_loss_backward         1.24%     212.000us         6.78%       1.157ms      57.850us            20
      -------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------
      Self CPU time total: 17.054ms
      """
  
label_desc: Use image node_id 1 for calling a global function with example usage: test_profile_class(device) and returns: self, torch