minicpm5-finetune-llamafactory
하는 일
이 스킬은 설정 파일로 움직이는 인기 학습 도구 LLaMA-Factory로 MiniCPM5를 미세 조정하도록 AI를 안내합니다. 잘 문서화된 설정 기반 방식으로 모델을 학습시키고 싶은 사람을 위한 스킬입니다.
사용하는 경우
- ✓LLaMA-Factory나 llamafactory-cli로 MiniCPM5를 미세 조정하고 싶을 때.
- ✓Python 코드를 쓰는 대신 YAML 설정 파일로 학습하고 싶을 때.
- ✓LLaMA-Factory 웹 인터페이스로 모델을 학습하고 싶은 경우.
스킬 링크
https://github.com/OpenBMB/MiniCPM/blob/main/skills/minicpm5-finetune-llamafactory/SKILL.md복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.
사용 방법
가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
AI에게 요청하는 예시
“제 채팅 예시 파일로 LLaMA-Factory를 사용해 MiniCPM5-2B를 미세 조정하도록 도와주세요.”
매주 새 스킬 5개. 읽는 데 1분.
작동 방식
이 스킬은 별도 환경에 LLaMA-Factory를 설치하고, 데이터셋을 등록하고, YAML 학습 설정을 작성한 뒤 학습을 시작합니다.
기술 내용 (원본 SKILL.md)
작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.
Fine-tune MiniCPM5-1B and MiniCPM5-2B with LLaMA-Factory
YAML-driven SFT / DPO with WebUI. Most-documented community framework.
Required input
| Var | Example | Default |
|---|---|---|
BASE_MODEL |
openbmb/MiniCPM5-2B |
required; openbmb/MiniCPM5-1B also works |
DATA_DIR |
dir containing dataset_info.json + jsonl |
required |
DATASET_NAME |
name registered in dataset_info.json |
required |
OUTPUT_DIR |
./runs/minicpm5_lf |
required |
GPU_ID |
0 |
0 |
Steps
1. Install (once, in its own venv to avoid breaking vLLM)
python -m venv .venv-lf && source .venv-lf/bin/activate
# `template: minicpm5` landed after v0.9.5 (the latest PyPI release) — install from source.
git clone --depth 1 https://github.com/hiyouga/LLaMA-Factory.git
pip install -e LLaMA-Factory
⚠️ LLaMA-Factory requires
transformers>=4.55.0,<=5.8.0(excluding 4.57.0 and 5.6.0), which can clash with a serving stack such as vLLM. Always install it into its own venv.
2. Register the dataset (sharegpt / messages format)
${DATA_DIR}/dataset_info.json:
{
"${DATASET_NAME}": {
"file_name": "your_data.jsonl",
"formatting": "sharegpt",
"columns": {"messages": "messages"},
"tags": {
"role_tag": "role", "content_tag": "content",
"user_tag": "user", "assistant_tag": "assistant", "system_tag": "system"
}
}
}
Each line of your_data.jsonl:
{"messages": [{"role":"system","content":"..."}, {"role":"user","content":"..."}, {"role":"assistant","content":"..."}]}
3. Write the training YAML
Save as ${OUTPUT_DIR}/lora_sft.yaml:
### model
model_name_or_path: ${BASE_MODEL}
trust_remote_code: false
### method
stage: sft
do_train: true
finetuning_type: lora
lora_rank: 16
lora_alpha: 32
lora_target: all # all linear layers
### dataset
dataset: ${DATASET_NAME}
dataset_dir: ${DATA_DIR}
template: minicpm5 # 🔑 MANDATORY for MiniCPM5 — ChatML + XML tool calling
cutoff_len: 4096
max_samples: 100000
overwrite_cache: true
preprocessing_num_workers: 8
### output
output_dir: ${OUTPUT_DIR}
logging_steps: 10
save_steps: 200
plot_loss: true
overwrite_output_dir: true
### train
per_device_train_batch_size: 4
gradient_accumulation_steps: 4
learning_rate: 2.0e-4
num_train_epochs: 2.0
lr_scheduler_type: cosine
warmup_ratio: 0.03
bf16: true
ddp_timeout: 180000000
🔑
template: minicpm5is MANDATORY. It reproduces the model's ownchat_template.jinjabyte-for-byte — ChatML with MiniCPM5-2B Think mode, MiniCPM5-1B Think / No-think modes, plus XML tool calling.Do NOT use
template: empty. LLaMA-Factory does not delegate to the tokenizer's jinja;emptyis a genuinely empty template (bare{{content}}slots, no role markers, no EOS replacement, ReAct-style tools) that trains on a layout the model has never seen.llama3/qwen/ etc. are equally wrong. Requires LLaMA-Factory from source — see step 1.
4. Train
CUDA_VISIBLE_DEVICES=${GPU_ID} llamafactory-cli train ${OUTPUT_DIR}/lora_sft.yaml
For multi-GPU: prepend FORCE_TORCHRUN=1 and set NPROC_PER_NODE=8.
5. Validate
Loss should decrease monotonically; you should see lines like:
{'loss': 4.19, 'learning_rate': 0.000192, 'epoch': 0.2}
{'loss': 3.62, 'learning_rate': 0.000001, 'epoch': 1.0}
After training, the LoRA adapter is at ${OUTPUT_DIR}/. Sanity-check inference:
import torch
from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer
base = AutoModelForCausalLM.from_pretrained("${BASE_MODEL}", torch_dtype=torch.bfloat16, device_map="auto").eval()
model = PeftModel.from_pretrained(base, "${OUTPUT_DIR}").eval()
tok = AutoTokenizer.from_pretrained("${BASE_MODEL}")
inputs = tok.apply_chat_template([{"role":"user","content":"1+1=?"}], add_generation_prompt=True, enable_thinking=True, return_tensors="pt", return_dict=True).to(model.device)
print(tok.decode(model.generate(**inputs, max_new_tokens=32, do_sample=False)[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True))
Coherent answer ⇒ ✅. Gibberish ⇒ check template: minicpm5 in the YAML. (A clean loss curve does not confirm the template is right — a mismatched template trains just as smoothly.)
Merge LoRA for serving
cat > ${OUTPUT_DIR}/merge.yaml <<EOF
model_name_or_path: ${BASE_MODEL}
adapter_name_or_path: ${OUTPUT_DIR}
template: minicpm5
finetuning_type: lora
export_di
자주 묻는 질문
어떤 데이터 형식이 필요한가요?
sharegpt 또는 messages 형식을 사용하며, 각 줄에 대화 하나가 들어 있습니다.
왜 별도 환경을 써야 하나요?
LLaMA-Factory가 vLLM 같은 서빙 도구와 충돌할 수 있으므로, 자체 환경을 가져야 한다고 이 스킬은 경고합니다.
DPO도 지원하나요?
네. 이 스킬은 LLaMA-Factory가 SFT와 DPO 학습을 모두 지원한다고 설명합니다.
상세 정보
작성자의 원본 설명
Fine-tune MiniCPM5-1B or MiniCPM5-2B with LLaMA-Factory (YAML-driven SFT / DPO / WebUI). Use when the user wants to fine-tune via LLaMA-Factory, llamafactory-cli, mentions YAML configs, WebUI, or asks for the most-documented community framework.
repo: OpenBMB/MiniCPM
인기도
- GitHub 스타
- 12k
- 순위
- #11541
- 라이선스
- Apache-2.0
- 업데이트
- 2026. 9. 21.
댓글
- …
이 저장소의 다른 스킬
minicpm5-deploy-litert
12k에이전트가 Google의 LiteRT-LM 런타임과 하나의 모델 파일로 컴퓨터나 Android 휴대폰에서 MiniCPM5 모델을 실행하도록 돕습니다.
minicpm5-deploy-llama-cpp
12k에이전트에게 llama.cpp와 미리 만들어진 GGUF 파일로 CPU나 가정용 그래픽 카드에서 MiniCPM5 모델을 실행하는 방법을 보여 줍니다.
minicpm5-deploy-lmstudio
12k에이전트가 채팅 창이 있는 데스크톱 앱 LM Studio에서 MiniCPM5 모델을 실행하고, OpenAI 방식의 로컬 서버를 시작하도록 돕습니다.
minicpm5-deploy-mlx
12k에이전트가 Apple의 MLX 프레임워크로 Apple Silicon Mac에서 MiniCPM5 모델을 직접 실행해, 빠른 로컬 채팅과 텍스트 생성을 하도록 돕습니다.