def step(self, closure=None):
loss = None<EOL>if closure is not None:<EOL><INDENT>loss = closure()<EOL><DEDENT>for group in self.param_groups:<EOL><INDENT>for p in group['<STR_LIT>']:<EOL><INDENT>if p.grad is None:<EOL><INDENT>continue<EOL><DEDENT>grad = p.grad.data<EOL>if grad.is_sparse:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>state = self.state[p]<EOL>if len(state) == <NUM_LIT:0>:<EOL><INDENT>state['<STR_LIT>'] = <NUM_LIT:0><EOL>state['<STR_LIT>'] = torch.ones_like(p.data)<EOL>if group['<STR_LIT>'] > <NUM_LIT:0>:<EOL><INDENT>state['<STR_LIT>'] = torch.zeros_like(p.data)<EOL><DEDENT>if group['<STR_LIT>']:<EOL><INDENT>state['<STR_LIT>'] = torch.zeros_like(p.data)<EOL><DEDENT><DEDENT>square_avg = state['<STR_LIT>']<EOL>alpha = group['<STR_LIT>']<EOL>state['<STR_LIT>'] += <NUM_LIT:1><EOL>if group['<STR_LIT>'] != <NUM_LIT:0>:<EOL><INDENT>grad = grad.add(group['<STR_LIT>'], p.data)<EOL><DEDENT>square_avg.mul_(alpha).addcmul_(<NUM_LIT:1> - alpha, grad, grad)<EOL>if group['<STR_LIT>']:<EOL><INDENT>grad_avg = state['<STR_LIT>']<EOL>grad_avg.mul_(alpha).add_(<NUM_LIT:1> - alpha, grad)<EOL>avg = square_avg.addcmul(-<NUM_LIT:1>, grad_avg, grad_avg).add(group['<STR_LIT>']).sqrt()<EOL><DEDENT>else:<EOL><INDENT>avg = square_avg.add(group['<STR_LIT>']).sqrt()<EOL><DEDENT>if group['<STR_LIT>'] > <NUM_LIT:0>:<EOL><INDENT>buf = state['<STR_LIT>']<EOL>buf.mul_(group['<STR_LIT>']).addcdiv_(grad, avg)<EOL>p.data.add_(-group['<STR_LIT>'], buf)<EOL><DEDENT>else:<EOL><INDENT>p.data.addcdiv_(-group['<STR_LIT>'], grad, avg)<EOL><DEDENT><DEDENT><DEDENT>return loss<EOL>
Performs a single optimization step.

        Arguments:
            closure (callable, optional): A closure that reevaluates the model
                and returns the loss.