docstr: Computes the loss given the prediction labels and the true labels.
  
  Parameters
  ---------
  y_pred
      Prediction labels.
  y_true
      True labels.
  
  Returns
  -------
  A tuple consisting of the total loss computed as a weighted sum of individual losses and a dictionary         of individual losses used of logging.
docstr_tok: ["Computes","the","loss","given","the","prediction","labels","and","the","true","labels",".","Parameters","--","--","--","--","-","y_pred","Prediction","labels",".","y_true","True","labels",".","Returns","--","--","--","-","A","tuple","consisting","of","the","total","loss","computed","as","a","weighted","sum","of","individual","losses","and","a","dictionary","of","individual","losses","used","of","logging","."]
code: def compute_loss(
      self,
      y_pred: Union[torch.Tensor, List[torch.Tensor]],
      y_true: Union[torch.Tensor, List[torch.Tensor]],
  ) -> Tuple[torch.Tensor, Dict[str, float]]:
      """
          Computes the loss given the prediction labels and the true labels.
  
          Parameters
          ---------
          y_pred
              Prediction labels.
          y_true
              True labels.
  
          Returns
          -------
          A tuple consisting of the total loss computed as a weighted sum of individual losses and a dictionary \
          of individual losses used of logging.
          """
      # compute loss
      if isinstance(self.loss, list):
          assert isinstance(y_pred, list)
          assert isinstance(y_true, list)
  
          loss = torch.tensor(0.0).to(
              self.device
          )  # necessary for mypy otherwise use `type: ignore`
          results = dict()
  
          for i, partial_loss in enumerate(self.loss):
              weight = (
                  self.loss_weights[i]
                  if len(self.loss_weights)
                  else 1.0
              )
              loss += weight * partial_loss(y_pred[i], y_true[i])
              results.update(
                  {
                      key: weight * val
                      for key, val in partial_loss.result().items()
                  }
              )
  
          # compute total loss
          results.update({"loss": sum(results.values())})
      else:
          assert isinstance(y_pred, torch.Tensor)
          assert isinstance(y_true, torch.Tensor)
  
          loss = self.loss(y_pred, y_true)
          results = self.loss.result()
  
      return loss, results
  
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 4 for calling the Model obj's underlying member method code with example usage: obj.compute_loss(y_pred, y_true) and returns: loss,  results