When I look through the codes, noticed that the main usage of model.register_parameter(name, param)
is assigning None
to the parameters. I have the following toy example:
class MyModel(nn.Module):
def __init__(self):
super().__init__()
self.register_parameter('t', None)
def forward(self, x):
pass
my_model = MyModel()
I thought that when I call list(my_model.named_parameters())
, I will see my parameter named t
. But the result is empty list. So 2 questions came to my mind:
-
Instead of
register_parameter(...)
, what about just usingself.t = None
.
PS: Ignoring that some sanity checksregister_parameter(...)
is using. pytorch/module.py at 7aa605ed92dbb726a2f285246369b0a17972ba12 · pytorch/pytorch · GitHub -
What about about using
self.t = nn.Parameter(None)
. In this case, evenlist(my_model.named_parameters())
is not empty
What is wrong with these approaches?