Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add grid lstm #345

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions Grid2DLSTM.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ end

function Grid2DLSTM:__init( outputSize, nb_layers, dropout, tie_weights, rho, cell2gate)
parent.__init(self, rho or 9999)
self.inputSize = outputSize
self.inputSize = outputSize -- for compatibility with tostring function in AbstractRecurrent
self.outputSize = outputSize
self.should_tie_weights = tie_weights or true
self.dropout = dropout or 0
Expand Down Expand Up @@ -147,17 +147,24 @@ function Grid2DLSTM:buildModel()
end

function Grid2DLSTM:updateOutput(input)
if (self.step == 1) and not self.cells[0] then
-- the initial state of the cell/hidden states
print("Initializing the cell/hidden states")
self.cells = {[0] = {}}

for L=1,self.nb_layers do
local h_init = torch.zeros(input:size(1), self.outputSize):cuda()
table.insert(self.cells[0], h_init:clone())
table.insert(self.cells[0], h_init:clone()) -- extra initial state for prev_c
if self.step == 1 then
-- the initial state of the cell/hidden states
if self.userPrevCell then
-- print("Initializing the cell/hidden states with user previous cell")
self.cells = { [0] = self.userPrevCell }
else
-- print("Initializing the cell/hidden states with zero")
self.cells = {[0] = {}}

for L=1,self.nb_layers do
local h_init = torch.zeros(input:size(1), self.outputSize):cuda()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will have to fix this option so it can work without a gpu, i'm getting errors on cpu version

Copy link

@kenkit kenkit Sep 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried removing cuda() references but could not get it to work on the rnn-sin demo with 4x2 tensor/table

table.insert(self.cells[0], h_init:clone())
table.insert(self.cells[0], h_init:clone()) -- extra initial state for prev_c
end
end
end

local input_mem_cell = torch.zeros(input:size(1), self.outputSize):float():cuda()

local rnn_inputs = {input_mem_cell, input, unpack(self.cells[self.step-1])}
Expand Down