pytorch / executorch

On-device AI across mobile, embedded and edge for PyTorch
https://pytorch.org/executorch/
Other
1.72k stars 293 forks source link

examples/models/llama2 - undefined reference to `pthread_once' #4113

Open paziewskib opened 2 months ago

paziewskib commented 2 months ago

Hello, I can't run step 4 from the instruction that is available on https://github.com/pytorch/executorch/tree/main/examples/models/llama2

When I run point 2. Build llama runner. I have an error:

[  8%] Linking CXX shared library libllama_runner.so
[ 16%] Linking CXX static library libcustom_ops.a
[ 33%] Built target custom_ops
[ 75%] Built target llama_runner
[ 83%] Linking CXX executable llama_main
/usr/bin/ld: CMakeFiles/llama_main.dir/home/b.paziewski/conda_executorch/executorch/backends/xnnpack/threadpool/cpuinfo_utils.cpp.o: in function `torch::executorch::cpuinfo::get_num_performant_cores()':
cpuinfo_utils.cpp:(.text+0x919): undefined reference to `pthread_once'
/usr/bin/ld: /home/b.paziewski/conda_executorch/executorch/cmake-out/lib/libxnnpack_backend.a(threadpool.cpp.o): in function `torch::executorch::threadpool::get_threadpool()':
threadpool.cpp:(.text._ZN5torch10executorch10threadpool14get_threadpoolEv+0x98): undefined reference to `pthread_once'
/usr/bin/ld: /home/b.paziewski/conda_executorch/executorch/cmake-out/lib/libpthreadpool.a(pthreads.c.o): in function `pthreadpool_create':
pthreads.c:(.text+0x32d): undefined reference to `pthread_create'
/usr/bin/ld: /home/b.paziewski/conda_executorch/executorch/cmake-out/lib/libpthreadpool.a(pthreads.c.o): in function `pthreadpool_destroy':
pthreads.c:(.text+0x67e): undefined reference to `pthread_join'
/usr/bin/ld: /home/b.paziewski/conda_executorch/executorch/cmake-out/lib/libcpuinfo.a(init.c.o): in function `cpuinfo_initialize':
init.c:(.text+0x17): undefined reference to `pthread_once'
/usr/bin/ld: /home/b.paziewski/conda_executorch/executorch/cmake-out/lib/libXNNPACK.a(init.c.o): in function `xnn_initialize':
init.c:(.text+0x61): undefined reference to `pthread_once'
/usr/bin/ld: /home/b.paziewski/conda_executorch/executorch/cmake-out/lib/libXNNPACK.a(hardware-config.c.o): in function `xnn_init_hardware_config':
hardware-config.c:(.text+0xf6): undefined reference to `pthread_once'
/usr/bin/ld: /home/b.paziewski/conda_executorch/executorch/cmake-out/lib/libXNNPACK.a(argmaxpool-config.c.o): in function `xnn_init_f32_argmaxpool_config':
argmaxpool-config.c:(.text+0x87): undefined reference to `pthread_once'
/usr/bin/ld: /home/b.paziewski/conda_executorch/executorch/cmake-out/lib/libXNNPACK.a(avgpool-config.c.o): in function `xnn_init_f16_avgpool_config':
avgpool-config.c:(.text+0xe0): undefined reference to `pthread_once'
/usr/bin/ld: /home/b.paziewski/conda_executorch/executorch/cmake-out/lib/libXNNPACK.a(avgpool-config.c.o):avgpool-config.c:(.text+0x111): more undefined references to `pthread_once' follow
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/llama_main.dir/build.make:133: llama_main] Error 1
make[1]: *** [CMakeFiles/Makefile2:119: CMakeFiles/llama_main.dir/all] Error 2
make: *** [Makefile:136: all] Error 2

Based on Common Issues and Mitigations I added two lines of code to examples/models/llama2/CMakeLists.txt

find_package(Threads REQUIRED)
set(link_libraries pthread)

After that, when I run cmake --build cmake-out/examples/models/llama2 -j16 --config Release the script returned another error:

