DEV Community

matias yoon
matias yoon

Posted on

로컬 LLM 셋업 가이드 (v22)

로컬 LLM 셋업 가이드 (v22)

1. 개요 및 사전 준비

로컬 LLM 실행은 GPU 없이도 가능하지만, 성능을 위해 GPU가 권장됩니다. 최소 RAM 요구사항은 8GB이며, 16GB 이상 권장됩니다. GPU가 있는 경우 NVIDIA GPU가 필요합니다. 이 가이드에서는 Ubuntu 22.04 기준으로 설명합니다.

# 시스템 정보 확인
lspci | grep -i nvidia
free -h
Enter fullscreen mode Exit fullscreen mode

2. 프레임워크 비교

프레임워크 장점 단점 추천 사용 사례
llama.cpp 가볍고 직접적, 최적화된 C++ 코드 복잡한 설정 필요 개발 및 테스트
Ollama 간단한 CLI 및 API, 쉬운 관리 제한된 최적화 빠른 프로토타입
vLLM 높은 성능, 효율적인 배포 복잡한 설정, 메모리 요구량 높음 프로덕션 환경
LocalAI 다양한 API 호환성, 다중 모델 지원 복잡한 구성 파일 복합적인 LLM 통합

3. 권장 설정 단계별 설치

우리는 llama.cpp를 사용하여 로컬 LLM을 설정할 것입니다. 이유는 간단하고, 최적화된 성능을 제공하며, 최소한의 시스템 요구사항입니다.

# 필요 패키지 설치
sudo apt update
sudo apt install -y git cmake build-essential

# llama.cpp 클론 및 빌드
git clone https://github.com/ggerganov/llama.cpp
cd llama.cpp
mkdir build && cd build
cmake ..
make -j4

# 실행 파일 위치 확인
ls -la bin/
Enter fullscreen mode Exit fullscreen mode

4. 모델 선택 가이드

모델 용도 추천 사양
Llama3 8B Q4_K_M 일반적 텍스트 생성 8GB RAM + GPU
Llama3 70B Q4_K_M 고급 작업 16GB RAM + GPU
Mistral 7B Q4_K_M 빠른 추론 8GB RAM
Mixtral 8x7B Q4_K_M 복잡한 작업 16GB RAM

5. 양자화 타입 설명

Q4_K_M는 가장 일반적인 양자화 방식입니다. 다음은 주요 양자화 타입입니다:

  • Q4_K_M: 4-bit 양자화, 최적화된 성능과 정확도
  • Q5_K_M: 5-bit 양자화, 정확도 향상
  • Q8_0: 8-bit 양자화, 정확도 최대치
# 모델 양자화 예시
./convert-hf-to-gguf.py /path/to/model --outtype q4_k_m --outfile model-q4_k_m.gguf
Enter fullscreen mode Exit fullscreen mode

6. API 설정 및 기존 도구 통합

llama.cpp는 기본적으로 HTTP API를 제공합니다:

# 기본 API 서버 실행
./server -m /path/to/model-q4_k_m.gguf -c 2048 --host 0.0.0.0 --port 8080

# API 호출 예시
curl http://localhost:8080/completion -H "Content-Type: application/json" -d '{
  "prompt": "Hello, how are you?",
  "n_predict": 100
}'
Enter fullscreen mode Exit fullscreen mode

7. 24/7 운영을 위한 Systemd 서비스

/etc/systemd/system/llama.service 파일 생성:

[Unit]
Description=Local LLM Server
After=network.target

[Service]
Type=simple
User=your_username
WorkingDirectory=/path/to/llama.cpp
ExecStart=/path/to/llama.cpp/bin/server -m /path/to/model-q4_k_m.gguf -c 2048 --host 0.0.0.0 --port 8080
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target
Enter fullscreen mode Exit fullscreen mode
# 서비스 등록 및 시작
sudo systemctl daemon-reload
sudo systemctl enable llama
sudo systemctl start llama
sudo systemctl status llama
Enter fullscreen mode Exit fullscreen mode

8. 모니터링 및 성능 조정

성능을 모니터링하기 위해 다음 명령어 사용:

# CPU 및 메모리 사용량 모니터링
htop
nvidia-smi  # NVIDIA GPU 사용 시

# 서버 로그 확인
sudo journalctl -u llama -f

# 성능 벤치마크
time ./server -m /path/to/model-q4_k_m.gguf -c 2048 --host 0.0.0.0 --port 8080 &
curl http://localhost:8080/completion -H "Content-Type: application/json" -d '{
  "prompt": "The quick brown fox jumps over the lazy dog",
  "n_predict": 50
}'
Enter fullscreen mode Exit fullscreen mode

9. 실전 예제 및 명령어

1. 모델 다운로드 및 변환:

# Hugging Face에서 모델 다운로드
git lfs install
git clone https://huggingface.co/meta-llama/Llama-3.2-1B
cd Llama-3.2-1B

# GGUF 형식으로 변환
../llama.cpp/convert-hf-to-gguf.py . --outtype q4_k_m --outfile llama3-1b-q4_k_m.gguf
Enter fullscreen mode Exit fullscreen mode

2. 서버 실행:

# 메모리 제한 설정
ulimit -v 1000000

# 서버 실행 (CPU 사용)
./server -m llama3-1b-q4_k_m.gguf -c 2048 --host 0.0.0.0 --port 8080 -ngl 0

# GPU 사용 (NVIDIA)
./server -m llama3-1b-q4_k_m.gguf -c 2048 --host 0.0.0.0 --port 8080 -ngl 33
Enter fullscreen mode Exit fullscreen mode

3. API 통신 예제:

# 단순 질의
curl http://localhost:8080/completion -H "Content-Type: application/json" -d '{
  "prompt": "Python으로 간단한 웹 서버를 만드는 방법은?",
  "n_predict": 200,
  "temperature": 0.7,
  "stop": ["\n\n"]
}'
Enter fullscreen mode Exit fullscreen mode

이 가이드는 실제 개발자들이 로컬 LLM을 쉽게 설정하고 운영할 수 있도록 설계되었습니다. 구체적인 명령어와 설정을 통해 빠르게 시작할 수 있습니다.


📥 Get the full guide on Gumroad: https://gumroad.com/l/auto ($7)

Top comments (0)