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.
docstr: Scale up the values in the given tensors.
code: def scale(
      self,
      tensors: Union["torch.Tensor", Iterable["torch.Tensor"]],
      inplace=False,
  ) -> Union["torch.Tensor", List["torch.Tensor"]]:
      """Scale up the values in the given tensors."""
      if not self._enabled:
          return cast("torch.Tensor", tensors)
  
      incorrect_type = ValueError(
          "Input to gradient scaling must be a Tensor or Iterable[Tensor]"
      )
  
      # Cache per-device scales to avoid unnecessary d2d copies of the current scale.
      scale_per_device: Dict["torch.device", "torch.Tensor"] = dict()
  
      if is_torch_array(tensors):
          tensor = cast("torch.Tensor", tensors)
          return self._scale_tensor(tensor, scale_per_device, inplace)
      elif isinstance(tensors, Iterable):
          scaled_tensors = []
  
          for tensor in tensors:
              if not is_torch_array(tensor):
                  raise incorrect_type
  
              scaled_tensors.append(
                  self._scale_tensor(tensor, scale_per_device, inplace)
              )
  
          return scaled_tensors
  
      raise incorrect_type
  
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 3 for calling the PyTorchGradScaler obj's underlying member method code with example usage: obj.scale(tensors, inplace) and returns: cast, self, scaled_tensors