windows 환경에서 llama.cpp 설치 방법
ai모델을 로컬환경에서 돌려보기 위해 llama.cpp를 설치해본다.
llama.cpp는 GPU 없이도 CPU만으로 Meta의 LLaMA 모델을 실행하게 해주는 오픈소스 라이브러리다.
참고로 Windows 기본 셸인 cmd가 아닌 Git Bash를 사용하여 명령어를 실행했다.
■ ai모델 다운로드
1. 허깅페이스(huggingface.co)에 접속, 원하는 모델을 찾는다.
2. 상단 탭 중 2번째 탭인 [Files and versions] 클릭. 확장자 .gguf 파일을 찾아서 로컬에 다운로드 한다.
원하는 폴더에 저장한다. ex) C:\ai\models\[모델명] 폴더에 다운
■ 실행도구 설치 (llama.cpp 설치)
# c드라이브에 llama 폴더 생성
# Git Bash 실행
cd c:/llama
git clone https://github.com/ggerganov/llama.cpp # llama.cpp 라는 폴더가 생김
cd llama.cpp
mkdir build
cd build
cmake ..
cmake --build . --config Release
# Git Bash 실행
cd c:/llama
git clone https://github.com/ggerganov/llama.cpp # llama.cpp 라는 폴더가 생김
cd llama.cpp
mkdir build
cd build
cmake ..
cmake --build . --config Release
문제해결 1. cmake: command not found 오류
cmake.. 명령어 쳤을 때 bash: cmake: command not found 오류가 발생한다면, CMake 공식 홈페이지에서 Windows Installer를 다운로드받아 설치하면 된다. (https://cmake.org/download/)
# 오류내용
bash: cmake: command not found
bash: cmake: command not found
64비트 윈도우의 경우 설치파일명은 현시점 기준 cmake-4.0.2-windows-x86_64.msi 이다.
CMake 설치할 때 반드시 [Add CMake to the PATH environment variable]에 체크박스 체크하고 진행한다.
문제해결 2. Could NOT find CURL (missing: CURL_LIBRARY CURL_INCLUDE_DIR) 오류
cmake 설치했지만, 다시 한번 cmake.. 명령어 쳤을 때 Could NOT find CURL (missing: CURL_LIBRARY CURL_INCLUDE_DIR) 오류가 발생한다면 curl을 설치해야 한다.
# 오류내용
-- Adding CPU backend variant ggml-cpu: /arch:AVX2 GGML_AVX2;GGML_FMA;GGML_F16C
-- Could NOT find CURL (missing: CURL_LIBRARY CURL_INCLUDE_DIR)
CMake Error at common/CMakeLists.txt:95 (message):
Could NOT find CURL. Hint: to disable this feature, set -DLLAMA_CURL=OFF
-- Adding CPU backend variant ggml-cpu: /arch:AVX2 GGML_AVX2;GGML_FMA;GGML_F16C
-- Could NOT find CURL (missing: CURL_LIBRARY CURL_INCLUDE_DIR)
CMake Error at common/CMakeLists.txt:95 (message):
Could NOT find CURL. Hint: to disable this feature, set -DLLAMA_CURL=OFF
2-1. vcpkg로 curl 설치
vcpkg를 이용하면 Windows에서 C/C++ 라이브러리를 쉽게 설치할 수 있다.
vcpkg로 curl 라이브러리를 설치하고 cmake 실행 시 경로를 부여하면 된다.
# c드라이브에 vcpkg 폴더 생성
# Git Bash 실행
cd c:/vcpkg
git clone https://github.com/microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh # Git Bash로 실행하므로 윈도우이지만 bat파일이 아닌 sh파일 실행
./vcpkg install curl
./vcpkg install curl:x64-windows # 윈도우가 64비트 환경이라면 설치. 32비트와 충돌없으므로 둘 다 설치하면 된다.
# Git Bash 실행
cd c:/vcpkg
git clone https://github.com/microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh # Git Bash로 실행하므로 윈도우이지만 bat파일이 아닌 sh파일 실행
./vcpkg install curl
./vcpkg install curl:x64-windows # 윈도우가 64비트 환경이라면 설치. 32비트와 충돌없으므로 둘 다 설치하면 된다.
이제 cmake 명령어 실행할 때 vcpkg 경로를 지정해서 시도해보자.
■ 실행도구 설치 (llama.cpp 설치) 재시도
다시 cmake와 cmake build해본다.
cd c:/llama/llama.cpp/build
# cmake -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/vcpkg/scripts/buildsystems/vcpkg.cmake .. # 32비트인 경우
cmake -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/vcpkg/scripts/buildsystems/vcpkg.cmake -A x64 .. # 64비트인 경우
cmake --build . --config Release
# cmake -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/vcpkg/scripts/buildsystems/vcpkg.cmake .. # 32비트인 경우
cmake -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/vcpkg/scripts/buildsystems/vcpkg.cmake -A x64 .. # 64비트인 경우
cmake --build . --config Release
문제해결 3. CMake Error: generator platform: x64 오류
만약 아래처럼 CMake Error: generator platform: x64 오류가 발생하면, 32비트 명령어를 실행했다가 실패해서, 다시 64비트 명령어를 실행하는 경우일 것이다.
캐시를 제거하고 다시 해본다.
# 오류내용
CMake Error: generator platform: x64
Does not match the platform used previously:
Either remove the CMakeCache.txt file and CMakeFiles directory or choose a different binary directory.
CMake Error: generator platform: x64
Does not match the platform used previously:
Either remove the CMakeCache.txt file and CMakeFiles directory or choose a different binary directory.
캐시제거 방법
cd c:/llama/llama.cpp/build
rm -rf CMakeCache.txt
rm -rf CMakeFiles/
cd c:/llama/llama.cpp/build
rm -rf CMakeCache.txt
rm -rf CMakeFiles/
캐시를 제거하고 다시 시도하면, 이제 정상적으로 cmake, cmake build 될 것이다.
llama.cpp의 build까지 완료했다.
요약하면 llama.cpp 를 빌드하려면 아래 순서로 해본다.
1. Git Bash 설치
2. CMake 설치
3. (curl 설치를 위해) vcpkg 설치
4. curl 라이브러리 설치
5. llama.cpp 를 cmake 및 cmake --build 하기
■ llama.cpp로 ai모델 실행하기
먼저 허깅페이스에서 다운로드 받은 ai모델을 원하는 폴더에 위치시킨다.
ex ) C:/ai/models/uigen/uigen-t3-preview-q8_0.gguf
ex) C:/ai/models/uigen/uigen-t3-preview-14b-q8_0.gguf
# Git Bash에서 아래 명령어 실행
cd c:/llama/llama.cpp/build/bin/Release
./llama-simple-chat.exe -m "C:/ai/models/uigen/uigen-t3-preview-q8_0.gguf"
create a modern pricing page with three plans
cd c:/llama/llama.cpp/build/bin/Release
./llama-simple-chat.exe -m "C:/ai/models/uigen/uigen-t3-preview-q8_0.gguf"
create a modern pricing page with three plans
아래는 실행결과.