clarification regarding Module:getParameters()

443 views
Skip to first unread message

Yossi Biton

unread,
Apr 30, 2015, 10:08:47 AM4/30/15
to tor...@googlegroups.com
i'm using getParameters() in order to train using optim.sgd. 
(btw, i have considered using nn.Optim from fbnn instead, but didn't love the idea of switching from the master branch of nn).

now, to my question...
from the documentation of nn.Module (https://github.com/torch/nn/blob/master/doc/module.md#flatparameters-flatgradparameters-getparameters):
Since the storage of every weight and gradWeight is changed, this function should be called only once on a given network.
 
when i start training getParameters is called once. 
in some cases i want to stop my training and start again with the same model - in that case getParameters is called again for the same model (but not in the same run).

model = torch.load('model.net')
params,gradParams = model:getParameters()

is it ok or something i should avoid ?

soumith

unread,
Apr 30, 2015, 10:52:11 AM4/30/15
to torch7 on behalf of Yossi Biton
That should be okay.



--
You received this message because you are subscribed to the Google Groups "torch7" group.
To unsubscribe from this group and stop receiving emails from it, send an email to torch7+un...@googlegroups.com.
To post to this group, send email to tor...@googlegroups.com.
Visit this group at http://groups.google.com/group/torch7.
For more options, visit https://groups.google.com/d/optout.

Yossi Biton

unread,
Apr 30, 2015, 11:25:01 AM4/30/15
to torch7 on behalf of smth chntla

Could you explain why is it ok ?
Based on the documentation you shouldnt call it twice with the same model.


You received this message because you are subscribed to a topic in the Google Groups "torch7" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/torch7/bqbvIKjG4PU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to torch7+un...@googlegroups.com.

soumith

unread,
Apr 30, 2015, 2:07:50 PM4/30/15
to torch7 on behalf of Yossi Biton
If you call it twice within the same model, the handles wrt the first call become invalid. This is not obvious to people usually.

For eaxmple:

x1,dx1 = model:getParameters()
x2,dx2 = model:getParameters()

Now only x2 and dx2 are valid.
x1 and dx1 are stale handles.

ama...@gmail.com

unread,
Jun 21, 2017, 4:57:41 AM6/21/17
to torch7
In what order are the parameters returned by calling getParameters() on a given module, could you please explain
In my case i need to set the forget gate bias of FastLSTM to 1 ,for that i need to know the order of the parameters
Reply all
Reply to author
Forward
0 new messages