class_docstr: A helper class for mixed precision training. This mixin is used in mixed precision optimizers.
  
  Attributes:
      dtype (torc.dtype): The expected dtype of the gradients.
  
  Examples:
      ```python
      class MyMixedPrecisionOptimizer(OptimizerWrapper):
          def __init__(self, optim: Optimizer):
              super().__init__(optim)
              self.mixed_precision = MixedPrecisionMixin()
  
          def backward(self, loss):
              loss = self.mixed_precision.pre_backward(loss)
              loss.backward()
  
          def backward_by_grad(self, tensor, grad):
              grad = self.mixed_precision.pre_backward_by_grad(tensor, grad)
              tensor.backward(grad)
  
          def step(self):
              if self.mixed_precision.should_skip_step():
                  self.zero_grad()
                  return
              div_scale = self.mixed_precision.get_grad_div_scale()
              # maybe clip grad here
              # maybe scale grad here
              self.optim.step()
  
          def zero_grad(self):
              self.mixed_precision.pre_zero_grad()
              return self.optim.zero_grad()
      ```
docstr: Called before backward.
  
  Args:
      loss (Tensor): Loss value.
  
  Returns:
      Tensor: Loss value (possibly scaled).
code: def pre_backward(self, loss: Tensor) -> Tensor:
      """Called before backward.
  
      Args:
          loss (Tensor): Loss value.
  
      Returns:
          Tensor: Loss value (possibly scaled).
      """
  
file_path: ColossalAI/colossalai/amp/naive_amp/mixed_precision_mixin/base.py
imports: from abc import ABC, abstractmethod
  import torch
  from torch import Tensor
label_desc: Use image node_id 1 for calling the MixedPrecisionMixin obj's underlying member method code with example usage: obj.pre_backward(loss) without return types