from torch import nn
class MyModel(nn.Module):
def __init__(self):
super().__init__()
self._add_module()
def _add_module(self):
self._modules['test'] = nn.Linear(3, 5)
m = MyModel()
print(m.test)
The result of the code above is exactly
Linear(in_features=3, out_features=5, bias=True)
I found this interesting. Why is this happening?