Hi!
I implemented a model where one variable is defined inside the function nn.Parameter() in order to be used during the optimization process. However, when I request the list of variables defined in the model, that variable is not displayed.
Here is the class, in this case, the variable I need to optimize is W_ij:
class CapsNet(nn.Module):
	def __init__(self, r = 1):
		super(CapsNet, self).__init__()
		self.ReLUConv1 = nn.Sequential(
			nn.Conv2d(in_channels=1, out_channels=256, kernel_size=9, stride=1),
			nn.ReLU(inplace=True)
		)
		self.W_ij = nn.Parameter(torch.rand((32, 10, 6*6, 16, 8), requires_grad = True))
		self.PrimaryCaps = nn.ModuleList()
		self.r = r
		for _ in range(32):
			self.PrimaryCaps.append(nn.Conv2d(in_channels=256, out_channels=8, kernel_size=9, stride=2))
		self.decoder = nn.Sequential(
			nn.Linear(16*10, 512),
			nn.ReLU(inplace=True),
			nn.Linear(512, 1024),
			nn.ReLU(inplace=True),
			nn.Linear(1024, 784),
			nn.Sigmoid()
		)

	def forward(self)...

And here is the list of variables displayed by the model parameters output:
model = CapsNet()
model.parameters

<bound method Module.parameters of CapsNet(
  (ReLUConv1): Sequential(
	(0): Conv2d(1, 256, kernel_size=(9, 9), stride=(1, 1))
	(1): ReLU(inplace)
  )
  (PrimaryCaps): ModuleList(
	(0): Conv2d(256, 8, kernel_size=(9, 9), stride=(2, 2))
	(1): Conv2d(256, 8, kernel_size=(9, 9), stride=(2, 2))
	(2): Conv2d(256, 8, kernel_size=(9, 9), stride=(2, 2))
	(3): Conv2d(256, 8, kernel_size=(9, 9), stride=(2, 2))
	(4): Conv2d(256, 8, kernel_size=(9, 9), stride=(2, 2))
	(5): Conv2d(256, 8, kernel_size=(9, 9), stride=(2, 2))
	(6): Conv2d(256, 8, kernel_size=(9, 9), stride=(2, 2))
	(7): Conv2d(256, 8, kernel_size=(9, 9), stride=(2, 2))
	(8): Conv2d(256, 8, kernel_size=(9, 9), stride=(2, 2))
	(9): Conv2d(256, 8, kernel_size=(9, 9), stride=(2, 2))
	(10): Conv2d(256, 8, kernel_size=(9, 9), stride=(2, 2))
	(11): Conv2d(256, 8, kernel_size=(9, 9), stride=(2, 2))
	(12): Conv2d(256, 8, kernel_size=(9, 9), stride=(2, 2))
	(13): Conv2d(256, 8, kernel_size=(9, 9), stride=(2, 2))
	(14): Conv2d(256, 8, kernel_size=(9, 9), stride=(2, 2))
	(15): Conv2d(256, 8, kernel_size=(9, 9), stride=(2, 2))
	(16): Conv2d(256, 8, kernel_size=(9, 9), stride=(2, 2))
	(17): Conv2d(256, 8, kernel_size=(9, 9), stride=(2, 2))
	(18): Conv2d(256, 8, kernel_size=(9, 9), stride=(2, 2))
	(19): Conv2d(256, 8, kernel_size=(9, 9), stride=(2, 2))
	(20): Conv2d(256, 8, kernel_size=(9, 9), stride=(2, 2))
	(21): Conv2d(256, 8, kernel_size=(9, 9), stride=(2, 2))
	(22): Conv2d(256, 8, kernel_size=(9, 9), stride=(2, 2))
	(23): Conv2d(256, 8, kernel_size=(9, 9), stride=(2, 2))
	(24): Conv2d(256, 8, kernel_size=(9, 9), stride=(2, 2))
	(25): Conv2d(256, 8, kernel_size=(9, 9), stride=(2, 2))
	(26): Conv2d(256, 8, kernel_size=(9, 9), stride=(2, 2))
	(27): Conv2d(256, 8, kernel_size=(9, 9), stride=(2, 2))
	(28): Conv2d(256, 8, kernel_size=(9, 9), stride=(2, 2))
	(29): Conv2d(256, 8, kernel_size=(9, 9), stride=(2, 2))
	(30): Conv2d(256, 8, kernel_size=(9, 9), stride=(2, 2))
	(31): Conv2d(256, 8, kernel_size=(9, 9), stride=(2, 2))
  )
  (decoder): Sequential(
	(0): Linear(in_features=160, out_features=512, bias=True)
	(1): ReLU(inplace)
	(2): Linear(in_features=512, out_features=1024, bias=True)
	(3): ReLU(inplace)
	(4): Linear(in_features=1024, out_features=784, bias=True)
	(5): Sigmoid()
  )
)>

Only the variables defined in the sequential functions are defined as parameters of my model, but not the variable W_ij. In this regards, I have two questions:

How I can include the variable W_ij as a member of the set of parameters to be updated in the optimization step. So far, the loss function does not change during that part and I believe this is the reason.
Do I have to set  requires_grad = True in the definition of the variable despite it is included in the nn.Parameter function?

Any suggestions?
Henry