mudler / LocalAI

:robot: The free, Open Source OpenAI alternative. Self-hosted, community-driven and local-first. Drop-in replacement for OpenAI running on consumer-grade hardware. No GPU required. Runs gguf, transformers, diffusers and many more models architectures. It allows to generate Text, Audio, Video, Images. Also with voice cloning capabilities.
https://localai.io
MIT License
22.12k stars 1.69k forks source link

Build fails on MacBook Pro M1 when following instructions on website #1504

Closed cnatale closed 6 months ago

cnatale commented 6 months ago

LocalAI version: Git commit id: 9723c3c21d4f2a9fdb91bb2f17e8319a810e6cca

Environment, CPU architecture, OS, and Version:

Darwin Kernel Version 22.6.0: Tue Nov 7 21:40:08 PST 2023; root:xnu-8796.141.3.702.9~2/RELEASE_ARM64_T6000 arm64

Apple M1 Pro, 32GB unified memory

Describe the bug I'm attempting to build localai on my M1 MacBook Pro for the first time. I'm following instructions here: https://localai.io/basics/build/#build-on-mac.

For some reason I'm getting a "symbol(s) not found for architecture x86_64" error. Is there somewhere I need to specify that I want an ARM64 build?

More error logging:

  "gpt_sample_top_k_top_p_repeat(gpt_vocab const&, float const*, int const*, unsigned long, int, double, double, int, float, std::__1::mersenne_twister_engine<unsigned int, 32ul, 624ul, 397ul, 31ul, 2567483615u, 11ul, 4294967295u, 7ul, 2636928640u, 15ul, 4022730752u, 18ul, 1812433253u>&)", referenced from:
      main_mpt(int, char**) in 000014.o
      _mpt_predict in 000014.o
  "gpt_vocab::add_special_token(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&)", referenced from:
      dollyv2_model_load(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, dollyv2_model&, gpt_vocab&) in 000009.o
      starcoder_model_load(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, starcoder_model&, gpt_vocab&) in 000016.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

To Reproduce I followed the "build on Mac" steps described here: https://localai.io/basics/build/#build-on-mac

# install build dependencies
brew install abseil cmake go grpc protobuf wget

# clone the repo
git clone https://github.com/go-skynet/LocalAI.git

cd LocalAI

# build the binary
make build

# Download gpt4all-j to models/
wget https://gpt4all.io/models/ggml-gpt4all-j.bin -O models/ggml-gpt4all-j

# Use a template from the examples
cp -rf prompt-templates/ggml-gpt4all-j.tmpl models/

# Run LocalAI
./local-ai --models-path=./models/ --debug=true

# Now API is accessible at localhost:8080
curl http://localhost:8080/v1/models

curl http://localhost:8080/v1/chat/completions -H "Content-Type: application/json" -d '{
     "model": "ggml-gpt4all-j",
     "messages": [{"role": "user", "content": "How are you?"}],
     "temperature": 0.9 
   }'

Expected behavior The build process should complete successfully.

Logs Shared above.

Additional context Initially I tried the make BUILD_TYPE=metal build option suggested for Apple Silicon systems. That failed with the same message.

netandreus commented 6 months ago

@cnatale I think you should try to build with BUILD_TYPE make BUILD_TYPE=metal build.

cnatale commented 6 months ago

I figured out what the problem was. I migrated from an Intel Mac, and never uninstalled/reinstalled my copy of Homebrew. One of the pieces of software in the build process gets system architecture from Homebrew, so it was setting it to x86, and causing the build to fail. An uninstall/reinstall of Homebrew fixed things.