[ 25%] Built target custom_ops
[ 75%] Built target llama_runner
[ 83%] Building CXX object CMakeFiles/llama_main.dir/home/b.paziewski/conda_executorch/executorch/backends/xnnpack/threadpool/cpuinfo_utils.cpp.o
[ 91%] Building CXX object CMakeFiles/llama_main.dir/main.cpp.o
[100%] Linking CXX executable llama_main
/usr/bin/ld: CMakeFiles/llama_main.dir/main.cpp.o: in function `main':
main.cpp:(.text.startup+0x41): undefined reference to `google::ParseCommandLineFlags(int*, char***, bool)'
/usr/bin/ld: CMakeFiles/llama_main.dir/main.cpp.o: in function `_GLOBAL__sub_I_main.cpp':
main.cpp:(.text.startup+0x358): undefined reference to `google::FlagRegisterer::FlagRegisterer<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(char const*, char const*, char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*)'
/usr/bin/ld: main.cpp:(.text.startup+0x3fa): undefined reference to `google::FlagRegisterer::FlagRegisterer<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(char const*, char const*, char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*)'
/usr/bin/ld: main.cpp:(.text.startup+0x496): undefined reference to `google::FlagRegisterer::FlagRegisterer<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(char const*, char const*, char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*)'
/usr/bin/ld: main.cpp:(.text.startup+0x4f9): undefined reference to `google::FlagRegisterer::FlagRegisterer<double>(char const*, char const*, char const*, double*, double*)'
/usr/bin/ld: main.cpp:(.text.startup+0x528): undefined reference to `google::FlagRegisterer::FlagRegisterer<int>(char const*, char const*, char const*, int*, int*)'
/usr/bin/ld: main.cpp:(.text.startup+0x557): undefined reference to `google::FlagRegisterer::FlagRegisterer<int>(char const*, char const*, char const*, int*, int*)'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/llama_main.dir/build.make:132: llama_main] Error 1
make[1]: *** [CMakeFiles/Makefile2:119: CMakeFiles/llama_main.dir/all] Error 2
make: *** [Makefile:136: all] Error 2

Can you have any advice how I can run it? Maybe I added the lines in the wrong file? Should I add something more to the CMakeLists.txt?

Barleysack commented 2 months ago

being suffered with exactly same error with the first error. Waiting for the response.

mergennachin commented 2 months ago

@paziewskib

that looks like the right place.

Can you try rm -rf cmake-out and try compiling again?

paziewskib commented 2 months ago

@mergennachin

So I did it like this: 1st attempt - rm -rf cmake-out; after that

cmake -DPYTHON_EXECUTABLE=python \
    -DCMAKE_INSTALL_PREFIX=cmake-out \
    -DEXECUTORCH_ENABLE_LOGGING=1 \
    -DCMAKE_BUILD_TYPE=Release \
    -DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
    -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
    -DEXECUTORCH_BUILD_XNNPACK=ON \
    -DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \
    -DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \
    -DEXECUTORCH_BUILD_KERNELS_CUSTOM=ON \
    -Bcmake-out .

cmake --build cmake-out -j16 --target install --config Release

and

cmake -DPYTHON_EXECUTABLE=python \
    -DCMAKE_INSTALL_PREFIX=cmake-out \
    -DCMAKE_BUILD_TYPE=Release \
    -DEXECUTORCH_BUILD_KERNELS_CUSTOM=ON \
    -DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \
    -DEXECUTORCH_BUILD_XNNPACK=ON \
    -DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \
    -Bcmake-out/examples/models/llama2 \
    examples/models/llama2

cmake --build cmake-out/examples/models/llama2 -j16 --config Release

Results: nothing changed, the same error as above with undefined reference togoogle::FlagRegisterer::FlagRegisterer`

2nd attempt: rm -rf cmake-out and after that only 2nd point from 4th step from the instruction:

cmake -DPYTHON_EXECUTABLE=python \
    -DCMAKE_INSTALL_PREFIX=cmake-out \
    -DCMAKE_BUILD_TYPE=Release \
    -DEXECUTORCH_BUILD_KERNELS_CUSTOM=ON \
    -DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \
    -DEXECUTORCH_BUILD_XNNPACK=ON \
    -DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \
    -Bcmake-out/examples/models/llama2 \
    examples/models/llama2

cmake --build cmake-out/examples/models/llama2 -j16 --config Release

Results: errors:

>     -DCMAKE_INSTALL_PREFIX=cmake-out \
>     -DCMAKE_BUILD_TYPE=Release \
    -Bcmake-out/examples/models/llama2 \
    examples/models/llama2>     -DEXECUTORCH_BUILD_KERNELS_CUSTOM=ON \
>     -DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \
>     -DEXECUTORCH_BUILD_XNNPACK=ON \
>     -DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \
>     -Bcmake-out/examples/models/llama2 \
>     examples/models/llama2
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
CMake Warning (dev) at CMakeLists.txt:85 (find_package):
  Policy CMP0144 is not set: find_package uses upper-case <PACKAGENAME>_ROOT
  variables.  Run "cmake --help-policy CMP0144" for policy details.  Use the
  cmake_policy command to set the policy and suppress this warning.

  CMake variable EXECUTORCH_ROOT is set to:

    /home/b.paziewski/conda_executorch/executorch/examples/models/llama2/../../..

  For compatibility, find_package is ignoring the variable, but code in a
  .cmake module might still use it.
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Error at CMakeLists.txt:85 (find_package):
  Could not find a package configuration file provided by "executorch" with
  any of the following names:

    executorchConfig.cmake
    executorch-config.cmake

  Add the installation prefix of "executorch" to CMAKE_PREFIX_PATH or set
  "executorch_DIR" to a directory containing one of the above files.  If
  "executorch" provides a separate development package or SDK, be sure it has
  been installed.

-- Configuring incomplete, errors occurred!
westphal-jan commented 2 months ago

Facing the same issue.

paziewskib commented 1 month ago

Any ideas?

paziewskib commented 1 month ago

I've tried to follow the instructions once again and the other problem has appeared in Step 3: Evaluate model accuracy. After executing python -m examples.models.llama2.eval_llama -c lama-2-7b/consolidated.00.pth -t tokenizer.model -p llama-2-7b/params.json -d fp32 --max_seq_len 2048 --limit 1000 command the system has returned

TypeError: HFLM.__init__() missing 1 required positional argument: 'pretrained'