Skills

Minicpm5 Finetune Xtuner

Fine-tune MiniCPM5-1B with xtuner (mmengine config-driven SFT).

Install

npx skills add OpenBMB/MiniCPM --skill minicpm5-finetune-xtuner -g -a claude-code -y
Repository
OpenBMB/MiniCPM11.8k
Category
Engineering
Updated
1mo ago
License
Apache-2.0
Context cost
Mediumabout 1,682 tokens
Runs scripts
No, instructions only

What it does

Fine-tune MiniCPM5-1B with xtuner (mmengine config-driven SFT). Use when the user mentions "xtuner", "mmengine", InternLM's training framework, or wants config-file-driven training.

Fine-tune MiniCPM5-1B with xtuner

mmengine config-driven SFT. Uses Python config files (not YAML) and integrates with mmengine's runner / hook system.

Required input

VarExampleDefault
BASE_MODELopenbmb/MiniCPM5-1Brequired
DATApath to messages-format jsonlrequired
WORK_DIR./runs/minicpm5_xtunerrequired

Steps

1. Install (once)

pip install "xtuner==0.2.0"
# Replace opencv-python with the headless variant (avoids libGL linkage)
pip install --force-reinstall opencv-python-headless
pip uninstall -y opencv-python

2. Save the config, ${WORK_DIR}/minicpm5_lora.py

import torch
from datasets import load_dataset
from mmengine.dataset import DefaultSampler
from mmengine.hooks import (CheckpointHook, DistSamplerSeedHook, IterTimerHook,
                            LoggerHook, ParamSchedulerHook)
from mmengine.optim import AmpOptimWrapper, CosineAnnealingLR, LinearLR
from peft import LoraConfig
from torch.optim import AdamW
from transformers import AutoModelForCausalLM, AutoTokenizer

from xtuner.dataset import process_hf_dataset
from xtuner.dataset.collate_fns import default_collate_fn
from xtuner.dataset.map_fns import openai_map_fn, template_map_fn_factory
from xtuner.engine.hooks import DatasetInfoHook
from xtuner.engine.runner import TrainLoop
from xtuner.model import SupervisedFinetune
from xtuner.utils import PROMPT_TEMPLATE

pretrained_model_name_or_path = "${BASE_MODEL}"      # ← replace
data_path = "${DATA}"                                # ← replace
prompt_template = PROMPT_TEMPLATE.qwen_chat          # 🔑 ChatML, DO NOT use llama3_chat
max_length = 2048

batch_size = 4
accumulative_counts = 4
max_epochs = 2
lr = 2e-4
warmup_ratio = 0.03

tokenizer = dict(type=AutoTokenizer.from_pretrained,
                 pretrained_model_name_or_path=pretrained_model_name_or_path,
                 trust_remote_code=False, padding_side="right")
Read the whole SKILL.md on GitHub

More in Engineering