bgraysea
(Brent)
1
When is it ok to not call the super
constructor on extending (nn.)Module
From https://pytorch.org/docs/stable/generated/torch.nn.Module.html the example is
class Model(nn.Module):
def __init__(self):
super(Model, self).__init__()
However; I don’t see any call to super in
class RegModel(Module):
def __init__(self): self.a,self.b = nn.Parameter(torch.randn(1)),nn.Parameter(torch.randn(1))
Is the Module in RegModel(Module)
the same as nn.Module?
help(Module) gives alot of output; and looks like its directly from pytorch
bgraysea
(Brent)
2
Haha; the only difference between nn.Module (pytorch) and Module (fastai) is explained - https://github.com/fastai/fastai/blob/aaccca299b0dbf36a8fcf12d2f47430821f10a7d/fastai/torch_core.py#L569
class Module(nn.Module, metaclass=PrePostInitMeta):
"Same as `nn.Module`, but no need for subclasses to call `super().__init__`"