class_docstr: A shard aware Grad Scaler which enables loss scaling with/without cpu_offload. This is a
  slight modification of the pytorch grad scaler.
  https://pytorch.org/docs/stable/amp.html#torch.cuda.amp.GradScaler
class_docstr_tok: ["A","shard","aware","Grad","Scaler","which","enables","loss","scaling","with\/without","cpu_offload",".","This","is","a","slight","modification","of","the","pytorch","grad","scaler",".","https",":","\/\/pytorch.org\/docs\/stable\/amp.html","#","torch.cuda.amp.GradScaler"]
docstr: Multiplies ('scales') a tensor or list of tensors by the scale factor.
  
  Returns scaled outputs.  If this instance of :class:`GradScaler` is not enabled, outputs are returned
  unmodified.
  
  Args:
      outputs (Tensor or iterable of Tensors):  Outputs to scale.
docstr_tok: ["Multiplies","(","'scales","'",")","a","tensor","or","list","of","tensors","by","the","scale","factor",".","Returns","scaled","outputs",".","If","this","instance","of",":","class",":","`","GradScaler","`","is","not","enabled",",","outputs","are","returned","unmodified",".","Args",":","outputs","(","Tensor","or","iterable","of","Tensors",")",":","Outputs","to","scale","."]
code: def scale(
      self, outputs: Union[torch.Tensor, List[torch.Tensor]]
  ) -> Union[torch.Tensor, abc.Iterable]:
      """
      Multiplies ('scales') a tensor or list of tensors by the scale factor.
  
      Returns scaled outputs.  If this instance of :class:`GradScaler` is not enabled, outputs are returned
      unmodified.
  
      Args:
          outputs (Tensor or iterable of Tensors):  Outputs to scale.
      """
      if not self._enabled:
          return outputs
  
      # Short-circuit for the common case.
      if isinstance(outputs, torch.Tensor):
          assert (
              outputs.is_cuda
              or outputs.device.type == "xla"
              or outputs.device.type == "cpu"
          )
          if self._scale is None:
              self._lazy_init_scale_growth_tracker(outputs.device)  # type: ignore
          assert self._scale is not None
          return outputs * self._scale.to(
              device=outputs.device, non_blocking=True
          )
  
      # Invoke the more complex machinery only if we're treating multiple outputs.
      stash: List[
          _GeneralMultiDeviceReplicator
      ] = []  # holds a reference that can be overwritten by apply_scale
  
      def apply_scale(
          val: Union[torch.Tensor, abc.Iterable]
      ) -> Union[torch.Tensor, abc.Iterable]:
          if isinstance(val, torch.Tensor):
              assert (
                  val.is_cuda
                  or val.device.type == "xla"
                  or val.device.type == "cpu"
              )
              if len(stash) == 0:
                  if self._scale is None:
                      self._lazy_init_scale_growth_tracker(val.device)  # type: ignore
                  assert self._scale is not None
                  stash.append(
                      _GeneralMultiDeviceReplicator(self._scale)
                  )
              return val * stash[0].get(val.device)
          elif isinstance(val, abc.Iterable):
              iterable = map(apply_scale, val)
              if isinstance(val, list) or isinstance(val, tuple):
                  return type(val)(iterable)
              else:
                  return iterable
          else:
              raise ValueError(
                  "outputs must be a Tensor or an iterable of Tensors"
              )
  
      return apply_scale(outputs)
  
imports: from collections import defaultdict
  import collections.abc
  from enum import Enum
  import logging
  from typing import Any, Dict, List, Optional, Union
  import warnings
  import torch
  from torch.cuda import FloatTensor
  from torch.cuda.amp.common import amp_definitely_not_available
  from torch.cuda.amp.grad_scaler import GradScaler
  import torch.distributed
  from torch.optim import Optimizer
  from torch.optim.sgd import SGD
  from fairscale.internal import torch_version
label_desc: Use image node_id 2 for calling the ShardedGradScaler obj's underlying member method code with example usage: obj.scale(outputs) and returns: apply_scale, outputs, unknown, unknown, type, iterable