Search code examples
luamachine-learningdeep-learningtorch

Bug encountered When running Google's Deep Q Network Code


Google's Deep Q Network for Atari Games is here.

https://github.com/rahular/deepmind-dqn

When I run it with GPU setting

./run_gpu <game name>

I had this error

../torch/bin/luajit: ./convnet.lua:22: attempt to call local 'convLayer' (a nil value)
stack traceback:
    ./convnet.lua:22: in function 'network'
    ./NeuralQLearner.lua:89: in function '__init'
    ...einforcement_Learning/torch/share/lua/5.1/torch/init.lua:51: in function <...einforcement_Learning/torch/share/lua/5.1/torch/init.lua:47>
    [C]: at 0x7f419423d380
    ./initenv.lua:133: in function 'setup'
    train_agent.lua:52: in main chunk
    [C]: at 0x00406230

The code that caused this issue is in this file https://github.com/rahular/deepmind-dqn/blob/master/dqn/convnet.lua

and it is in this function

function create_network(args)

    local net = nn.Sequential()
    net:add(nn.Reshape(unpack(args.input_dims)))

    --- first convolutional layer
    local convLayer = nn.SpatialConvolution

    if args.gpu >= 0 then
        net:add(nn.Transpose({1,2},{2,3},{3,4}))
        convLayer = nn.SpatialConvolutionCUDA
    end

    net:add(convLayer(args.hist_len*args.ncols, args.n_units[1],
                        args.filter_size[1], args.filter_size[1],
                        args.filter_stride[1], args.filter_stride[1],1))
    net:add(args.nl())

The net:add(convLayer( is 22th line.

I used gpu setting so it seems

convLayer =  nn.SpatialConvolutionCUDA

caused convLayer to be nil.

Does anyone know why nn.SpatialConvolutionCUDA returns a nil ?


Solution

  • Did the code originally come with GPU support, or did you add it yourself?

    You should replaced the depreceated layers, i.e. replace:

    net:add(nn.Transpose({1,2},{2,3},{3,4}))
    convLayer = nn.SpatialConvolutionCUDA
    

    with

    convLayer = nn.SpatialConvolution
    

    Check the documentation for the layers.

    Edit: Use this branch, I fixed it for GPU support.