class_docstr: FP16-safe cross entropy loss.
  
  This avoids overflow in the softmax by doing the operation in FP32.
class_docstr_tok: ["FP16-safe","cross","entropy","loss",".","This","avoids","overflow","in","the","softmax","by","doing","the","operation","in","FP32","."]
code: def __init__(
      self,
      weight: Optional[torch.Tensor] = None,
      ignore_index: int = -100,
      reduction: str = "none",
  ):
      # default ignore_index=-100 mimics pytorch's default in
      # torch.nn.functional.nll_loss
      super().__init__()
      self.register_buffer("weight", weight)  # type: ignore
      self.ignore_index = ignore_index
      self.reduction = reduction
  
imports: import math
  from itertools import chain
  from typing import Optional
  import parlai.utils.logging
label_desc: Use image node_id 1 to create a new FP16SafeCrossEntropy object from inherited base classes: torch.nn with example: obj = FP16SafeCrossEntropy(weight, ignore_index, reduction)