Skip to content

Commit cfb96f3

Browse files
committed
refactor: noise_norm
1 parent 2e30d3f commit cfb96f3

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

pytorch_optimizer/optimizer/ranger21.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ def step(self, closure: CLOSURE = None) -> LOSS:
245245
bias_correction1 = 1.0 - beta1 ** step # fmt: skip
246246
bias_correction2_sq = math.sqrt(1.0 - beta2 ** step) # fmt: skip
247247

248+
noise_norm: float = math.sqrt((1.0 + beta2) ** 2 + beta2 ** 2) # fmt: skip
249+
248250
# warm up
249251
lr = self.warm_up_dampening(lr, step)
250252

@@ -292,7 +294,6 @@ def step(self, closure: CLOSURE = None) -> LOSS:
292294
if self.use_softplus:
293295
de_nom = F.softplus(de_nom, beta=self.beta_softplus)
294296

295-
noise_norm: float = math.sqrt((1.0 + beta2) ** 2 + beta2 ** 2) # fmt: skip
296297
pn_momentum = grad_ma.mul(1.0 + 1.0).add(neg_grad_ma, alpha=-1.0).mul(1.0 / noise_norm)
297298
p.addcdiv_(pn_momentum, de_nom, value=-step_size)
298299

0 commit comments

Comments
 (0)