minicpm5-finetune-xtuner
What it does
This skill guides your AI through training MiniCPM5-1B with xtuner, a toolkit that uses Python config files. It is for people who use the mmengine style of training setup.
When to use it
- βWhen you want to fine-tune MiniCPM5-1B with xtuner.
- βWhen you prefer Python config files over YAML for training.
- βWhen your team already uses mmengine and wants to train MiniCPM5 the same way.
Skill link
https://github.com/OpenBMB/MiniCPM/blob/main/skills/minicpm5-finetune-xtuner/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
βHelp me set up an xtuner training config to fine-tune MiniCPM5-1B on my dataset file.β
5 new skills a week. 1 minute to read.
How it works
The skill installs xtuner and a headless OpenCV package, writes a Python config for LoRA training, and runs training with the xtuner tools.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
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
| Var | Example | Default |
|---|---|---|
BASE_MODEL |
openbmb/MiniCPM5-1B |
required |
DATA |
path to messages-format jsonl | required |
WORK_DIR |
./runs/minicpm5_xtuner |
required |
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")
model = dict(
type=SupervisedFinetune, use_varlen_attn=False,
llm=dict(type=AutoModelForCausalLM.from_pretrained,
pretrained_model_name_or_path=pretrained_model_name_or_path,
trust_remote_code=False, torch_dtype=torch.bfloat16),
lora=dict(type=LoraConfig, r=16, lora_alpha=32, lora_dropout=0.05,
bias="none", task_type="CAUSAL_LM",
target_modules=["q_proj","k_proj","v_proj","o_proj","gate_proj","up_proj","down_proj"]),
)
train_dataset = dict(
type=process_hf_dataset,
dataset=dict(type=load_dataset, path="json", data_files=dict(train=data_path)),
tokenizer=tokenizer, max_length=max_length,
dataset_map_fn=openai_map_fn, # π messages format
template_map_fn=dict(type=template_map_fn_factory, template=prompt_template),
remove_unused_columns=True, shuffle_before_pack=True,
pack_to_max_length=False, use_varlen_attn=False,
)
train_dataloader = dict(
batch_size=batch_size, num_workers=2,
dataset=train_dataset,
sampler=dict(type=DefaultSampler, shuffle=True),
collate_fn=dict(type=default_collate_fn, use_varlen_attn=False),
)
optim_wrapper = dict(
type=AmpOptimWrapper,
optimizer=dict(type=AdamW, lr=lr, betas=(0.9, 0.999), weight_decay=0),
clip_grad=dict(max_norm=1, error_if_nonfinite=False),
accumulative_counts=accumulative_counts, loss_scale="dynamic", dtype="bfloat16",
)
param_scheduler = [
dict(type=LinearLR, start_factor=1e-2, # π use 1e-2 not 1e-5 (default is too small)
by_epoch=True, begin=0, end=warmup_ratio * max_epochs, convert_to_iter_based=True),
dict(type=CosineAnnealingLR, eta_min=0.0, by_epoch=True,
begin=warmup_ratio * max_epochs, end=max_epochs, convert_to_iter_based=True),
]
train_cfg = dict(type=TrainLoop, max_epochs=max_epochs)
default_hooks = dict(
timer=dict(type=IterTimerHook),
logger=dict(type=LoggerHook, log_metric_by_epoch=False, interval=10),
param_scheduler=dict(type=ParamSchedulerHook),
checkpoint=dict(type=CheckpointHook, by_epoch=False, interval=200, max_keep_ckpts=2),
sampler_seed=dict(type=DistSamplerSeedHook),
)
custom_hooks = [dict(type=DatasetInfoHook, tokenizer=tokenizer)]
env_cfg = dict(cudnn_benchmark=False, mp_cfg=dict(mp_start_method="fork"), dist_cfg=dict(backend="nccl"))
log_level = "INFO"
load_from = None
resume = False
randomness = dict(seed=42, deterministic=False)
log_processor = dict(by_epoch=False)
π **`PROMPT
FAQ
Why replace the OpenCV package?
The skill swaps opencv-python for the headless version, which avoids a libGL linkage problem.
Which model is this guide for?
The skill is written for MiniCPM5-1B.
What data does it need?
It needs a file in messages format, with one conversation per line.
Details
Original description by the author
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.
repo: OpenBMB/MiniCPM
Popularity
- GitHub stars
- 12k
- Ranking position
- #11545
- 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.