google / gemma.cpp

lightweight, standalone C++ inference engine for Google's Gemma models.
Apache License 2.0
5.9k stars 500 forks source link

Error at the end when compiling #49

Closed iSach closed 6 months ago

iSach commented 6 months ago

When compiling with make -j4 gemma, I get the following error.

[100%] Linking CXX executable gemma
CMakeFiles/gemma.dir/gemma.cc.o: In function `std::filesystem::__cxx11::path::path<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::filesystem::__cxx11::path>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::filesystem::__cxx11::path::format)':
gemma.cc:(.text._ZNSt10filesystem7__cxx114pathC2INSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES1_EERKT_NS1_6formatE[_ZNSt10filesystem7__cxx114pathC5INSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES1_EERKT_NS1_6formatE]+0x74): undefined reference to `std::filesystem::__cxx11::path::_M_split_cmpts()'
CMakeFiles/gemma.dir/gemma.cc.o: In function `std::unique_ptr<unsigned char [], hwy::AlignedFreer> gcpp::N_AVX3_ZEN4::GetCompressedWeights<gcpp::ConfigGemma7B>(gcpp::Path const&, gcpp::Path const&, hwy::ThreadPool&)':
gemma.cc:(.text._ZN4gcpp11N_AVX3_ZEN420GetCompressedWeightsINS_13ConfigGemma7BEEESt10unique_ptrIA_hN3hwy12AlignedFreerEERKNS_4PathESA_RNS5_10ThreadPoolE[_ZN4gcpp11N_AVX3_ZEN420GetCompressedWeightsINS_13ConfigGemma7BEEESt10unique_ptrIA_hN3hwy12AlignedFreerEERKNS_4PathESA_RNS5_10ThreadPoolE]+0x32): undefined reference to `std::filesystem::status(std::filesystem::__cxx11::path const&)'
gemma.cc:(.text._ZN4gcpp11N_AVX3_ZEN420GetCompressedWeightsINS_13ConfigGemma7BEEESt10unique_ptrIA_hN3hwy12AlignedFreerEERKNS_4PathESA_RNS5_10ThreadPoolE[_ZN4gcpp11N_AVX3_ZEN420GetCompressedWeightsINS_13ConfigGemma7BEEESt10unique_ptrIA_hN3hwy12AlignedFreerEERKNS_4PathESA_RNS5_10ThreadPoolE]+0x5a): undefined reference to `std::filesystem::status(std::filesystem::__cxx11::path const&)'
CMakeFiles/gemma.dir/gemma.cc.o: In function `std::unique_ptr<unsigned char [], hwy::AlignedFreer> gcpp::N_AVX3_ZEN4::GetCompressedWeights<gcpp::ConfigGemma2B>(gcpp::Path const&, gcpp::Path const&, hwy::ThreadPool&)':
gemma.cc:(.text._ZN4gcpp11N_AVX3_ZEN420GetCompressedWeightsINS_13ConfigGemma2BEEESt10unique_ptrIA_hN3hwy12AlignedFreerEERKNS_4PathESA_RNS5_10ThreadPoolE[_ZN4gcpp11N_AVX3_ZEN420GetCompressedWeightsINS_13ConfigGemma2BEEESt10unique_ptrIA_hN3hwy12AlignedFreerEERKNS_4PathESA_RNS5_10ThreadPoolE]+0x32): undefined reference to `std::filesystem::status(std::filesystem::__cxx11::path const&)'
gemma.cc:(.text._ZN4gcpp11N_AVX3_ZEN420GetCompressedWeightsINS_13ConfigGemma2BEEESt10unique_ptrIA_hN3hwy12AlignedFreerEERKNS_4PathESA_RNS5_10ThreadPoolE[_ZN4gcpp11N_AVX3_ZEN420GetCompressedWeightsINS_13ConfigGemma2BEEESt10unique_ptrIA_hN3hwy12AlignedFreerEERKNS_4PathESA_RNS5_10ThreadPoolE]+0x5a): undefined reference to `std::filesystem::status(std::filesystem::__cxx11::path const&)'
CMakeFiles/gemma.dir/gemma.cc.o: In function `std::unique_ptr<unsigned char [], hwy::AlignedFreer> gcpp::N_SSSE3::GetCompressedWeights<gcpp::ConfigGemma7B>(gcpp::Path const&, gcpp::Path const&, hwy::ThreadPool&)':
gemma.cc:(.text._ZN4gcpp7N_SSSE320GetCompressedWeightsINS_13ConfigGemma7BEEESt10unique_ptrIA_hN3hwy12AlignedFreerEERKNS_4PathESA_RNS5_10ThreadPoolE[_ZN4gcpp7N_SSSE320GetCompressedWeightsINS_13ConfigGemma7BEEESt10unique_ptrIA_hN3hwy12AlignedFreerEERKNS_4PathESA_RNS5_10ThreadPoolE]+0x32): undefined reference to `std::filesystem::status(std::filesystem::__cxx11::path const&)'
CMakeFiles/gemma.dir/gemma.cc.o:gemma.cc:(.text._ZN4gcpp7N_SSSE320GetCompressedWeightsINS_13ConfigGemma7BEEESt10unique_ptrIA_hN3hwy12AlignedFreerEERKNS_4PathESA_RNS5_10ThreadPoolE[_ZN4gcpp7N_SSSE320GetCompressedWeightsINS_13ConfigGemma7BEEESt10unique_ptrIA_hN3hwy12AlignedFreerEERKNS_4PathESA_RNS5_10ThreadPoolE]+0x5a): more undefined references to `std::filesystem::status(std::filesystem::__cxx11::path const&)' follow
collect2: error: ld returned 1 exit status
make[3]: *** [CMakeFiles/gemma.dir/build.make:133: gemma] Error 1
make[2]: *** [CMakeFiles/Makefile2:377: CMakeFiles/gemma.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:384: CMakeFiles/gemma.dir/rule] Error 2
make: *** [Makefile:189: gemma] Error 2

I am not sure how to fix this, I tried adding -lsdtdc++fs in CMakeCache.txt but it does not seem to have any effect, where should it be added?

Thanks in advance.

jan-wassenberg commented 6 months ago

Hi, it would have to be added to the linker flags, for example adding to the line target_link_libraries(gemma hwy hwy_contrib sentencepiece) in CMakeLists.txt, then rm -rf the build directory.

iSach commented 6 months ago

Hi, it would have to be added to the linker flags, for example adding to the line target_link_libraries(gemma hwy hwy_contrib sentencepiece) in CMakeLists.txt, then rm -rf the build directory.

Thank you for your answer. It worked! For those interested, here is the fixed line: target_link_libraries(gemma hwy hwy_contrib sentencepiece "stdc++fs")

When running the model, I get the following error, do you know why?

Abort at /home/sach/llm/gemma.cpp/util/app.h:39: Assert 0 == sched_setaffinity(0, sizeof(cset), &cset)
[1]    1019925 abort (core dumped)  ./gemma --tokenizer tokenizer.spm --model 2b-pt --compressed_weights 2b-pt.sb

I've correctly compiled for bfloat16 weights.

jan-wassenberg commented 6 months ago

Glad to hear compiling works. Huh, I have not yet seen setaffinity fail, but it is possible. Do you have any cpushield or offline CPUs? What kind of platform/CPU is it? You can safely comment out the assert part, or even the entire line (assert+setaffinity).

Code-keys commented 6 months ago

I do this to solve:

  1. target_link_libraries( gemma stdc++fs )
  2. or update clang-version to clang-10
iSach commented 6 months ago

Glad to hear compiling works. Huh, I have not yet seen setaffinity fail, but it is possible. Do you have any cpushield or offline CPUs? What kind of platform/CPU is it? You can safely comment out the assert part, or even the entire line (assert+setaffinity).

Thanks, it works perfectly without the assert.

This is a Slurm job instance, that might be why I guess! Thanks again for your help and time.

iSach commented 6 months ago

Glad to hear compiling works. Huh, I have not yet seen setaffinity fail, but it is possible. Do you have any cpushield or offline CPUs? What kind of platform/CPU is it? You can safely comment out the assert part, or even the entire line (assert+setaffinity).

Thanks, it works perfectly fine with the assert commented.

This is run within a Slurm job, which probably causes this, as it's restricted in terms of accessible CPUs?

jan-wassenberg commented 6 months ago

Thanks for sharing. That makes sense, changing to an fprintf warning.