Skip to content
Skillpedia
Machine learning12k Β· #11545

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.md

Copy 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

Use this skill to help me: https://github.com/OpenBMB/MiniCPM/blob/main/skills/minicpm5-finetune-xtuner/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute β†’

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

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills