LUA - attempt to index global 'jit' (a nil value) - lua

I am running ubuntu 16.04 on my machine.
And trying to run the following provided code, which always returns "attempt to index global 'jit' (a nil value)":
#!/usr/bin/env th
require 'torch'
require 'optim'
require 'paths'
require 'xlua'
require 'csvigo'
require 'nn'
require 'dpnn'
local opts = paths.dofile('opts.lua')
opt = opts.parse(arg)
print(opt)
torch.setdefaulttensortype('torch.FloatTensor')
if opt.cuda then
require 'cutorch'
require 'cunn'
cutorch.setDevice(opt.device)
end
opt.manualSeed = 2
torch.manualSeed(opt.manualSeed)
paths.dofile('dataset.lua')
paths.dofile('batch-represent.lua')
model = torch.load(opt.model)
model:evaluate()
if opt.cuda then
model:cuda()
end
repsCSV = csvigo.File(paths.concat(opt.outDir, "reps.csv"), 'w')
labelsCSV = csvigo.File(paths.concat(opt.outDir, "labels.csv"), 'w')
batchRepresent()
repsCSV:close()
labelsCSV:close()
I don't really understand why I am getting this error and how I can fix it.
What am I doing wrong?
full output
/home/yalishanda/torch/install/bin/lua: /home/yalishanda/openface/batch-represent/dataset.lua:130: attempt to index global 'jit' (a nil value)
stack traceback:
/home/yalishanda/openface/batch-represent/dataset.lua:130: in function '__init'
/home/yalishanda/torch/install/share/lua/5.2/torch/init.lua:91: in function </home/yalishanda/torch/install/share/lua/5.2/torch/init.lua:87>
[C]: in function 'dataLoader'
.../yalishanda/openface/batch-represent/batch-represent.lua:19: in function 'batchRepresent'
../batch-represent/main.lua:42: in main chunk
[C]: in function 'dofile'
...anda/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:150: in main chunk
[C]: in ?
^CTraceback (most recent call last):
File "./myScript.py", line 47, in <module>
ret, frameRGB = video_capture.read()

You seem to be running a normal Lua interpreter, but you need to be running LuaJIT (it provides the jit table that the modules used in the script expect to access). Since you are using Torch, make sure you use LuaJIT interpreter that is included with Torch and the issue should go away.

Related

neovim init.lua module "lua.plguins" not found

I'm in the configuration neovim
I added the configuration file in C:\Users\wupan\AppData\Local\nvim\init.lua
require("lua.plugins")
and C:\Users\wupan\AppData\Local\nvim\lua\plugins.lua
return require('packer').startup(function()
use "wbthomason/packer.nvim"
end)
After the start-up neovim
Error detected while processing C:\Users\wupan\AppData\Local\nvim\init.lua:
E5113: Error while calling lua chunk: C:\Users\wupan\AppData\Local\nvim\init.lua:1: module 'lua.plugins' not found:
no field package.preload['lua.plugins']
no file '.\lua\plugins.lua'
no file 'C:\Users\wupan\scoop\apps\neovim\current\bin\lua\lua\plugins.lua'
no file 'C:\Users\wupan\scoop\apps\neovim\current\bin\lua\lua\plugins\init.lua'
no file '.\lua\plugins.dll'
no file 'C:\Users\wupan\scoop\apps\neovim\current\bin\lua\plugins.dll'
no file 'C:\Users\wupan\scoop\apps\neovim\current\bin\loadall.dll'
no file '.\lua.dll'
no file 'C:\Users\wupan\scoop\apps\neovim\current\bin\lua.dll'
no file 'C:\Users\wupan\scoop\apps\neovim\current\bin\loadall.dll'
stack traceback:
[C]: in function 'require'
C:\Users\wupan\AppData\Local\nvim\init.lua:1: in main chunk
Press ENTER or type command to continue
May I ask why
I tried to install Lua test the require
scoop install lua
C:\Users\wupan\code\lua\test.lua
require("hello")
C:\Users\wupan\code\lua\hello.lua
print("hello world")
There are also problems
C:\Users\wupan\scoop\apps\lua\current\lua54.exe: .\test.lua:1: module 'hello' not found:
no field package.preload['hello']
no file 'C:\Users\wupan\scoop\apps\lua\current'
no file 'C:\Users\wupan\scoop\apps\lua\current'
stack traceback:
[C]: in function 'require'
.\test.lua:1: in main chunk
[C]: in ?
Problem analysis
Let's use the following example which you gave us:
C:\Users\wupan\AppData\Local\nvim\init.lua
require("lua.plugins")
C:\Users\wupan\AppData\Local\nvim\lua\plugins.lua
return require('packer').startup(function()
use "wbthomason/packer.nvim"
end)
And now let's take a look into your error message:
no file 'C:\Users\wupan\scoop\apps\neovim\current\bin\lua\lua\plugins.lua'
The important part is the bin\lua\lua thing here. It's because your
require("lua.plugins") starts to look up a directory in one of your runtime
path (see :h rtp for more information).
Solution
You just need to fix your content in
C:\Users\wupan\AppData\Local\nvim\init.lua to:
require("plugins")
because then neovim will look up a directory which is named plugins in
C:\Users\wupan\scoop\apps\neovim\current\bin\lua for example, since its in
your runtime path.
Little note
You can change your content from
C:\Users\wupan\AppData\Local\nvim\lua\plugins.lua to:
require('packer').startup(function()
use "wbthomason/packer.nvim"
end)
or how I did it:
local packer = require('packer')
packer.startup(function(use)
use 'wbthomason/packer.nvim'
end)
That makes it a little bit more readable in my opinion :)

