megengine.amp.GradScaler.backward

GradScaler.backward(gm, y=None, dy=None, *, unscale_grad=True, update_scale='if_unscale_grad')[源代码]

A wrapper of GradManager’s backward, used to scale y’s grad and unscale parameters’ grads.

参数
  • gm (GradManager) – The to be wrapped GradManager.

  • y (Union[Tensor, List[Tensor], None]) – Same as GradManager backward’s y.

  • dy (Union[Tensor, List[Tensor], None]) – Same as GradManager backward’s dy. Will be multiplied by scale_factor.

  • unscale_grad (bool) – Whether do unscale at the same time. Could be False if needs to accumulate grads.

  • update_scale (bool) – Same as unscale’s update. Will be ignored if unscale_grad is False.