File size: 787 Bytes
bc75bfa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# The base class for all optimizers. Acts as an interface for the optimizers.

from abc import ABC, abstractmethod

class BaseOptimizer(ABC):
    """

    Base class for all optimizers.

    """

    @abstractmethod
    def step(self):
        """

        Perform a single optimization step.

        """
        pass

    @abstractmethod
    def zero_grad(self):
        """

        Clear the gradients of all optimized parameters.

        """
        pass

    @abstractmethod
    def state_dict(self):
        """

        Return the state of the optimizer as a dictionary.

        """
        pass

    @abstractmethod
    def load_state_dict(self, state_dict):
        """

        Load the optimizer state from a dictionary.

        """
        pass