You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[SoftmaxRegression] munmap_chunk(): invalid pointer during smr.Train() #1358
#1 0x00007f8759677cf7 in __GI_abort () at abort.c:90
#2 0x00007f87596b8f87 in __libc_message (action=action@entry=do_abort, fmt=fmt@entry=0x7f87597bec38 "%s\n") at ../sysdeps/posix/libc_fatal.c:181
#3 0x00007f87596bf27a in malloc_printerr (str=str@entry=0x7f87597c04f8 "munmap_chunk(): invalid pointer") at malloc.c:5354
#4 0x00007f87596bf72c in munmap_chunk (p=<optimized out>) at malloc.c:2845
#5 0x00000000004155c8 in arma::memory::release<double const> (mem=0x7fffffffe180) at /usr/include/armadillo_bits/memory.hpp:145
#6 arma::Mat<double>::~Mat (this=0x7fffffffd830) at /usr/include/armadillo_bits/Mat_meat.hpp:29
#7 0x0000000000419b05 in mlpack::regression::SoftmaxRegressionFunction::~SoftmaxRegressionFunction (this=0x7fffffffd6b0) at /usr/include/mlpack/methods/softmax_regression/softmax_regression_function.hpp:21
#8 0x0000000000414fbf in mlpack::regression::SoftmaxRegression::Train<mlpack::optimization::GradientDescent> (this=0x7fffffffde10, data=..., labels=..., numClasses=4, optimizer=...)
at /usr/include/mlpack/methods/softmax_regression/softmax_regression_impl.hpp:64
#9 0x000000000040add6 in mlpackMain () at mlpack.cpp:33
#10 0x000000000040aa2a in main (argc=2, argv=0x7fffffffe448) at /usr/include/mlpack/core/util/mlpack_main.hpp:68```
Further digging shows this error can be changed to Mat::init(): requested size is too large by changing numClasses in the initialization call of smr to 0
The code compiles and runs with error "Mat::init(): requested size is too large" and when run with valgrind, shows a move depending on uninitialized values arising from double mlpack::regression::SoftmaxRegression::Train<mlpack::optimization::L_BFGS>(arma::Mat<double> const&, arma::Row<unsigned long> const&, unsigned long, mlpack::optimization::L_BFGS) (softmax_regression_impl.hpp:53)
Ok, so I have done quite some digging on this and I am not to the bottom of it yet, but I have both a workaround and the information I need to keep digging.
The problem can be worked around (technically in an unsafe manner because it does not solve the actual problem) by moving the definition of arma::sp_mat groundTruth to the last member of SoftmaxRegressionFunction.
The smoking gun is this. When I run std::cout << "sizeof(arma::sp_mat): " << sizeof(arma::sp_mat) inside SoftmaxRegressionFunction::SoftmaxRegressionFunction() (i.e. in softmax_regression_function.cpp), I get:
sizeof(arma::sp_mat): 160
but when I run the same from softmax_regression_impl.hpp, I get:
sizeof(arma::sp_mat): 208
So the definitions of the class are different during compilation of mlpack and of the test program. And I haven't yet figured out exactly why that is. I'll keep you updated as I get deeper into it.
Ok, the real issue here is that when mlpack was compiled, it was compiled with OpenMP. But when you compile with g++, the -fopenmp option isn't specified. This happens to change the size of the Armadillo sparse matrix (which behaves differently with and without OpenMP). So, if you compile with -fopenmp, this should resolve the issue.
I'm now working on a patch that will at least issue a warning during compilation if mlpack was compiled with -fopenmp and the program linking against mlpack is not using OpenMP.
I opened #1382, which will issue a clear warning in situations like this. Once we merge that, I'll go ahead and release mlpack 3.0.1 and close this issue. Please do feel free to comment there (or here) if you have any input about the patch.
Activity
bqv commentedon Apr 7, 2018
Further digging shows this error can be changed to
Mat::init(): requested size is too largeby changing numClasses in the initialization call of smr to 0bqv commentedon Apr 8, 2018
Further yet digging shows uninitialized memory regions in valgrind when run on the following code with a much smaller dataset:
The code compiles and runs with error "Mat::init(): requested size is too large" and when run with valgrind, shows a move depending on uninitialized values arising from
double mlpack::regression::SoftmaxRegression::Train<mlpack::optimization::L_BFGS>(arma::Mat<double> const&, arma::Row<unsigned long> const&, unsigned long, mlpack::optimization::L_BFGS) (softmax_regression_impl.hpp:53)bqv commentedon Apr 8, 2018
More succinct example of this behaviour:
rickllyxu commentedon Apr 8, 2018
Different from your result, I runed the succinct version and got many undefined reference error. Can you tell me your compiling command?
manish7294 commentedon Apr 8, 2018
@bqv I tried all your examples with the dataset provided by you and got all of them working smoothly. I think it might be a dependency issue.
bqv commentedon Apr 8, 2018
I'm compiling with
clang++ -std=c++11 -g -O0 -c -o minimal.o minimal.cppandclang++ -g -o minimal minimal.o -lmlpack -lboost_program_options -larmadillo.bqv commentedon Apr 8, 2018
In case it is a dependency isssue, I'm running this on debian unstable with the packages:
rcurtin commentedon Apr 11, 2018
I reproduced this in a debian:sid Docker container. It's late now but I'll keep digging tomorrow.
rcurtin commentedon Apr 24, 2018
Ok, so I have done quite some digging on this and I am not to the bottom of it yet, but I have both a workaround and the information I need to keep digging.
The problem can be worked around (technically in an unsafe manner because it does not solve the actual problem) by moving the definition of
arma::sp_mat groundTruthto the last member ofSoftmaxRegressionFunction.The smoking gun is this. When I run
std::cout << "sizeof(arma::sp_mat): " << sizeof(arma::sp_mat)insideSoftmaxRegressionFunction::SoftmaxRegressionFunction()(i.e. insoftmax_regression_function.cpp), I get:but when I run the same from
softmax_regression_impl.hpp, I get:So the definitions of the class are different during compilation of mlpack and of the test program. And I haven't yet figured out exactly why that is. I'll keep you updated as I get deeper into it.
rcurtin commentedon Apr 25, 2018
Ok, the real issue here is that when mlpack was compiled, it was compiled with OpenMP. But when you compile with g++, the
-fopenmpoption isn't specified. This happens to change the size of the Armadillo sparse matrix (which behaves differently with and without OpenMP). So, if you compile with-fopenmp, this should resolve the issue.I'm now working on a patch that will at least issue a warning during compilation if mlpack was compiled with
-fopenmpand the program linking against mlpack is not using OpenMP.rcurtin commentedon Apr 26, 2018
I opened #1382, which will issue a clear warning in situations like this. Once we merge that, I'll go ahead and release mlpack 3.0.1 and close this issue. Please do feel free to comment there (or here) if you have any input about the patch.
rcurtin commentedon Apr 30, 2018
Fixed with the merge of #1382. I'll go ahead and release mlpack 3.0.1 as a bugfix with this incorporated shortly.