minicpm5-finetune-ms-swift
What it does
This skill guides your AI through training MiniCPM5 with ms-swift, a training toolkit. It is for people who want to use the swift command to run fine-tuning or preference training.
When to use it
- ✓When you want to run swift sft or swift rlhf on a MiniCPM5 model.
- ✓When you are training MiniCPM5-2B and need its specific ms-swift version and template.
- ✓When you want to use Megatron-SWIFT for training.
Skill link
https://github.com/OpenBMB/MiniCPM/blob/main/skills/minicpm5-finetune-ms-swift/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agent’s skills folder.
Example of what to ask your AI
“Train MiniCPM5-1B with LoRA using ms-swift on my messages file.”
5 new skills a week. 1 minute to read.
How it works
The skill picks the correct ms-swift version and template for your model, installs it, and starts a LoRA training run with the swift command.
Technical content (original SKILL.md)
Original text by the author, straight from 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_typeto--tuner_type. Use--tuner_type lorafor 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 minicpm5for MiniCPM5-1B or--template minicpm5_2bfor MiniCPM5-2B.minicpm5_2b is not registered: the active Python environment is using an older ms-swift release. Installms-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 setPYTHONNOUSERSITE=1to ignore user-sitetransformers.
Reference
FAQ
Which template goes with which model?
The skill uses the minicpm5 template for MiniCPM5-1B and the minicpm5_2b template for MiniCPM5-2B.
What changed in the arguments?
The skill notes that ms-swift 4.x uses --tuner_type lora, where older versions used --train_type.
What data format is used?
Each line holds a messages list with role and content fields.
Details
Original description by the author
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
Popularity
- GitHub stars
- 12k
- Ranking position
- #11542
- License
- Apache-2.0
- Updated
- 9/21/2026
Comments
- …
More skills from this repository
minicpm5-deploy-litert
12kLets your agent run MiniCPM5 models on a computer or Android phone with Google's LiteRT-LM runtime, using one model file.
minicpm5-deploy-llama-cpp
12kShows your agent how to run MiniCPM5 models with llama.cpp on a CPU or a home graphics card, using ready-made GGUF files.
minicpm5-deploy-lmstudio
12kHelps your agent run MiniCPM5 models in LM Studio, a desktop app with a chat window, and start its local OpenAI-style server.
minicpm5-deploy-mlx
12kLets your agent run MiniCPM5 models natively on Apple Silicon Macs with Apple's MLX framework, for fast local chat and text generation.
Similar skills
pytorch-patterns
280kHelps your agent use PyTorch for machine learning models. It applies best practices for efficient model training and ensures reproducible results.
evm-token-decimals
280kHelps your agent avoid errors with decimal numbers across different blockchain networks. It ensures token values are accurate in transactions and calculations.
ito-inference
280kLets your agent check the availability of AI models for use. It connects the compute request with the ready model service.