C.W.K.
Stream
Lesson 05 of 05 · published

Modelfile 설정

~24 min · ollama, modelfile

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

Modelfile이 뭐야

Modelfile은 Ollama한테 Dockerfile이 Docker한테 하는 역할이야 — base에서 커스텀 모델 derive하는 작은 텍스트 파일. System prompt, default parameter, few-shot 예제, LoRA adapter까지 박아놓고 ollama create로 빌드. 결과는 일반 모델처럼 호출돼: ollama run my-assistant.

실전에서 쓰는 instruction

Instruction필수?용도
FROMBase 모델 이름, GGUF 파일 경로, safetensors 디렉토리
SYSTEM선택모든 chat에 박힐 system prompt
PARAMETER선택temperature, num_ctx, top_p, top_k, repeat_penalty, seed, stop, num_predict, min_p
TEMPLATE선택Prompt 포맷용 Go template (advanced — 보통 FROM에서 상속)
ADAPTER선택LoRA adapter 적용 (safetensor / GGUF)
MESSAGE선택Few-shot 예제 (role: user / assistant / system)

Modelfile이 빛나는 경우

  • 모델 하나 위에 single product 만들고 모든 caller에 동일한 system prompt 원할 때.
  • 안정적인 num_ctx default 원할 때 (Ollama default가 자주 너무 작음; 8192나 16384가 더 실용적).
  • 이름 붙은 variant — my-coder, my-summarizer, my-translator — 같은 base 공유하지만 system prompt랑 parameter 다르게 갈 때.

안 쓰는 게 나을 때

어차피 API call마다 system prompt 보낼 거면 Modelfile은 유지할 layer 하나 늘리는 거. Modelfile은 caller가 몰라도 되도록 설정에 이름 붙이고 싶을 때 빛나.

Code

진짜 Modelfile·bash
# Modelfile 이름으로 저장 (확장자 없음)
FROM qwen2.5:7b-instruct

PARAMETER temperature 0.6
PARAMETER num_ctx 8192
PARAMETER top_p 0.9
PARAMETER repeat_penalty 1.05

SYSTEM """You are a senior Python engineer. Respond with:
1. A clear plan in 3 bullets.
2. Production-grade code with type hints and docstrings.
3. One failure mode worth knowing.
Keep replies under 300 words unless the user asks for more."""

MESSAGE user How do I read a JSON file safely?
MESSAGE assistant Plan: open with explicit encoding, parse, handle decode errors.
빌드, 실행, 반복·bash
# Derived 모델 빌드
ollama create py-senior -f ./Modelfile

# 실행
ollama run py-senior "How do I parallelize a loop?"

# 박힌 거 inspect
ollama show py-senior --modelfile

# 반복 — Modelfile 편집 후 rebuild
$EDITOR Modelfile
ollama create py-senior -f ./Modelfile

# 실험 끝나면 제거
ollama rm py-senior

External links

Exercise

좋아하는 7B 모델에서 pippa-summarizer derive하는 Modelfile 써. 3-bullet 요약 + 1-sentence verdict 요청하는 system prompt 박고, temperature 0.3, num_ctx 16384로. 빌드해서 2-paragraph essay에 돌리고, 마음에 안 드는 부분 보면서 system prompt 두 번 iterate.

Progress

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

댓글 0

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

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