minicpm5-finetune-ms-swift
Qué hace
Esta skill guía a tu IA para entrenar MiniCPM5 con ms-swift, un conjunto de herramientas de entrenamiento. Es para personas que quieren usar el comando swift para hacer ajuste fino o entrenamiento de preferencias.
Cuándo usarla
- ✓Cuando quieres ejecutar swift sft o swift rlhf sobre un modelo MiniCPM5.
- ✓Cuando entrenas MiniCPM5-2B y necesitas su versión concreta de ms-swift y su plantilla.
- ✓Cuando quieres usar Megatron-SWIFT para el entrenamiento.
Link de la skill
https://github.com/OpenBMB/MiniCPM/blob/main/skills/minicpm5-finetune-ms-swift/SKILL.mdCópialo y pégalo en tu IA (Claude, ChatGPT o Cursor) pidiéndole que siga las instrucciones.
Cómo usar
La forma más fácil: copia el mensaje y pégalo en tu IA. Ella lee la skill y sigue las instrucciones.
Mensaje listo para pegar
Para Claude Code, Codex o Cursor: ejecútalo en la carpeta del proyecto y la skill queda instalada.
Descarga el SKILL.md y ponlo en la carpeta de skills de tu agente.
Ejemplo de qué pedirle a la IA
“Entrena MiniCPM5-1B con LoRA usando ms-swift sobre mi archivo de mensajes.”
5 skills nuevas por semana. 1 minuto de lectura.
Cómo funciona
La skill elige la versión de ms-swift y la plantilla correctas para tu modelo, la instala y arranca un entrenamiento LoRA con el comando swift.
Contenido técnico (SKILL.md original)
Texto original del autor, en inglés, directo de 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
Preguntas frecuentes
¿Qué plantilla corresponde a cada modelo?
La skill usa la plantilla minicpm5 para MiniCPM5-1B y la plantilla minicpm5_2b para MiniCPM5-2B.
¿Qué cambió en los argumentos?
La skill indica que ms-swift 4.x usa --tuner_type lora, mientras que las versiones anteriores usaban --train_type.
¿Qué formato de datos se usa?
Cada línea contiene una lista messages con los campos role y content.
Detalles
Descripción original del autor
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
Popularidad
- Estrellas en GitHub
- 12 mil
- Posición en el ranking
- #11542
- Licencia
- Apache-2.0
- Actualizada
- 21/9/2026
Comentarios
- …
Más skills de este repositorio
minicpm5-deploy-litert
12 milPermite que tu agente ejecute modelos MiniCPM5 en un ordenador o en un teléfono Android con el entorno de ejecución LiteRT-LM de Google, usando un solo archivo de modelo.
minicpm5-deploy-llama-cpp
12 milMuestra a tu agente cómo ejecutar modelos MiniCPM5 con llama.cpp en una CPU o en una tarjeta gráfica doméstica, usando archivos GGUF ya preparados.
minicpm5-deploy-lmstudio
12 milAyuda a tu agente a ejecutar modelos MiniCPM5 en LM Studio, una app de escritorio con ventana de chat, e iniciar su servidor local compatible con OpenAI.
minicpm5-deploy-mlx
12 milPermite que tu agente ejecute modelos MiniCPM5 de forma nativa en Macs con Apple Silicon, con el framework MLX de Apple, para chat y texto local rápido.
Skills parecidas
pytorch-patterns
280 milAyuda a tu agente a usar PyTorch para modelos de machine learning. Aplica buenas prácticas para entrenar modelos de forma eficiente y obtener resultados reproducibles.
evm-token-decimals
280 milAyuda a tu agente a evitar errores con números decimales en distintas redes blockchain. Asegura que los valores de los tokens sean exactos en transacciones y cálculos.
ito-inference
280 milPermite a tu agente comprobar la disponibilidad de modelos de IA. Conecta la solicitud de cómputo con el servicio de modelo listo.