@torch.no_grad()
def step(self, closure=None):
    'Performs a single optimization step.\n        Args:\n            closure (callable, optional): A closure that reevaluates the model\n                and returns the loss.\n        '
    loss = None
    if (closure is not None):
        with torch.enable_grad():
            loss = closure()
    for group in self.param_groups:
        weight_decay = group['weight_decay']
        momentum = group['momentum']
        dampening = group['dampening']
        nesterov = group['nesterov']
        for p in group['params']:
            if (p.grad is None):
                continue
            d_p = p.grad
            p_norm = torch.norm(p.data)
            g_norm = torch.norm(p.grad.data)
            if (weight_decay != 0):
                if ((p_norm != 0) and (g_norm != 0)):
                    lars_lr = (p_norm / ((g_norm + (p_norm * weight_decay)) + group['eps']))
                    lars_lr *= group['trust_coefficient']
                    d_p = d_p.add(p, alpha=weight_decay)
                    d_p *= lars_lr
            if (momentum != 0):
                param_state = self.state[p]
                if ('momentum_buffer' not in param_state):
                    buf = param_state['momentum_buffer'] = torch.clone(d_p).detach()
                else:
                    buf = param_state['momentum_buffer']
                    buf.mul_(momentum).add_(d_p, alpha=(1 - dampening))
                if nesterov:
                    d_p = d_p.add(buf, alpha=momentum)
                else:
                    d_p = buf
            p.add_(d_p, alpha=(- group['lr']))
    return loss
Performs a single optimization step.
Args:
    closure (callable, optional): A closure that reevaluates the model
        and returns the loss.
@torch.no_grad()
def step(self, closure=None):
    'Performs a single optimization step.\n        Args:\n            closure (callable, optional): A closure that reevaluates the model\n                and returns the loss.\n        '
    loss = None
    if (closure is not None):
        with torch.enable_grad():
            loss = closure()
    for group in self.param_groups:
        weight_decay = group['weight_decay']
        momentum = group['momentum']
        dampening = group['dampening']
        nesterov = group['nesterov']
        for p in group['params']:
            if (p.grad is None):
                continue
            d_p = p.grad
            p_norm = torch.norm(p.data)
            g_norm = torch.norm(p.grad.data)
            if (weight_decay != 0):
                if ((p_norm != 0) and (g_norm != 0)):
                    lars_lr = (p_norm / ((g_norm + (p_norm * weight_decay)) + group['eps']))
                    lars_lr *= group['trust_coefficient']
                    d_p = d_p.add(p, alpha=weight_decay)
                    d_p *= lars_lr
            if (momentum != 0):
                param_state = self.state[p]
                if ('momentum_buffer' not in param_state):
                    buf = param_state['momentum_buffer'] = torch.clone(d_p).detach()
                else:
                    buf = param_state['momentum_buffer']
                    buf.mul_(momentum).add_(d_p, alpha=(1 - dampening))
                if nesterov:
                    d_p = d_p.add(buf, alpha=momentum)
                else:
                    d_p = buf
            p.add_(d_p, alpha=(- group['lr']))
    return loss