SimilarityMeasure is an invalid module name

This is a follow-up to my earlier question Lua: Semantic Similarity using Neural Networks.
For Semantic similarity I've execute the following code,
include('Conv.lua')
modelTrained = torch.load("download_local_location/modelSTS.trained.th", 'ascii')
modelTrained.convModel:evaluate()
modelTrained.softMaxC:evaluate()
local linputs = torch.zeros(rigth_sentence_length, emd_dimension)
linpus = XassignEmbeddingValuesX
local rinputs = torch.zeros(left_sentence_length, emd_dimension)
rinpus = XassignEmbeddingValuesX
local part2 = modelTrained.convModel:forward({linputs, rinputs})
local output = modelTrained.softMaxC:forward(part2)
local val = torch.range(0, 5, 1):dot(output:exp())
return val/5
And Execute it using the following command in terminal,
> th similarity.lua
But the error it displays is,
while creating metatable similarityMeasure.Conv: bad argument #1 (similarityMeasure is an invalid module name)
stack traceback:
[C]: in function 'newmetatable'
/torch/install/share/lua/5.2/torch/init.lua:102: in function 'class'
.../textSimilarityConvNet-master/Conv.lua:1: in main chunk
[C]: in function 'dofile'
/torch/install/share/lua/5.2/paths/init.lua:84: in function 'dofile'
/torch/install/share/lua/5.2/torch/init.lua:49: in function 'include'
similarity.lua:1: in main chunk
[C]: in function 'dofile'
.../torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:150: in main chunk
[C]: in ?
First few lines in Conv.lua is,
local Conv = torch.class('similarityMeasure.Conv')
function Conv:__init(config)
self.mem_dim = config.mem_dim or 150
self.learning_rate = config.learning_rate or 0.01
self.batch_size = config.batch_size or 1 --25
self.num_layers = config.num_layers or 1
self.reg = config.reg or 1e-4
self.structure = config.structure or 'lstm' -- {lstm, bilstm}
self.sim_nhidden = config.sim_nhidden or 150
self.task = config.task or 'sic' -- or 'vid'
-- word embedding
self.emb_vecs = config.emb_vecs
self.emb_dim = config.emb_vecs:size(2)
Please guide me to solve this.
You are missing the similarityMeasure module (and likely other modules as well). I'm guessing that the things you are missing are dependencies that are not included with the default Torch installation. The installation instructions in the Github respository's readme file say the following:
Please install Torch deep learning library. We recommend this local
installation which includes all required packages our tool needs,
simply follow the instructions here: https://github.com/torch/distro
If you installed Torch some other way, try doing it using the linked distro instead and see if that fixes the problem.
It should work. Also the repo has been recently updated.
https://github.com/castorini/MP-CNN-Torch
Once you installed the torch library properly, then you can check and see the newly added/provided testDeployment.lua file, as an example to see how to use the trained model properly.

Torch 7/Lua cannot require a .so file, but package.loadlib() can

I get a problem when playing Torch 7 code. I have a shared library libhashnn.so file, and I want to load the functions in Torch 7 script, so I use this expression: require 'libhashnn', but the trepl gives an error.
However, if I use package.loadlibfunction, it does work. Here are the results, but I don't know why I can't use require, how can I use require to load lib successfully?
require'libhashnn'
/home/dazhen/torch/install/share/lua/5.1/trepl/init.lua:383: bad argument #1 to '?' (table expected, got string)
stack traceback:
[C]: in function 'error'
/home/dazhen/torch/install/share/lua/5.1/trepl/init.lua:383: in function 'require'
[string "_RESULT={require'libhashnn'}"]:1: in main chunk
[C]: in function 'xpcall'
/home/dazhen/torch/install/share/lua/5.1/trepl/init.lua:650: in function 'repl'
...zhen/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:199: in main chunk
and
f=package.loadlib('libhashnn.so' ,'luaopen_libhashnn')
[0.0195s]
th> f
function: 0x41630f38
Try calling the function that package.loadlib gives you. I bet you will then get the same error that you get when you use require.
To understand why: require does the equivalent of package.loadlib and then calls that function so that the module that you are loading can initialize itself. With just package.loadlib, this initialization is not done and so the error that occurs during initialization does not show up.
I don't know what hashnn is and so I cannot tell you why it is broken, but looking at /home/dazhen/torch/install/share/lua/5.1/trepl/init.lua line 383 might be a good start to figure out what is going on.

