class_docstr: A gradient scaler which uses dynamic loss scale
  
  Args:
      initial_scale (float): the initial loss scale, defaults to 2**16
      growth_factor (float): the multiplication factor for increasing loss scale, defaults to 2
      backoff_factor (float): the multiplication factor for decreasing loss scale, defaults to 0.5
      growth_interval (int): the number of steps to increase loss scale when no overflow occurs, defaults to 1000
      min_scale (float): the minimum loss scale, defaults to None
      max_scale (float): the maximum loss scale, defaults to None
      hysteresis (int):  the number of overflows before decreasing loss scale, defaults to 2
      verbose (bool): whether to log messages, defaults to False
class_docstr_tok: ["A","gradient","scaler","which","uses","dynamic","loss","scale","Args",":","initial_scale","(","float",")",":","the","initial","loss","scale",",","defaults","to","2","*","*","16","growth_factor","(","float",")",":","the","multiplication","factor","for","increasing","loss","scale",",","defaults","to","2","backoff_factor","(","float",")",":","the","multiplication","factor","for","decreasing","loss","scale",",","defaults","to","0.5","growth_interval","(","int",")",":","the","number","of","steps","to","increase","loss","scale","when","no","overflow","occurs",",","defaults","to","1000","min_scale","(","float",")",":","the","minimum","loss","scale",",","defaults","to","None","max_scale","(","float",")",":","the","maximum","loss","scale",",","defaults","to","None","hysteresis","(","int",")",":","the","number","of","overflows","before","decreasing","loss","scale",",","defaults","to","2","verbose","(","bool",")",":","whether","to","log","messages",",","defaults","to","False"]
code: def __init__(
      self,
      initial_scale: float = 2**16,
      growth_factor: float = 2,
      backoff_factor: float = 0.5,
      growth_interval: int = 1000,
      min_scale: Optional[float] = None,
      max_scale: Optional[float] = None,
      hysteresis: int = 2,
      verbose: bool = False,
  ):
      super().__init__(initial_scale, verbose)
      if min_scale:
          self._min_scale = torch.tensor(
              [min_scale],
              device=get_current_device(),
              dtype=torch.float,
          )
      else:
          self._min_scale = None
  
      if max_scale:
          self._max_scale = torch.tensor(
              [max_scale],
              device=get_current_device(),
              dtype=torch.float,
          )
      else:
          self._max_scale = None
  
      self._growth_factor = growth_factor
      self._backoff_factor = backoff_factor
      self._growth_interval = growth_interval
      self._growth_step = 0
      self._hysteresis = hysteresis
      self._hysteresis_step = 0
      self._sanity_checks()
  
file_path: ColossalAI/colossalai/amp/naive_amp/grad_scaler/dynamic_grad_scaler.py
imports: from typing import Optional
  import torch
  from colossalai.utils.device import get_current_device
  from .base_grad_scaler import BaseGradScaler
label_desc: Use image node_id 1 to create a new DynamicGradScaler object from inherited base classes: BaseGradScaler with example: obj = DynamicGradScaler(initial_scale, growth_factor, backoff_factor, growth_interval, min_scale, max_scale, hysteresis, verbose)