본문으로 건너뛰기
Skillpedia
머신러닝12k · #11542

minicpm5-finetune-ms-swift

하는 일

이 스킬은 학습 도구 모음인 ms-swift로 MiniCPM5를 학습하도록 AI를 안내합니다. swift 명령으로 미세 조정이나 선호도 학습을 실행하려는 사람을 위한 스킬입니다.

사용하는 경우

  • ✓MiniCPM5 모델에서 swift sft 또는 swift rlhf를 실행하고 싶을 때.
  • ✓MiniCPM5-2B를 학습하며 그 모델에 맞는 ms-swift 버전과 템플릿이 필요할 때.
  • ✓학습에 Megatron-SWIFT를 사용하고 싶은 경우.

스킬 링크

https://github.com/OpenBMB/MiniCPM/blob/main/skills/minicpm5-finetune-ms-swift/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/OpenBMB/MiniCPM/blob/main/skills/minicpm5-finetune-ms-swift/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“제 messages 파일로 ms-swift를 사용해 LoRA 방식으로 MiniCPM5-1B를 학습해 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

이 스킬은 모델에 맞는 ms-swift 버전과 템플릿을 고르고, 설치한 뒤, swift 명령으로 LoRA 학습을 시작합니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

Fine-tune MiniCPM5-1B and MiniCPM5-2B with ms-swift

Select the version and template that match the model:

Model ms-swift version Arguments
MiniCPM5-1B PyPI 4.5.3 --model_type llama --template minicpm5
MiniCPM5-2B >=4.6.0.dev0 --model_type llama --template minicpm5_2b

Both models require transformers>=5.6.

ms-swift 4.x renamed --train_type to --tuner_type. Use --tuner_type lora for LoRA training.

Required input

Var Example Default
BASE_MODEL openbmb/MiniCPM5-2B required; openbmb/MiniCPM5-1B is also supported
TEMPLATE minicpm5_2b use minicpm5 for MiniCPM5-1B
DATA path to messages-format jsonl required
OUTPUT_DIR ./runs/minicpm5_swift required
GPU_ID 0 0

Each line of DATA: {"messages": [{"role":"...","content":"..."}, ...]}.

Steps

1. Install (once)

For MiniCPM5-1B:

pip install "ms-swift==4.5.3" "transformers>=5.6"

For MiniCPM5-2B:

git clone https://github.com/modelscope/ms-swift.git
cd ms-swift
git checkout 654e24f17b5d9f40ed4b9ee4c56a723320244db5
pip install -e .
pip install "transformers>=5.6,<5.17"

For Megatron-SWIFT:

pip install mcore-bridge==1.6.4

2. Train (LoRA SFT)

CUDA_VISIBLE_DEVICES=${GPU_ID} swift sft \
    --model "${BASE_MODEL}" \
    --model_type llama \
    --template "${TEMPLATE}" \
    --tuner_type lora \
    --dataset "${DATA}" \
    --output_dir "${OUTPUT_DIR}" \
    --num_train_epochs 2 \
    --per_device_train_batch_size 4 \
    --gradient_accumulation_steps 4 \
    --learning_rate 2e-4 \
    --lora_rank 16 --lora_alpha 32 --lora_dropout 0.05 \
    --target_modules q_proj k_proj v_proj o_proj gate_proj up_proj down_proj \
    --max_length 4096 \
    --warmup_ratio 0.03 \
    --bf16 true \
    --logging_steps 10 \
    --save_steps 200

Set TEMPLATE=minicpm5 for MiniCPM5-1B or TEMPLATE=minicpm5_2b for MiniCPM5-2B.

3. Validate

Loss should decrease over the first few hundred steps:

{'loss': 4.52, 'token_acc': 0.26, 'epoch': 0.04}
{'loss': 3.57, 'token_acc': 0.35, 'epoch': 1.00}

Adapter is at ${OUTPUT_DIR}/v0-${TIMESTAMP}/checkpoint-${STEP}/.

Merge for serving

swift export \
    --model "${BASE_MODEL}" \
    --adapters "${OUTPUT_DIR}/v0-${TIMESTAMP}/checkpoint-${STEP}" \
    --merge_lora true \
    --output_dir ./minicpm5-swift-merged

The merged model is a regular LlamaForCausalLM and serves with any minicpm5-deploy-* skill.

Full SFT / DPO / RLHF

Same flag surface, just swap the trainer:

# Full SFT
swift sft --tuner_type full ...

# DPO
swift rlhf --rlhf_type dpo \
    --model "${BASE_MODEL}" --model_type llama --template "${TEMPLATE}" \
    --dataset preference.jsonl \
    --output_dir ${OUTPUT_DIR} ...

# Megatron-SWIFT SFT
megatron sft \
    --model "${BASE_MODEL}" \
    --model_type llama \
    --template "${TEMPLATE}" \
    --dataset "${DATA}" \
    --finetune true \
    --output_dir "${OUTPUT_DIR}"

Set TEMPLATE=minicpm5 for MiniCPM5-1B or TEMPLATE=minicpm5_2b for MiniCPM5-2B.

For complete training options and configuration details, see the ms-swift command-line parameters and the Megatron-SWIFT quick start.

Multi-GPU

NPROC_PER_NODE=8 swift sft \
    --model "${BASE_MODEL}" --model_type llama --template "${TEMPLATE}" \
    --tuner_type lora --deepspeed default-zero2 \
    ...

Common pitfalls

  • Failed to automatically match model_type: add --model_type llama.
  • Failed to automatically match template_type: use --template minicpm5 for MiniCPM5-1B or --template minicpm5_2b for MiniCPM5-2B.
  • minicpm5_2b is not registered: the active Python environment is using an older ms-swift release. Install ms-swift>=4.6.0.dev0; the source installation above pins a known revision for reproducibility.
  • Conflict with LLaMA-Factory in same env: LLaMA-Factory pins transformers==4.52, ms-swift wants the latest (currently transformers ≥5.6). Use separate venvs, or set PYTHONNOUSERSITE=1 to ignore user-site transformers.

Reference

docs/finetune/ms_swift.md

자주 묻는 질문

모델마다 어떤 템플릿을 쓰나요?

MiniCPM5-1B에는 minicpm5 템플릿을, MiniCPM5-2B에는 minicpm5_2b 템플릿을 사용합니다.

인자에서 무엇이 바뀌었나요?

ms-swift 4.x에서는 이전 버전의 --train_type 대신 --tuner_type lora를 사용한다고 이 스킬은 알려 줍니다.

어떤 데이터 형식을 쓰나요?

각 줄에 role과 content 필드를 가진 messages 목록이 들어 있습니다.

상세 정보

작성자의 원본 설명

Fine-tune MiniCPM5-1B or MiniCPM5-2B with ms-swift or Megatron-SWIFT. Use when the user mentions "ms-swift", "swift sft", "swift rlhf", or "megatron sft". MiniCPM5-1B uses the PyPI release with `--template minicpm5`; MiniCPM5-2B requires `ms-swift>=4.6.0.dev0` with `--template minicpm5_2b`. Both use `--model_type llama`.

repo: OpenBMB/MiniCPM

인기도

GitHub 스타
12k
순위
#11542
라이선스
Apache-2.0
업데이트
2026. 9. 21.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