hughperkins / clnn

OpenCL backend for Torch nn neural networks library
BSD 2-Clause "Simplified" License
125 stars 16 forks source link

LookupTable broken #32

Closed jcjohnson closed 8 years ago

jcjohnson commented 8 years ago

I think that some recent refactoring in torch/nn broke the backward pass for nn.LookupTable when running with cltorch. Here's a quick test case:

require 'torch'
require 'nn'
require 'cltorch'
require 'clnn'

local N, D, V = 3, 4, 5
local lookup_table = nn.LookupTable(V, D)
local x = torch.Tensor(N):random(V)
local dy = torch.randn(N, D)
local y = lookup_table:forward(x)
local dx = lookup_table:backward(x, dy)

local x_cl = x:cl()
local dy_cl = dy:cl()
lookup_table:cl()
local y_cl = lookup_table:forward(x)
local dx_cl = lookup_table:backward(x, dy)

This crashes with the error:

/home/justin/torch/install/bin/luajit: /home/justin/torch/install/share/lua/5.1/nn/LookupTable.lua:73: attempt to call field 'LookupTable_accGradParameters' (a nil value)
stack traceback:
    /home/justin/torch/install/share/lua/5.1/nn/LookupTable.lua:73: in function 'accGradParameters'
    /home/justin/torch/install/share/lua/5.1/nn/Module.lua:31: in function 'backward'
    foo.lua:17: in main chunk
    [C]: in function 'dofile'
    ...stin/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:131: in main chunk
    [C]: at 0x00406670

I tried updating torch, nn, cltorch, and clnn, but the error persists; I'm running on Ubuntu 14.04.

hughperkins commented 8 years ago

Tentatively fixed. Let me know if you suspect it suddenly became orders of magnitudes slower. You will need to update: clnn.

hughperkins commented 8 years ago

Nice project you have there! :-) For the opencl, seems it runs now. But slllloooowwwww, compared to the cuda version. Like, 6-10 times slower I think? The CUDA version is pretty nice :-)

jcjohnson commented 8 years ago

Thanks! Looks like your fix worked; everything runs just fine in OpenCL now. But you're right about the speed - opencl is about the same speed as CPU on my machine =(