C.W.K.
Stream
Lesson 02 of 04 · published

llama.cpp server

~22 min · serving, llamacpp, gguf

Level 0Downloader
0 XP0/41 lessons0/11 achievements
0/120 XP to next level120 XP to go0% complete

왜 llama.cpp server?

llama.cpp가 기반 C/C++ inference engine. Ollama가 내부에서 이거 사용. llama-server (llama.cpp 트리에서 빌드)가 같은 engine을 standalone HTTP server로 노출 — full OpenAI-compatible chat completion + llama.cpp 전용 endpoint들 포함.

직접 잡을 때

  • Ollama가 ship 안 하는 특정 GGUF가 있고 Modelfile + repository 만들기 싫을 때.
  • Flag 레벨 컨트롤 필요 — 정확한 num_ctx, batch size, GPU split, mmap 설정, KV cache type.
  • Engine을 자체 product에 embed하고 싶고 binary 하나, daemon 없음, 모델 registry 없음 원할 때.
  • 다른 port에 여러 variant 돌리고 싶을 때 — 모델 하나당 server 하나, 공유 state 없음.

빌드, serve, hit

llama.cpp는 CMake 한 번으로 빌드. Server binary는 llama-server. 어떤 GGUF 파일이든 가리키면 고른 port에서 listen, OpenAI-compat endpoint default로 live.

Code

빌드, GGUF serve, hit·bash
# llama.cpp 빌드 (Apple Silicon Metal 빌드)
git clone https://github.com/ggml-org/llama.cpp ~/llama.cpp
cd ~/llama.cpp && cmake -B build && cmake --build build --config Release -j

# 직접 serve할 GGUF 다운로드
huggingface-cli download bartowski/Qwen2.5-7B-Instruct-GGUF \
  Qwen2.5-7B-Instruct-Q4_K_M.gguf --local-dir ~/models

# 8K context, 모든 GPU layer로 port 8080에 serve
./build/bin/llama-server \
  -m ~/models/Qwen2.5-7B-Instruct-Q4_K_M.gguf \
  -c 8192 \
  -ngl 999 \
  --port 8080

# OpenAI-compatible client로 hit
curl http://localhost:8080/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen-direct",
    "messages": [{"role":"user","content":"Hello!"}],
    "stream": false
  }'
OpenAI SDK를 llama-server에·python
from openai import OpenAI
client = OpenAI(
    base_url="http://localhost:8080/v1",
    api_key="not-used",   # llama-server는 무시; SDK가 비어있지 않은 값 요구
)

resp = client.chat.completions.create(
    model="qwen-direct",   # llama-server는 준 이름 그대로; 일부 빌드는 아무거나 받음
    messages=[{"role": "user", "content": "Define GGUF in one sentence."}],
    stream=False,
)
print(resp.choices[0].message.content)

External links

Exercise

머신에 llama.cpp 빌드. HuggingFace에서 GGUF 하나 직접 다운로드 (Ollama가 ship 안 하는 quant 시도). Port 8080에 serve. OpenAI Python SDK로 hit. 같은 모델의 Ollama 버전이랑 답변 품질이랑 tok/s 비교.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.