DEV Community

matias yoon
matias yoon

Posted on

로컬 LLM 셋업 가이드 (v11)

로컬 LLM 셋업 가이드 (v11)

1. 개요 및 전제 조건

로컬 LLM은 클라우드 비용을 절감하고 데이터 프라이버시를 보장할 수 있습니다. 이 가이드는 16GB RAM 이상의 Linux 머신에서 실행 가능한 최적의 로컬 LLM 설정을 다룹니다.

요구사항:

  • Ubuntu 20.04 이상 또는 Debian 11 이상
  • NVIDIA GPU (적어도 8GB VRAM) 또는 CPU-only 환경
  • 최소 16GB RAM (32GB 이상 권장)
  • 100GB 이상의 디스크 공간

2. 프레임워크 비교

프레임워크 장점 단점 추천 사용 사례
llama.cpp 최적화된 C++ 구현, 낮은 메모리 사용, 직접 컴파일 가능 복잡한 설치 과정, GPU 지원 제한 빠른 프로토타이핑, 최적화된 서버
Ollama 설치 간단, Docker 기반, CLI 편리 메모리 사용량 높음, GPU 최적화 부족 개발 테스트, 빠른 설정
vLLM 높은 성능, 대규모 모델 지원 복잡한 의존성, CUDA 필요 대규모 프로덕션 환경
LocalAI 다양한 API 호환성, 커뮤니티 지원 높은 메모리 사용, 복잡한 구성

우선순위: llama.cpp (최적화된 성능 + 간단한 설치)

3. 설치 절차 (llama.cpp 기반)

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

# 2. llama.cpp 클론
git clone https://github.com/ggerganov/llama.cpp
cd llama.cpp

# 3. 최적화된 빌드
mkdir build && cd build
cmake ..
make -j$(nproc)

# 4. 실행 가능한 파일 확인
ls -la llama-server
Enter fullscreen mode Exit fullscreen mode
# 5. 모델 다운로드 및 변환
cd ..
mkdir models
wget https://huggingface.co/TheBloke/Llama-3.2-3B-Instruct-GGUF/resolve/main/llama-3.2-3b-instruct.Q4_K_M.gguf -O models/llama32-3b.Q4_K_M.gguf

# 6. 서버 시작
./build/bin/llama-server \
  --model models/llama32-3b.Q4_K_M.gguf \
  --port 8080 \
  --host 0.0.0.0 \
  --n-gpu-layers 35 \
  --ctx-size 4096 \
  --temp 0.2 \
  --n-predict 2048
Enter fullscreen mode Exit fullscreen mode

4. 모델 선택 가이드

사용 사례 모델 퀀타이제이션 추천 이유
일반 개발 Llama-3.2-3B Q4_K_M 균형 잡힌 성능
고속 추론 Mistral-7B Q5_K_M 빠른 응답
정확도 중심 Llama-3-8B Q5_K_M 높은 정확도
코드 생성 CodeLlama-7B Q4_K_M 코드 이해력
텍스트 요약 Phi-3 Q4_K_M 효율적인 요약
# 모델별 성능 비교
./build/bin/llama-server --model models/llama32-3b.Q4_K_M.gguf --n-predict 100 --temp 0.1 --port 8081 &
./build/bin/llama-server --model models/mistral-7b.Q5_K_M.gguf --n-predict 100 --temp 0.1 --port 8082 &
Enter fullscreen mode Exit fullscreen mode

5. 퀀타이제이션 유형 설명

유형 비트 수 메모리 사용량 정확도 추천 사용 사례
Q4_K_M 4-bit 최적화 높음 일반 사용
Q5_K_M 5-bit 높음 매우 높음 정확도 중요
Q6_K 6-bit 중간 매우 높음 고성능
Q8_0 8-bit 높음 높음 정확도 우선
# 퀀타이제이션 변환 예시
python3 convert.py models/llama-3.2-3b-instruct.gguf --outtype q4_k_m --output models/llama32-3b.Q4_K_M.gguf
Enter fullscreen mode Exit fullscreen mode

6. API 설정 및 통합

# config.yaml - llama.cpp 서버 설정
port: 8080
host: 0.0.0.0
model: models/llama32-3b.Q4_K_M.gguf
n_gpu_layers: 35
ctx_size: 4096
temp: 0.2
n_predict: 2048
Enter fullscreen mode Exit fullscreen mode
# OpenAI 호환 API 설정
./build/bin/llama-server \
  --model models/llama32-3b.Q4_K_M.gguf \
  --port 8080 \
  --host 0.0.0.0 \
  --api-key YOUR_API_KEY \
  --endpoint /v1/chat/completions \
  --endpoint /v1/completions
Enter fullscreen mode Exit fullscreen mode
# Python 클라이언트 예제
import openai

client = openai.OpenAI(
    base_url="http://localhost:8080/v1",
    api_key="sk-1234567890"
)

response = client.chat.completions.create(
    model="llama32-3b",
    messages=[{"role": "user", "content": "Hello world"}],
    temperature=0.2,
    max_tokens=512
)
Enter fullscreen mode Exit fullscreen mode

7. Systemd 서비스 설정

# /etc/systemd/system/llama-server.service
[Unit]
Description=Local LLM Server
After=network.target

[Service]
Type=simple
User=ubuntu
WorkingDirectory=/home/ubuntu/llama.cpp
ExecStart=/home/ubuntu/llama.cpp/build/bin/llama-server \
  --model /home/ubuntu/llama.cpp/models/llama32-3b.Q4_K_M.gguf \
  --port 8080 \
  --host 0.0.0.0 \
  --n-gpu-layers 35 \
  --ctx-size 4096 \
  --temp 0.2 \
  --n-predict 2048
Restart=always
RestartSec=10

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

8. 모니터링 및 성능 최적화

# GPU 사용량 모니터링
nvidia-smi -l 1

# CPU 및 메모리 사용량
htop

# 로그 확인
journalctl -u llama-server -f
Enter fullscreen mode Exit fullscreen mode
# 성능 벤치마크
ab -n 100 -c 10 http://localhost:8080/v1/chat/completions
Enter fullscreen mode Exit fullscreen mode
# 고급 설정 예제
server_config:
  model: models/llama32-3b.Q4_K_M.gguf
  n_gpu_layers: 35
  ctx_size: 8192
  n_predict: 2048
  temp: 0.2
  top_p: 0.9
  frequency_penalty: 0.0
  presence_penalty: 0.0
  stop: ["\nUser:", "\nAssistant:"]
Enter fullscreen mode Exit fullscreen mode

9. 실전 예제

코드 생성 예제


bash
# curl로 API 호출
curl http://localhost:8080/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "llama32-3b",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "Write a Python function to calculate Fibonacci numbers"}
    ],


---

📥 **Get the full guide on Gumroad**: https://gumroad.com/l/auto ($7)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)