(self, closure=None)
return loss
Performs a single optimization step.
        Arguments:
          closure (callable, optional): A closure that reevaluates the model
            and returns the loss.
Performs a single optimization step.
        Arguments:
          closure (callable, optional): A closure that reevaluates the model
            and returns the loss.
Performs a single optimization step . Arguments : closure ( callable optional ) : A closure that reevaluates the model and returns the loss .
def step(self, closure=None):
        """Performs a single optimization step.
        Arguments:
          closure (callable, optional): A closure that reevaluates the model
            and returns the loss.
        """
        loss = None
        if closure is not None:
            loss = closure()

        for group in self.param_groups:
            for p in group['params']:
                if p.grad is None:
                    continue

                grad = p.grad.data.float()
                state = self.state[p]

                # State initialization
                if len(state) == 0:
                    state['step'] = 0
                    # Exponential moving average of gradient values
                    state['exp_avg'] = grad.new().resize_as_(grad).zero_()
                    # Exponential moving average of squared gradient values
                    state['exp_avg_sq'] = grad.new().resize_as_(grad).zero_()
                    # Fp32 copy of the weights
                    state['fp32_p'] = p.data.float()

                exp_avg, exp_avg_sq = state['exp_avg'], state['exp_avg_sq']
                beta1, beta2 = group['betas']

                state['step'] += 1

                if group['weight_decay'] != 0:
                    grad = grad.add(group['weight_decay'], state['fp32_p'])

                # Decay the first and second moment running average coefficient
                exp_avg.mul_(beta1).add_(1 - beta1, grad)
                exp_avg_sq.mul_(beta2).addcmul_(1 - beta2, grad, grad)

                denom = exp_avg_sq.sqrt().add_(group['eps'])

                bias_correction1 = 1 - beta1 ** state['step']
                bias_correction2 = 1 - beta2 ** state['step']
                step_size = group['lr'] * \
                    math.sqrt(bias_correction2) / bias_correction1

                state['fp32_p'].addcdiv_(-step_size, exp_avg, denom)
                p.data = state['fp32_p'].half()

        return loss
def step ( self , closure = None ) : loss = None if closure is not None : loss = closure ( ) for group in self . param_groups : for p in group [ 'params' ] : if p . grad is None : continue grad = p . grad . data . float ( ) state = self . state [ p ] # State initialization if len ( state ) == 0 : state [ 'step' ] = 0 # Exponential moving average of gradient values state [ 'exp_avg' ] = grad . new ( ) . resize_as_ ( grad ) . zero_ ( ) # Exponential moving average of squared gradient values state [ 'exp_avg_sq' ] = grad . new ( ) . resize_as_ ( grad ) . zero_ ( ) # Fp32 copy of the weights state [ 'fp32_p' ] = p . data . float ( ) exp_avg , exp_avg_sq = state [ 'exp_avg' ] , state [ 'exp_avg_sq' ] beta1 , beta2 = group [ 'betas' ] state [ 'step' ] += 1 if group [ 'weight_decay' ] != 0 : grad = grad . add ( group [ 'weight_decay' ] , state [ 'fp32_p' ] ) # Decay the first and second moment running average coefficient exp_avg . mul_ ( beta1 ) . add_ ( 1 - beta1 , grad ) exp_avg_sq . mul_ ( beta2 ) . addcmul_ ( 1 - beta2 , grad , grad ) denom = exp_avg_sq . sqrt ( ) . add_ ( group [ 'eps' ] ) bias_correction1 = 1 - beta1 ** state [ 'step' ] bias_correction2 = 1 - beta2 ** state [ 'step' ] step_size = group [ 'lr' ] * math . sqrt ( bias_correction2 ) / bias_correction1 state [ 'fp32_p' ] . addcdiv_ ( - step_size , exp_avg , denom ) p . data = state [ 'fp32_p' ] . half ( ) return loss