본문 바로가기
C.W.K.
Stream
Lesson 03 of 08 · published

Ollama / llama.cpp 용 GGUF Export

~24 min · ops, gguf, ollama

Level 0스카우트
0 XP0/50 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

GGUF는 로컬 실행에 필요한 묶음을 한 파일에 담아

llama.cpp가 만든 GGUF는 CPU 중심 추론, Apple Silicon의 Metal 가속, 여러 운영체제에 배포하는 실행을 겨냥해. 가중치, tokenizer, 메타데이터가 .gguf 하나에 들어가므로 Ollama와 llama.cpp가 바로 읽기 좋아.

HF 체크포인트를 변환하고 양자화해

표준 경로는 llama.cpp의 convert_hf_to_gguf.py야. HF 저장소를 입력으로 주고 Q4_K_M·Q5_K_M·Q8_0·F16 같은 등급을 골라 배포할 파일을 만들어.

파일 이름에서 양자화 등급을 읽어

Hub에서는 보통 {model}-{params}-{quant}.gguf처럼 이름을 붙여. Llama-3.1-8B-Instruct-Q4_K_M.gguf의 마지막 부분이 비트 폭과 반올림 방식을 알려 주며, Q4_K_M은 크기와 품질을 절충하는 흔한 선택이야.

Code

HF 모델을 GGUF 로 변환·bash
# 1회 셋업
git clone https://github.com/ggml-org/llama.cpp.git
cd llama.cpp
pip install -r requirements.txt

# HF 모델 다운로드
huggingface-cli download "Qwen/Qwen2.5-1.5B-Instruct" --local-dir ./qwen-1.5b

# F16 GGUF 로 변환
python convert_hf_to_gguf.py ./qwen-1.5b --outfile qwen-1.5b-f16.gguf

# Q4_K_M 으로 양자화 (cmake 으로 quantize 바이너리 먼저 빌드)
./build/bin/llama-quantize qwen-1.5b-f16.gguf qwen-1.5b-Q4_K_M.gguf Q4_K_M
GGUF 를 Hub 레포에 push, Ollama 로 pull·bash
# Hub 에 모델 레포 생성
huggingface-cli upload "yourname/qwen-1.5b-gguf" qwen-1.5b-Q4_K_M.gguf --repo-type=model

# 그다음 Ollama 로 pull (modelfile 패턴)
cat > Modelfile <<EOF
FROM hf.co/yourname/qwen-1.5b-gguf:Q4_K_M
EOF

ollama create qwen-1.5b-cwk -f Modelfile
ollama run qwen-1.5b-cwk

External links

Exercise

1-3B Hub 모델을 GGUF (Q4_K_M) 로 변환. private Hub 레포에 GGUF push. Modelfile 패턴으로 Ollama 통해 pull. 인퍼런스 실행, 5 프롬프트에 unquantized HF 모델과 출력 품질 비교.

Progress

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

댓글 0

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

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