MCPcopy Create free account
hub / github.com/OpenGVLab/HumanBench / update_master_grads

Method update_master_grads

PATH/core/fp16/opt.py:543–554  ·  view source on GitHub ↗

Copy the ``.grad`` attribute from stored references to fp16 parameters to the ``.grad`` attribute of the fp32 master parameters that are directly updated by the optimizer. :attr:`update_master_grads` only needs to be called if ``fp16_optimizer_obj.backward`` was

(self)

Source from the content-addressed store, hash-verified

541 self.update_master_grads()
542
543 def update_master_grads(self):
544 """
545 Copy the ``.grad`` attribute from stored references to fp16 parameters to
546 the ``.grad`` attribute of the fp32 master parameters that are directly
547 updated by the optimizer. :attr:`update_master_grads` only needs to be
548 called if ``fp16_optimizer_obj.backward`` was called with
549 ``update_master_grads=False``.
550 """
551 self._model_grads_to_master_grads()
552
553 self.overflow = self.loss_scaler.unscale_and_update(self.param_groups,
554 self.loss_scale)
555
556 # Promote loss scale so it can be retrieved or set via
557 # "fp16_optimizer_instance.loss_scale"

Callers 1

backwardMethod · 0.95

Calls 2

unscale_and_updateMethod · 0.80

Tested by

no test coverage detected