Convolutional_LSTM_PyTorch icon indicating copy to clipboard operation
Convolutional_LSTM_PyTorch copied to clipboard

Why Wci, Wcf, Wco are Variables rather than nn.Parameters

Open bkoyuncu opened this issue 6 years ago • 3 comments

Is there any reason for initializing Wci_o_f in ConvLSTMCell as autograd Variables rather than nn.Parameters

bkoyuncu avatar Aug 06 '19 10:08 bkoyuncu

You are right, plz refer to convLSTM.py#L14 which states the reason.

Hzzone avatar Aug 11 '19 06:08 Hzzone

Thank you for your comment. I am new to pytorch and your explanation is not very clear for me, can you elaborate on that? To my knowledge nn.Parameters are included in model.parameters() so that they are updated with each call of optimizer.step() (what do you mean by forever?) I suppose that Wci,Wcf,Wco also should be trainable in the network.

Paper for convlstm : https://arxiv.org/abs/1506.04214 and your explaination,

-if using requires_grad flag, torch.save will not save parameters in deed although it may be updated every epoch.
-Howerver, if you use declare an optimizer like Adam(model.parameters()),
-parameters will not be updated forever.

Thank you

bkoyuncu avatar Aug 12 '19 13:08 bkoyuncu

import torch
from torch import nn
class Net(nn.Module):
    def __init__(self):
        super(Net, self).__init__()
        self.w = torch.rand(2, 2)
        self.w.requires_grad = True

    def forward(self, x):
        return self.w*x
net = Net()
net(torch.rand(2, 2))
tensor([[0.0726, 0.2216],
        [0.3548, 0.8168]], grad_fn=<MulBackward0>)
list(net.parameters())
[]
net.w.requires_grad
True
class Net(nn.Module):
    def __init__(self):
        super(Net, self).__init__()
        self.w = nn.Parameter(torch.rand(2, 2))

    def forward(self, x):
        return self.w*x
net = Net()
list(net.parameters())
[Parameter containing:
 tensor([[0.8596, 0.7057],
         [0.6475, 0.5657]], requires_grad=True)]

Hzzone avatar Aug 13 '19 13:08 Hzzone