Last active
August 29, 2015 14:01
-
-
Save soumith/d5aeb2b5eef53e6d4a81 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'torch' | |
require 'nn' | |
require 'sys' | |
torch.setdefaulttensortype('torch.FloatTensor') | |
numInputNodes=30 | |
numBatches=64 | |
numHidden1=64 | |
numHidden2=128 | |
numOutputNodes=1 | |
-------------- Model ------------------------- | |
mlp = nn.Sequential() | |
mlp:add(nn.Linear(numInputNodes,numHidden1)) | |
mlp:add(nn.Linear(numHidden1,numHidden2)) | |
mlp:add(nn.Linear(numHidden2,numOutputNodes)) | |
mlp:add(nn.Sum(1)) -- sum over the batch dimension which is the first dimension | |
-------------- End of Model ------------------------- | |
input = torch.rand(numBatches,numInputNodes) -- Send in a batch of 8 frames of 4 numbers each | |
local count = 0 | |
local numRuns = 10 | |
for i=1,numRuns do-- do 10 runs for benchmarking | |
sys.tic() | |
out=mlp:forward(input) | |
count = count + sys.toc() | |
end | |
print('Time (in seconds) for forward() 1 sample using mlp-batch: ' .. count / numRuns) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment