code: def extract_loss(
      report: Dict[str, Any], loss_divisor: int
  ) -> torch.Tensor:
      loss_dict = report.losses
      assert len(loss_dict) != 0, (
          "Model returned an empty loss dict. "
          "Did you forget to (i) define losses in your model configuration or"
          "(ii) return losses dict from your model?"
      )
  
      # Since losses are batch averaged in MMF, this makes sure the
      # scaling is right.
      for key, value in loss_dict.items():
          value = value.mean() / loss_divisor
          report.losses[key] = value
  
      loss = sum(loss.mean() for loss in loss_dict.values())
      return loss
  
imports: import collections
  import gc
  import logging
  import math
  import os
  import sys
  import time
  import warnings
  from bisect import bisect
  from typing import Any, Callable, Dict
  import torch
  from mmf.utils.distributed import get_rank, get_world_size, is_xla
  from mmf.utils.file_io import PathManager
  from packaging import version
  from torch import nn, Tensor
label_desc: Use image node_id 21 for calling a global function with example usage: extract_loss(report, loss_divisor) and returns: loss