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

Element Research rnn benchmark ++ #5

Merged
merged 3 commits into from
Mar 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 4 additions & 2 deletions theano/rnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def recurrence(x_t, c_tm1, h_tm1):
seq_length = opts.seq_length
batch_size = opts.batch_size


start = time.time()
# Data

n_samples = 100000
Expand Down Expand Up @@ -261,7 +261,9 @@ def recurrence(x_t, c_tm1, h_tm1):
print 'compiling...'
f_test = theano.function(inputs=[index], outputs=output, givens={x: x_values[index:index + batch_size]})
f_train = theano.function(inputs=[index], outputs=cost, updates=updates, givens={x: x_values[index:index + batch_size], y: y_values[index:index + batch_size]})

f_train(1)
print "Setup : compile + forward/backward x 1"
print "--- %s seconds" % time.time() - start

start = time.time()
for k, i in enumerate(xrange(0, n_samples, batch_size)):
Expand Down
24 changes: 16 additions & 8 deletions torch/rnn.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,12 @@ end
local xBatches = xValues:split(batchSize, 1)
local yBatches = yValues:split(batchSize, 1)

local a = torch.Timer()
local rnn
if networkType == 'rnn' then
rnn = nn.Sequential()
:add(nn.ParallelTable()
:add(nn.Linear(inputSize, hiddenSize))
:add(nn.Linear(hiddenSize, hiddenSize)))
:add(nn.CAddTable())
:add(nn.JoinTable(1,1))
:add(nn.Linear(inputSize+hiddenSize, hiddenSize))
:add(nn.Sigmoid())
rnn = nn.Recurrence(rnn, hiddenSize, 1)
elseif networkType == 'lstm' then
Expand All @@ -53,17 +52,25 @@ if cpu ~= true then
criterion:cuda()
end

local start = os.clock()
local input = xBatches[1]:split(inputSize, 2)
criterion:forward(rnn:forward(input), yBatches[1])
rnn:backward(input, criterion:backward(rnn.output, yBatches[1]))
if cpu ~= true then cutorch.synchronize() end
print("Setup : compile + forward/backward x 1")
print("--- " .. a:time().real .. " seconds ---")

a:reset()
for i = 1, #xBatches do
if (i % 100 == 0) then
print(i)
end
rnn:forward(xBatches[i]:split(inputSize, 2))
end
if cpu ~= true then cutorch.synchronize() end
print("Forward:")
print("--- " .. nSamples .. " samples in " .. (os.clock() - start) .. " seconds (" .. nSamples / (os.clock() - start) .. " samples/s) ---")
print("--- " .. nSamples .. " samples in " .. a:time().real .. " seconds (" .. nSamples / a:time().real .. " samples/s) ---")

start = os.clock()
a:reset()
for i = 1, #xBatches do
if (i % 100 == 0) then
print(i)
Expand All @@ -74,5 +81,6 @@ for i = 1, #xBatches do
rnn:backward(input, criterion:backward(rnn.output, yBatches[i]))
rnn:updateParameters(0.01)
end
if cpu ~= true then cutorch.synchronize() end
print("Forward + Backward:")
print("--- " .. nSamples .. " samples in " .. (os.clock() - start) .. " seconds (" .. nSamples / (os.clock() - start) .. " samples/s) ---")
print("--- " .. nSamples .. " samples in " .. a:time().real .. " seconds (" .. nSamples / a:time().real .. " samples/s) ---")