If an instance of torch.nn.Parameter is assigned to an attribute of a torch.nn.Module, the parameters are added to the list of the module's parameters (and can be accessed through the module's .parameter() method:
importtorchclass M(torch.nn.Module):
def __init__(self):
super().__init__()
m = M()
m.p1 = torch.nn.Parameter(torch.tensor([ [1.1,2.2] , [3.3,4.4] ]))
m.p2 = torch.nn.Parameter(torch.tensor([ [5.5,6.6] , [7.7,8.8] ]))
for param in (m.parameters()):
print(param)