Last active
April 21, 2016 03:53
-
-
Save pengsun/aa0c9ee1ad1e37f52032208e6ae28821 to your computer and use it in GitHub Desktop.
Revisions
-
pengsun revised this gist
Apr 21, 2016 . 1 changed file with 6 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ require'cunn' V = 30000 -- vocabulary size C = 500 -- output dim B = 100*500 -- #batches nloop = 3 @@ -21,15 +21,17 @@ gOutput = torch.CudaTensor(B, C):normal() function timing_module(input, m) time = torch.tic() for i = 1, nloop do m:updateOutput(input) end cutorch.synchronize() time = torch.toc(time) print(torch.type(m) .. ' fprop time ' .. time/nloop) time = torch.tic() for i = 1, nloop do m:accGradParameters(input, gOutput) end cutorch.synchronize() time = torch.toc(time) print(torch.type(m) .. ' bprop time ' .. time/nloop) end @@ -40,4 +42,4 @@ timing_module(input, lt) -- SparseLinear sl = nn.SparseLinear(V, C):cuda() timing_module(inputTable, sl) -
pengsun created this gist
Apr 20, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ -- nn.LookupTable vs nn.SparseLinear require'cunn' V = 30000 -- vocabulary size C = 500 -- output dim B = 100 -- #batches nloop = 3 -- onehot input input = torch.LongTensor(B):random(V):cuda() inputTable = {} for i = 1, B do inputTable[i] = torch.CudaTensor(1, 2) inputTable[i][1][1] = input[i] inputTable[i][1][2] = 1.0 end -- dense grad output gOutput = torch.CudaTensor(B, C):normal() function timing_module(input, m) time = torch.tic() for i = 1, nloop do m:forward(input) end time = torch.toc(time) print(torch.type(m) .. ' fprop time ' .. time/nloop) time = torch.tic() for i = 1, nloop do m:backward(input, gOutput) end time = torch.toc(time) print(torch.type(m) .. ' bprop time ' .. time/nloop) end -- LookupTable lt = nn.LookupTable(V, C):cuda() timing_module(input, lt) -- SparseLinear sl = nn.SparseLinear(V, C):cuda() timing_module(inputTable, sl)