ggerganov/llama.cpp

How to build the llamacpp's .so file separately and then pass it in the llama_cpp_python / wrapper libraries directly.

fastdaima opened this issue · 1 comments

Based on this discussion: abetlen/llama-cpp-python#1435 (Thanks abetlen and iamlemec )

I tried installing using,

cmake -DBUILD_SHARED_LIBS=ON -B build && cmake --build build --config Release

But getting error like ,

[ 15%] Linking CXX executable ../bin/test-tokenizer-0
/usr/bin/ld: ../common/libcommon.a(common.cpp.o): undefined reference to symbol 'pthread_setaffinity_np@@GLIBC_2.3.4'
/usr/bin/ld: /lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[2]: *** [tests/CMakeFiles/test-tokenizer-0.dir/build.make:99: bin/test-tokenizer-0] Error 1
make[1]: *** [CMakeFiles/Makefile2:1711: tests/CMakeFiles/test-tokenizer-0.dir/all] Error 2
make: *** [Makefile:146: all] Error 2

when I searched online, they asked me to include -pthread or -lpthread while building it.

Can anyone direct me to resolve this issue.

Hi Everyone,

I was able to resolve this issue, by adding -pthread cmake flag to CMakeLists.txt

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1c3b5c8e..9b1074de 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -154,7 +154,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED true)
 set(CMAKE_C_STANDARD 11)
 set(CMAKE_C_STANDARD_REQUIRED true)
 set(THREADS_PREFER_PTHREAD_FLAG ON)
-
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread")
 find_package(Threads REQUIRED)
 include(CheckCXXCompilerFlag)

then ran these commands, to build the .so files, then copied libllama.so and libggml_shared.so to env/lib/python_version/site-packages/llama_cpp

cmake -DLLAMA_STATIC=OFF -DBUILD_SHARED_LIBS=ON -DCMAKE_CXX_FLAGS=-fPIC -DCMAKE_C_FLAGS=-fPIC -DLLAMA_CCACHE=OFF -B build .
cmake --build build --config Release

After this , I was able to load the model in llama_cpp_python and use it.

Keeping this issue open, to check whether anyone else facing the issue while building the .so file.