(self, w, lr=None, momentum=None, weight_decay=0)
Creates instance of `SGD`.

        :param w: PyTorch model.
        :type w: torch.nn.Module
        :param lr: Learning rate.
        :type lr: float
        :param momentum: SGD momentum.
        :type momentum: float
        :param weight_decay: Weight decay amount (L2 regularation).
        :type weight_decay: float
Creates instance of `SGD`.
Creates instance of SGD .
def __init__(self, w, lr=None, momentum=None, weight_decay=0):
        """
        Creates instance of `SGD`.

        :param w: PyTorch model.
        :type w: torch.nn.Module
        :param lr: Learning rate.
        :type lr: float
        :param momentum: SGD momentum.
        :type momentum: float
        :param weight_decay: Weight decay amount (L2 regularation).
        :type weight_decay: float
        """
        if lr is None or momentum is None:
            raise ValueError('Learning rate and momentum are required')
        if lr < 0.0:
            raise ValueError('Invalid learning rate: {}'.format(lr))
        if momentum < 0.0:
            raise ValueError('Invalid momentum value: {}'.format(momentum))
        if weight_decay < 0.0:
            raise ValueError(
                'Invalid weight decay value: {}'.format(weight_decay))

        try:
            self.w = w.module
        except AttributeError:
            self.w = w

        self.lr = lr
        self.momentum = momentum
        self.weight_decay = weight_decay

        self.state = defaultdict(dict)
def __init__ ( self , w , lr = None , momentum = None , weight_decay = 0 ) : if lr is None or momentum is None : raise ValueError ( 'Learning rate and momentum are required' ) if lr < 0.0 : raise ValueError ( 'Invalid learning rate: {}' . format ( lr ) ) if momentum < 0.0 : raise ValueError ( 'Invalid momentum value: {}' . format ( momentum ) ) if weight_decay < 0.0 : raise ValueError ( 'Invalid weight decay value: {}' . format ( weight_decay ) ) try : self . w = w . module except AttributeError : self . w = w self . lr = lr self . momentum = momentum self . weight_decay = weight_decay self . state = defaultdict ( dict )