docstr: Compiles a model by setting the optimizer and the loss functions, loss weights and metrics to monitor
  the training of the model.
  
  Parameters
  ----------
  optimizer
      Optimizer to be used.
  loss
      Loss function to be used. Can be a list of the loss function which will be weighted and summed up to
      compute the total loss.
  loss_weights
      Weights corresponding to each loss function. Only used if the `loss` argument is a  list.
  metrics
      Metrics used to monitor the training process.
docstr_tok: ["Compiles","a","model","by","setting","the","optimizer","and","the","loss","functions",",","loss","weights","and","metrics","to","monitor","the","training","of","the","model",".","Parameters","--","--","--","--","--","optimizer","Optimizer","to","be","used",".","loss","Loss","function","to","be","used",".","Can","be","a","list","of","the","loss","function","which","will","be","weighted","and","summed","up","to","compute","the","total","loss",".","loss_weights","Weights","corresponding","to","each","loss","function",".","Only","used","if","the","`","loss","`","argument","is","a","list",".","metrics","Metrics","used","to","monitor","the","training","process","."]
code: def compile(
      self,
      optimizer: optim.Optimizer,
      loss: Union[Callable, List[Callable]],
      loss_weights: Optional[List[float]] = None,
      metrics: Optional[List[Metric]] = None,
  ):
      """
      Compiles a model by setting the optimizer and the loss functions, loss weights and metrics to monitor
      the training of the model.
  
      Parameters
      ----------
      optimizer
          Optimizer to be used.
      loss
          Loss function to be used. Can be a list of the loss function which will be weighted and summed up to
          compute the total loss.
      loss_weights
          Weights corresponding to each loss function. Only used if the `loss` argument is a  list.
      metrics
          Metrics used to monitor the training process.
      """
      self.optimizer = optimizer
      self.metrics = [] if (metrics is None) else metrics
      self.loss_weights = [] if (loss_weights is None) else loss_weights
      self.loss: Union[LossContainer, List[LossContainer]]
  
      if isinstance(loss, list):
          # check if the number of weights is the same as the number of partial losses
          if len(self.loss_weights) != len(loss):
              raise ValueError(
                  "The number of loss weights differs from the number of losses"
              )
  
          self.loss = []
          for i, partial_loss in enumerate(loss):
              self.loss.append(
                  LossContainer(partial_loss, name=f"output_{i+1}_loss")
              )
      else:
          self.loss = LossContainer(loss, name="loss")
  
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 2 for calling the Model obj's underlying member method code with example usage: obj.compile(optimizer, loss, loss_weights, metrics) without return types