Lua throws error luajit: error loading module 'libpaths' from file

I have lua 5.2, Torch version 7, Ubuntu version 14.04 trusty Installed
I am trying to run the following code
++++++++++++++++++++++code++++++++++++++++++++++++++++++++++++++++++++
require 'neuralconvo' require 'xlua'
-- Load Dataset
print("--Loading Dataset")
dataset=neuralconvo.Dataset(neuralconvo.CornellMovieDiaogs("data/cornell_movie_diaogs"),
{ loadFirst = options.dataset,
minWordFreq = options.minWordFreq
})
--Build Model
model = neuralconvo.Seq2Seq(dataset.wordsCount, options.hiddenSize) model.goToken = dataset.goToken
model.eosToken=dataset.eosToken
--Training Parameters
model.criterion=nn.SequencerCriterion(nn.ClassNLLCriterion())
model.learningRaw = options.learningRate
model.momentum = otions.momentum
local decayFactor = (options.minLR - options.learningRate)/options.saturateEpoch local minMeanError = nil
--Enable Cuda
if options.cuda then
require 'cutorch'
require 'cunn'
elseif options.opencl then
require 'cltorch'
require 'clnn'
model:cl()
end
-- Train Model using backpropogation
for epoch = 1,options.maxEpoch do
local errors = torch.Tensor(dataset.examplesCount):fill(0)
local timer=torch.timer()
local i=1
for examples in dataset:batches(options.batchSize) do
collectgarbage()
for _, example in ipairs(examples) do
local input, target = unpack(examples) do
if options.cuda then
input = input:cuda()
target = target:cuda()
elseif options.opencl then
input = input:cl()
target = target:cl()
end
local err=model:train(input, target)
if err ~= err then
error("Invalid error! Exiting.")
end
errors[i] = err
xlua.progress(i, dataset.examplesCount)
i=i+1
end
end
timer:stop()
--Save the model if not Improved
if minMeanError == nil or errors:mean() < minMeanError then
print("\n(Saving model...)")
torch.save("data/model.t7",model)
minMeanError=errors:mean()
end
-- Update Learning Rate
model.learningRate = model.learningRate + decayFactor
model.learningRate = math.max(options.minLR,model.learningRate)
end
end
=============================================================
I get the following error
luajit: error loading module 'libpaths' from file '/home/guru99u2/torch/install/lib/lua/5.2/libpaths.so':
/home/guru99u2/torch/install/lib/lua/5.2/libpaths.so: undefined symbol: luaL_setfuncs
stack traceback:
[C]: at 0x00450240
[C]: in function 'require'
/home/guru99u2/torch/install/share/lua/5.2/paths/init.lua:1: in main chunk
[C]: in function 'require'
/home/guru99u2/torch/install/share/lua/5.2/torch/init.lua:12: in main chunk
[C]: in function 'require'
./neuralconvo.lua:1: in main chunk
[C]: in function 'require'
bot.lua:1: in main chunk
[C]: at 0x00404d60
Something went wrong during the installation process (or you didn't clean the previous version) as you are trying to use modules built for Lua 5.2 with the interpreter that supports Lua 5.1 ABI (LuaJIT in this case). As the result you get that error undefined symbol: luaL_setfuncs because the dynamic library expects to have the function, but the loaded interpreter doesn't provide it.
Torch supports both LuaJIT and Lua 5.2, but you need to run ./clean.sh script as indicated in the documentation when switching Lua versions.

Torch, testing issue - imagenet-multiGPU.torch

I am a newbies to torch. I have trainined my model according to 2 classes via this instruction https://github.com/soumith/imagenet-multiGPU.torch (number of classes is modifed) then, I wantted to test my model. These lines of codes are writen in instruction for testing:
dofile('donkey.lua')
img = testHook({loadSize}, 'test.jpg')
model = torch.load('model_10.t7')
if img:dim() == 3 then
img = img:view(1, img:size(1), img:size(2), img:size(3))
end
predictions = model:forward(img:cuda())
I got errors at the initial line of codes while I was trying to write.
When I try to write ;
th> dofile('donkey.lua')
I get these errors;
th> dofile("donkey.lua")
donkey.lua:18: attempt to index global 'opt' (a nil value)
stack traceback:
donkey.lua:18: in main chunk
[C]: in function 'dofile'
[string "_RESULT={dofile("donkey.lua")}"]:1: in main chunk
[C]: in function 'xpcall'
/home/leo/torch/install/share/lua/5.1/trepl/init.lua:651: in function 'repl'
...leo/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:199: in main chunk
[C]: at 0x00406670
I don't know what to do. Thanks for helping.
You need to run opts.lua before running donkey.lua using
th> dofile("opts.lua")
Check main.lua and make sure, you are not missing any other dependencies.

Resources