soumith / torch-ship-binaries

A page describing how to ship torch binaries without sharing the source code of your scripts.
17 stars 0 forks source link

In the step 5, it shows "module 'torch' not found", how to solve? #2

Closed nejyeah closed 8 years ago

nejyeah commented 8 years ago

I follow the introduction, but in the step 5, an error throws out. Messages as follows:

qlua: autopickScripts/1_data_particle.lua:0: module 'torch' not found:
    no field package.preload['torch']
    no file '/home/gpu-server2/torch/autopickScripts:'
    no file './torch.so'
    no file '/usr/local/lib/lua/5.1/torch.so'
    no file '/home/gpu-server2/torch/install/lib/lua/5.1/torch.so'
    no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
    [C]: at 0x7f5173137a20
    [C]: in function 'require'

So it means that the thirdparty has to install Torch?

soumith commented 8 years ago

No, if you use the torch distro, and send them the zip file that already includes torch, they dont need to install it separately.

soumith commented 8 years ago

it looks like your package.path is not correctly set.

what's the output for:

print(package.path) print(package.cpath)

nejyeah commented 8 years ago

It seems that package.path and package.cpath in the thirdparty have some values same as the source code computer. The print messages as follows:

hx@hx[torch] /home/hx/torch/install/bin/luajit test.lua                                       [12:18下午]
package.path:
./?.lua;/home/bioserver1/torch/install/share/luajit-2.1.0-alpha/?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;/home/bioserver1/torch/install/share/lua/5.1/?.lua;/home/bioserver1/torch/install/share/lua/5.1/?/init.lua
package.cpath:
./?.so;/usr/local/lib/lua/5.1/?.so;/home/bioserver1/torch/install/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so
hx@hx[torch] ./run.sh                                                                         [12:19下午]
/home/hx/torch/install/bin/luajit: relionScripts/autopick.lua:0: module 'torch' not found:
    no field package.preload['torch']
    no file './torch.lua'
    no file '/home/bioserver1/torch/install/share/luajit-2.1.0-alpha/torch.lua'
    no file '/usr/local/share/lua/5.1/torch.lua'
    no file '/usr/local/share/lua/5.1/torch/init.lua'
    no file '/home/bioserver1/torch/install/share/lua/5.1/torch.lua'
    no file '/home/bioserver1/torch/install/share/lua/5.1/torch/init.lua'
    no file './torch.so'
    no file '/usr/local/lib/lua/5.1/torch.so'
    no file '/home/bioserver1/torch/install/lib/lua/5.1/torch.so'
    no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
    [C]: in function 'require'
    relionScripts/autopick.lua: in function <relionScripts/autopick.lua:0>
    [C]: at 0x00406670
hx@hx[torch]  

The thirdparty computer is /home/hx/torch, the original computer is /home/bioserver1/torch, so the right value of package.path and package.cpath are ?

nejyeah commented 8 years ago

I change the run.sh as follows, just assign some values to LUA_PATH,LUA_CPATH.

  1 #!/bin/bash
  2 currdir=`dirname $0`
  3 currdir=$(cd "$currdir" && pwd)
  4 export LUA_PATH="$currdir/install/share/lua/5.1/?.lua;$currdir/install/share/lua/5.1/?/init.lua;./?.lu    a;$currdir/install/share/luajit-2.1.0-alpha/?.lua;;"
  5 export LUA_CPATH="$currdir/install/lib/lua/5.1/?.so;./?.so;;"
  6 export PATH=$currdir/install/bin/:$PATH
  7 export LD_LIBRARY_PATH=$currdir/install/lib/:$LD_LIBRARY_PATH
  8 export DYLD_LIBRARY_PATH=$currdir/install/lib/:$DYLD_LIBRARY_PATH
  9 $currdir/install/bin/luajit myScripts/test.lua $*

What I add are the line 4 and line 5, And When I run run.sh, a similar problem occurs. I am sure that the libtorch.so is exactly there. I wonder why load 'libtorch.so' failed.

hx@hx[torch] ./run.sh                                                                        
/home/hx/torch/install/bin/luajit: /home/hx/torch/install/share/lua/5.1/torch/init.lua:13: cannot load '/home/hx/torch/install/lib/lua/5.1/libtorch.so'
stack traceback:
    [C]: in function 'require'
    /home/hx/torch/install/share/lua/5.1/torch/init.lua:13: in main chunk
    [C]: in function 'require'
    relionScripts/autopick.lua: in function <relionScripts/autopick.lua:0>
    [C]: at 0x00406670
soumith commented 8 years ago

@nejyeah good point, in changing the LUA_PATH and LUA_CPATH, it was much needed. I'll add it to the README.

Why libtorch.so failed, I am not sure yet. It's possible that it's missing some symbols

soumith commented 8 years ago

A good way to debug that would be too run the following line on the target system. install/bin/luajit -e 'ffi=require "ffi"; ffi.load("install/lib/lua/5.1/libtorch.so")'

nejyeah commented 8 years ago

I have solved my problem and make it success to run my binary code in the target system. All you need is to change the run.sh. Assign some values to LUA_PATH and LUA_CPATH. Besides, i replace dofile(*.lua) to require '*' in my source code, for the reason of some path problem when you run the binary file.

1 #!/bin/bash
2 currdir=`dirname $0`
3 currdir=$(cd "$currdir" && pwd)
4 export LUA_PATH="$currdir/myScripts/?.lua;$currdir/install/share/lua/5.1/?.lua;$currdir/install/share/lua/5.1/?/init.lua;./?.lu    a;$currdir/install/share/luajit-2.1.0-alpha/?.lua;;"
5 export LUA_CPATH="$currdir/install/lib/lua/5.1/?.so;./?.so;;"
6 export PATH=$currdir/install/bin/:$PATH
7 export LD_LIBRARY_PATH=$currdir/install/lib/:$LD_LIBRARY_PATH
8 export DYLD_LIBRARY_PATH=$currdir/install/lib/:$DYLD_LIBRARY_PATH
9 $currdir/install/bin/luajit myScripts/test.lua $*

As you can see in line 4, I add an extra value "$currdir/myScripts/?.lua" to LUA_PATH. myScripts is the same as the DIR where i put the binary code.
As for the problem of " load 'libtorch.so' failed " I mentioned above, I have no idea because I have no access to the machine for the moment. Just forget it !