docstr: Fit method. Equivalent of a training loop.
  
  Parameters
  ----------
  trainloader
      Training data loader.
  epochs
      Number of epochs to train the model.
  
  Returns
  -------
  Final epoch monitoring metrics.
docstr_tok: ["Fit","method",".","Equivalent","of","a","training","loop",".","Parameters","--","--","--","--","--","trainloader","Training","data","loader",".","epochs","Number","of","epochs","to","train","the","model",".","Returns","--","--","--","-","Final","epoch","monitoring","metrics","."]
code: def fit(
      self, trainloader: DataLoader, epochs: int
  ) -> Dict[str, float]:
      """
      Fit method. Equivalent of a training loop.
  
      Parameters
      ----------
      trainloader
          Training data loader.
      epochs
          Number of epochs to train the model.
  
      Returns
      -------
      Final epoch monitoring metrics.
      """
      for epoch in range(epochs):
          print("Epoch %d/%d" % (epoch, epochs))
  
          # reset losses and metrics
          self._reset_loss()
          self._reset_metrics()
  
          # perform train steps in batches
          for data in tqdm(trainloader):
              if len(data) < 2:
                  raise ValueError(
                      "An input and at least a label should be provided"
                  )
  
              x = data[0]
              y = data[1] if len(data) == 2 else data[1:]
              metrics_vals = self.train_step(x, y)
  
          # print metrics
          print(Model._metrics_to_str(metrics_vals))
      return metrics_vals
  
imports: import torch
  import torch.nn
  import torch.optim
  from torch.utils.data import DataLoader
  from tqdm import tqdm
  from typing import List, Dict, Callable, Union, Tuple, Optional
  from alibi.models.pytorch.metrics import Metric, LossContainer
label_desc: Use image node_id 8 for calling the Model obj's underlying member method code with example usage: obj.fit(trainloader, epochs) and returns: metrics_vals