Skip to content
This repository has been archived by the owner on Sep 27, 2020. It is now read-only.

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

Open
bkoyuncu opened this issue Aug 6, 2019 · 3 comments
Open

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

bkoyuncu opened this issue Aug 6, 2019 · 3 comments

Comments

@bkoyuncu
Copy link

bkoyuncu commented Aug 6, 2019

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

@Hzzone
Copy link

Hzzone commented Aug 11, 2019

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

@bkoyuncu
Copy link
Author

bkoyuncu commented Aug 12, 2019

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

@Hzzone
Copy link

Hzzone commented Aug 13, 2019

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)]

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants