def METHOD_NAME(
    self, task: Optional[str], sequence: Tensor, sample_list: Dict[str, Tensor]
) -> Dict[str, Tensor]:
    """
    For a given task, compute the forward for each head
    associated with the task, compute the losses for
    each head, and sum the losses and scores
    """
    if isinstance(self.heads, nn.ModuleList):
        heads_modules_list = self.heads
        # list of losses, head_losses[i] is the loss name for outputs_list[i]
        head_losses = self.head_loss_names
        head_names = self.head_names
    else:
        heads_modules_list = self.heads[task]
        head_losses = self.head_loss_names[task]
        head_names = self.head_names[task]
    # list of dict( head outputs )
    outputs_list = [
        head(sequence, processed_sample_list=sample_list)
        for head in heads_modules_list
    ]
    assert len(head_losses) == len(outputs_list)
    # list of dict( losses, scores )
    processed_outputs_list = [
        self._process_head_output(outputs, loss_name, head_name, sample_list)
        for outputs, loss_name, head_name in zip(
            outputs_list, head_losses, head_names
        )
    ]
    def reduce_losses(accum_result, loss_dict):
        for loss_key, loss_val in loss_dict.items():
            if loss_key in accum_result:
                accum_result[loss_key] += loss_val
            else:
                accum_result[loss_key] = loss_val
    loss_result = {}
    for output in processed_outputs_list:
        reduce_losses(loss_result, output["losses"])
    results = {
        "losses": loss_result,
        "scores": sum(
            [output.get("scores", 0) for output in processed_outputs_list]
        ),
    }
    return results