3 from .optimizer
import Optimizer
7 """Implements Adadelta algorithm. 9 It has been proposed in `ADADELTA: An Adaptive Learning Rate Method`__. 12 params (iterable): iterable of parameters to optimize or dicts defining 14 rho (float, optional): coefficient used for computing a running average 15 of squared gradients (default: 0.9) 16 eps (float, optional): term added to the denominator to improve 17 numerical stability (default: 1e-6) 18 lr (float, optional): coefficient that scale delta before it is applied 19 to the parameters (default: 1.0) 20 weight_decay (float, optional): weight decay (L2 penalty) (default: 0) 22 __ https://arxiv.org/abs/1212.5701 25 def __init__(self, params, lr=1.0, rho=0.9, eps=1e-6, weight_decay=0):
27 raise ValueError(
"Invalid learning rate: {}".format(lr))
28 if not 0.0 <= rho <= 1.0:
29 raise ValueError(
"Invalid rho value: {}".format(rho))
31 raise ValueError(
"Invalid epsilon value: {}".format(eps))
32 if not 0.0 <= weight_decay:
33 raise ValueError(
"Invalid weight_decay value: {}".format(weight_decay))
35 defaults = dict(lr=lr, rho=rho, eps=eps, weight_decay=weight_decay)
36 super(Adadelta, self).__init__(params, defaults)
38 def step(self, closure=None):
39 """Performs a single optimization step. 42 closure (callable, optional): A closure that reevaluates the model 46 if closure
is not None:
49 for group
in self.param_groups:
50 for p
in group[
'params']:
55 raise RuntimeError(
'Adadelta does not support sparse gradients')
61 state[
'square_avg'] = torch.zeros_like(p.data)
62 state[
'acc_delta'] = torch.zeros_like(p.data)
64 square_avg, acc_delta = state[
'square_avg'], state[
'acc_delta']
65 rho, eps = group[
'rho'], group[
'eps']
69 if group[
'weight_decay'] != 0:
70 grad = grad.add(group[
'weight_decay'], p.data)
72 square_avg.mul_(rho).addcmul_(1 - rho, grad, grad)
73 std = square_avg.add(eps).sqrt_()
74 delta = acc_delta.add(eps).sqrt_().div_(std).mul_(grad)
75 p.data.add_(-group[
'lr'], delta)
76 acc_delta.mul_(rho).addcmul_(1 - rho, delta, delta)
def step(self, closure=None)