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

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.

Related

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

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.

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.

Lua: "Attempt to index a nill value"

Hi so I just installed Lua and I have been playing around with it a bit. When I run a program that is supposed to calculate whether an integer is even or odd it throws an error at me.
Program:
function is_even(n)
if bit32.band(n,1) == 0 then
print('Even')
else
print('Odd')
end
end
This is the error that I receive:
stdin:2: attempt to index a nil value (global 'bit32')
stack traceback:
stdin:2: in function 'is_even'
(...tail calls...)
[C]: in ?
What am i doing wrong here? This program is supposed to work on Lua 5.2+ I currently have Lua 5.3.3 installed.
The bit32 library was deleted from Lua 5.3, because it now supports bitwise operators.

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.

Missing functions in Table Library in Lua

When I run table.maxn() or table.getn() in Lua I get the errors below:
> table.maxn(a)
stdin:1: attempt to call a nil value (field 'maxn')
stack traceback:
stdin:1: in main chunk
[C]: in ?
> table.getn(a)
stdin:1: attempt to call a nil value (field 'getn')
stack traceback:
stdin:1: in main chunk
[C]: in ?
When I try to explore the contents of the table object I get the results below. It is almost as though some functions are missing from the library.
> for k,v in pairs(table) do
>> print (k)
>> end
remove
insert
move
sort
concat
unpack
pack
>
I am using Lua5.3 - from downloaded win32 binaries > Lua53.exe
I have confirmed that I did not alter / affect the table object in any way. The results above were obtained after restarting the Interpreter afresh.
What could the issue be?
You are using lua 5.3 but:
table.getn was deprecated in lua 5.1 (ref)
table.maxn was deprecated in lua 5.2 (ref)
You need to write valid code for the version of lua you are targetting.

Resources