-
Notifications
You must be signed in to change notification settings - Fork 140
Description
In optim_modules.py, we see the following code:
self-adaptive-llms/optim_modules.py
Lines 13 to 15 in 03a41ae
| class OptimizationAlgorithm(abc.ABC): | |
| def __init__(self, **kwargs): | |
| nn.Module.__init__(self=self) |
where class OptimizationAlgorithm is calling init on nn.Module even though it doesn't inherit from it (but probably should inherit?).
Then, lower in the same file, we see class Reinforce:
self-adaptive-llms/optim_modules.py
Lines 45 to 49 in 03a41ae
| class Reinforce(OptimizationAlgorithm, nn.Module): | |
| def __init__( | |
| self, policy, gpu, max_grad_norm, lr, rw_norm, rw_clip, kl_ref_coeff, **kwargs | |
| ): | |
| nn.Module.__init__(self=self) |
which is also manually calling init on nn.Module and is explicitly inheriting from it.
I'm curious as to why you chose this pattern and what problem does it solve, or if this were incidental? It appears to be a non-standard pattern of initialization.
Would it make sense to have OptimizationAlgorithm inherit from nn.Module and call its init, and then have class Reinforce inherit from OptimizationAlgorithm and call its init, which will in turn, both inherit from and call init on nn.Module?
To simplify super class initialization with multiple inheritance, it's also possible to use super().__init__() without having to specify any of the superclasses, and it will take care of the ordering of parent class initialization.