本文へスキップ
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がスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/OpenBMB/MiniCPM/blob/main/skills/minicpm5-finetune-ms-swift/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

AIへの頼み方の例

“ms-swiftを使い、LoRAでMiniCPM5-1Bを、私のmessagesファイルを使って学習させてください。”

毎週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

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル