Skip to content

do_nothing_optimizer

DoNothingOptimizer

Bases: torch.optim.Optimizer

An optimizer that doesn't do anything, i.e. step and zero_grad are empty functions.

Source code in pytorch_adapt\layers\do_nothing_optimizer.py
 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
class DoNothingOptimizer(torch.optim.Optimizer):
    """
    An optimizer that doesn't do anything,
    i.e. ```step``` and ```zero_grad``` are empty functions.
    """

    def __init__(self, *arg, **kwargs):
        self.param_groups = [{"lr": 0}]

    def step(self):
        """"""
        pass

    def zero_grad(self):
        """"""
        pass

    def state_dict(self):
        """"""
        return {}

    def load_state_dict(self, state_dict):
        """"""
        pass

    def __repr__(self):
        return "DoNothingOptimizer()"