Model serving 관련

[yongggg's] llama.cpp install

Yonggg 2025. 1. 20. 14:53

안녕하세요 이번 장에서는 llama.cpp 를 설치하는 방법에 대해 말씀드리겠습니다.

llama.cpp 는 open-source LLM을 쉽게 다운로드, convert gguf, 양자화를 할 수 있도록 도와주는 기능이 매우 powerful 하다고 느꼈습니다! 

지금부터 llama.cpp를 설치하는 방법과 사용하는 방법에 대해 설명드리겠습니다! :)

1. CMake 모듈을 설치한다.

1-1) 종속성 설정

sudo apt-get remove --purge cmake -y # 기존 cmake 제거
sudo apt-get install -y software-properties-common build-essential # 기본 도구 설치
sudo apt-add-repository -y ppa:ubuntu-toolchain-r/test  # 최신 GCC 저장소 추가
sudo apt-get update
sudo apt-get install -y gcc-10 g++-10  # GCC/G++ 10 설치
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 10
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 10
sudo update-alternatives --config gcc  # 기본 GCC 설정
sudo update-alternatives --config g++  # 기본 G++ 설정

현재 llama.cpp 에서는 cmake를 3.18 버전 이상을 요구하지만, 사내 서버에서는 3.16.3의 cmake가 설치되어 있었고, "apt-get update" 하여 재설치를 해도 동일 현상이 발생했다.

1-2) cmake local 다운로드 (apt-get install cmake version error)

https://cmake.org/download/

 

Download CMake

You can either download binaries or source code archives for the latest stable or previous release or access the current development (aka nightly) distribution through Git. This software may not be exported in violation of any U.S. export laws or regulatio

cmake.org

 

해당 url로 들어가서 offline install을 시도하자. 해당 url에서 linux file에 링크 주소 복사를 한 뒤, 다음 명령어로 파일을 다운받을 수 있다.

curl -k -L https://github.com/Kitware/CMake/releases/download/v3.31.4/cmake-3.31.4.tar.gz --output cmake-3.31.4.tar.gz

1-3) 압축 해제 및 cmake install

그리고, 다음 명령어로 압축을 해제한다.

tar -zxvf cmake-3.31.4.tar.gz

 

cmake 모듈을 설치한다.

# cmake 종속 설치 openssl 관련
apt-get install libssl-dev

cd cmake-3.31.4
./bootstrap --prefix=$HOME/cmake-install
make
make install

 

1-2) 기존 cmake 버전이 3.18 이상인 경우

(이 명령어로 3.18 이상의 cmake가 설치된다면, 위처럼 설치를 안해도 무방함.)

sudo apt-get install -y cmake

2. Bulid llama.cpp git

git clone https://github.com/ggerganov/llama.cpp.git
cd llama.cpp

1-4) 환경변수 등록

설치가 완료 됐다면, 다음 환경변수 설정 명령어를 ~/.bashrc에 추가하고 적용시킨다.

export PATH=$HOME/cmake-install/bin:$PATH
export CMAKE_PREFIX_PATH=$HOME/cmake-install:$CMAKE_PREFIX_PATH
source ~/.bashrc

1-5) cmake 버전 확인

이제 모든 설정은 끝났고 버전을 확인해 보면, 처음 설치한 3.31.4 cmake 버전을 확인할 수 있다.

cmake --version

2. llama.cpp 설치

llama.cpp를 설치하기 위해선 해당 github를 클론하여 빌드해야 한다.

git clone https://github.com/ggerganov/llama.cpp.git
cd llama.cpp

llama.cpp의 CuDA version은 아래의 명령어로 설치할 수 있다.

cmake -B build -DGGML_CUDA=ON
cmake --build build --config Release

 

이렇게 llama.cpp를 설치하는 과정을 글로 작성해보았는데, 다음엔 양자화/배포 등의 llama.cpp의 기본적인 사용법을 작성해 보도록 하겠습니다 :)