minicpm5-finetune-ms-swift
Skill này làm gì
Skill này hướng dẫn AI huấn luyện MiniCPM5 bằng ms-swift, một bộ công cụ huấn luyện. Skill dành cho người muốn dùng lệnh swift để chạy fine-tune hoặc huấn luyện theo ưu tiên.
Khi nào nên dùng
- ✓Khi bạn muốn chạy swift sft hoặc swift rlhf trên một model MiniCPM5.
- ✓Khi bạn huấn luyện MiniCPM5-2B và cần đúng phiên bản ms-swift và template của nó.
- ✓Khi bạn muốn dùng Megatron-SWIFT để huấn luyện.
Liên kết skill
https://github.com/OpenBMB/MiniCPM/blob/main/skills/minicpm5-finetune-ms-swift/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Huấn luyện MiniCPM5-1B bằng LoRA với ms-swift trên file messages của tôi.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Skill chọn đúng phiên bản ms-swift và template cho model của bạn, cài đặt, rồi khởi động một lượt huấn luyện LoRA bằng lệnh swift.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
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
Câu hỏi thường gặp
Template nào đi với model nào?
Skill dùng template minicpm5 cho MiniCPM5-1B và template minicpm5_2b cho MiniCPM5-2B.
Có gì thay đổi ở các tham số?
Skill lưu ý ms-swift 4.x dùng --tuner_type lora, còn các phiên bản cũ dùng --train_type.
Định dạng dữ liệu là gì?
Mỗi dòng chứa một danh sách messages với các trường role và content.
Chi tiết
Mô tả gốc của tác giả
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
Độ phổ biến
- Sao GitHub
- 12k
- Vị trí xếp hạng
- #11542
- Giấy phép
- Apache-2.0
- Cập nhật
- 21/9/2026
Bình luận
- …
Thêm skill từ kho mã này
minicpm5-deploy-litert
12kGiúp agent chạy các model MiniCPM5 trên máy tính hoặc điện thoại Android bằng runtime LiteRT-LM của Google, chỉ với một file model.
minicpm5-deploy-llama-cpp
12kChỉ cho agent cách chạy model MiniCPM5 bằng llama.cpp trên CPU hoặc card đồ họa gia đình, dùng file GGUF có sẵn.
minicpm5-deploy-lmstudio
12kGiúp agent chạy các model MiniCPM5 trong LM Studio, ứng dụng desktop có cửa sổ chat, và khởi động máy chủ cục bộ kiểu OpenAI của nó.
minicpm5-deploy-mlx
12kGiúp agent chạy các model MiniCPM5 trực tiếp trên máy Mac Apple Silicon bằng framework MLX của Apple, để chat và sinh văn bản cục bộ nhanh.
Skill tương tự
pytorch-patterns
280kGiúp agent của bạn dùng PyTorch cho các mô hình học máy. Áp dụng thực hành tốt nhất để huấn luyện mô hình hiệu quả và đảm bảo kết quả có thể lặp lại.
evm-token-decimals
280kGiúp agent tránh lỗi về số thập phân khi làm việc với các mạng blockchain khác nhau. Đảm bảo giá trị token chính xác trong giao dịch và phép tính.
ito-inference
280kGiúp agent kiểm tra xem các mô hình AI đã sẵn sàng để dùng chưa. Kết nối yêu cầu tài nguyên tính toán với dịch vụ mô hình đã sẵn sàng.