class_docstr: Gradient scaler for the PyTorch shim.
  
  Gradients with small magnitudes are not representable in half-precision and
  will underflow to zero. A gradient scaler counters this issue by scaling
  up the loss before backpropagation, increasing the gradients by the same
  magnitude. A large enough scale will avoid that the gradients underflow.
  The gradients are unscaled in single precision after backpropagation, to
  provide the unscaled gradients to the optimizer.
code: def _scale_tensor(
      self,
      tensor: "torch.Tensor",
      scale_per_device: Dict["torch.device", "torch.Tensor"],
      inplace: bool,
  ):
      if not has_torch_amp:
          raise ValueError(
              "Gradient scaling is not supported, requires capable GPU and torch>=1.9.0"
          )
  
      if not tensor.is_cuda:
          msg = (
              "Gradient scaling is only supported for CUDA tensors. "
              "If you are using PyTorch models, you can avoid this "
              "error by disabling mixed-precision support."
          )
          raise ValueError(msg)
  
      device = tensor.device
  
      if device not in scale_per_device:
          scale_per_device[device] = self._scale.to(device=device)
  
      scale = scale_per_device[device]
      if inplace:
          return tensor.mul_(scale)
      else:
          return tensor * scale
  
file_path: thinc/thinc/shims/pytorch_grad_scaler.py
imports: from typing import Dict, Iterable, List, Union, cast
  from ..compat import has_torch_amp, torch
  from ..util import is_torch_array
label_desc: Use image node_id 4 for calling the PyTorchGradScaler obj's underlying member method code with example usage: obj._scale_tensor(tensor, scale_per_device, inplace) and returns: tensor, unknown