"docs/vscode:/vscode.git/clone" did not exist on "97b5e7fcc37ffd57da3f9daae0e320ba036dcafc"
Unverified Commit b33e705e authored by Min Xu's avatar Min Xu Committed by GitHub
Browse files

[minor] fixing exception on the error path (#984)


Co-authored-by: default avatarMin Xu <min.xu.public@gmail.com>
parent ae8a0bca
...@@ -147,6 +147,10 @@ class AdaScale(Optimizer): ...@@ -147,6 +147,10 @@ class AdaScale(Optimizer):
num_gradients_to_accumulate: int = 1, num_gradients_to_accumulate: int = 1,
debias_ewma: bool = True, debias_ewma: bool = True,
): ):
# Init hook_handles list, otherwise, a partial init'ed object may fail in ``__del__``.
self._hook_handles: List[Any] = []
# Init other fields.
self._optimizer = optimizer self._optimizer = optimizer
self._local_grad_sqr: Optional[torch.Tensor] = None self._local_grad_sqr: Optional[torch.Tensor] = None
self._world_size: int = ( self._world_size: int = (
...@@ -183,7 +187,7 @@ class AdaScale(Optimizer): ...@@ -183,7 +187,7 @@ class AdaScale(Optimizer):
self._scale = 1.0 # Assign to inform mypy about the typing of this variable. self._scale = 1.0 # Assign to inform mypy about the typing of this variable.
self.set_scale(self._world_size * self._num_grads_to_accum if scale is None else scale) self.set_scale(self._world_size * self._num_grads_to_accum if scale is None else scale)
self._hook_handles: List[Any] = [] # Safer to register hooks after all init actions are done.
self._hook() self._hook()
def _hook(self) -> None: def _hook(self) -> None:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment