minicpm5-finetune-xtuner
Skill này làm gì
Skill này hướng dẫn AI huấn luyện MiniCPM5-1B bằng xtuner, một bộ công cụ dùng file cấu hình Python. Skill dành cho người theo kiểu thiết lập huấn luyện của mmengine.
Khi nào nên dùng
- ✓Khi bạn muốn fine-tune MiniCPM5-1B bằng xtuner.
- ✓Khi bạn thích file cấu hình Python hơn YAML để huấn luyện.
- ✓Khi nhóm bạn đã dùng mmengine và muốn huấn luyện MiniCPM5 theo cùng cách.
Liên kết skill
https://github.com/OpenBMB/MiniCPM/blob/main/skills/minicpm5-finetune-xtuner/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Giúp tôi thiết lập một cấu hình huấn luyện xtuner để fine-tune MiniCPM5-1B trên file dữ liệu của tôi.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Skill cài xtuner và gói OpenCV headless, viết một cấu hình Python cho huấn luyện LoRA, rồi chạy huấn luyện bằng công cụ xtuner.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
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
Câu hỏi thường gặp
Vì sao thay gói OpenCV?
Skill thay opencv-python bằng bản headless, để tránh lỗi liên kết libGL.
Hướng dẫn này dành cho model nào?
Skill được viết cho MiniCPM5-1B.
Cần dữ liệu gì?
Cần một file theo định dạng messages, mỗi dòng là một cuộc hội thoại.
Chi tiết
Mô tả gốc của tác giả
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
Độ phổ biến
- Sao GitHub
- 12k
- Vị trí xếp hạng
- #11545
- Giấy phép
- Apache-2.0
- Cập nhật
- 21/9/2026
Bình luận
- …
Thêm skill từ kho mã này
minicpm5-deploy-litert
12kGiúp agent chạy các model MiniCPM5 trên máy tính hoặc điện thoại Android bằng runtime LiteRT-LM của Google, chỉ với một file model.
minicpm5-deploy-llama-cpp
12kChỉ cho agent cách chạy model MiniCPM5 bằng llama.cpp trên CPU hoặc card đồ họa gia đình, dùng file GGUF có sẵn.
minicpm5-deploy-lmstudio
12kGiúp agent chạy các model MiniCPM5 trong LM Studio, ứng dụng desktop có cửa sổ chat, và khởi động máy chủ cục bộ kiểu OpenAI của nó.
minicpm5-deploy-mlx
12kGiúp agent chạy các model MiniCPM5 trực tiếp trên máy Mac Apple Silicon bằng framework MLX của Apple, để chat và sinh văn bản cục bộ nhanh.
Skill tương tự
pytorch-patterns
280kGiúp agent của bạn dùng PyTorch cho các mô hình học máy. Áp dụng thực hành tốt nhất để huấn luyện mô hình hiệu quả và đảm bảo kết quả có thể lặp lại.
evm-token-decimals
280kGiúp agent tránh lỗi về số thập phân khi làm việc với các mạng blockchain khác nhau. Đảm bảo giá trị token chính xác trong giao dịch và phép tính.
ito-inference
280kGiúp agent kiểm tra xem các mô hình AI đã sẵn sàng để dùng chưa. Kết nối yêu cầu tài nguyên tính toán với dịch vụ mô hình đã sẵn sàng.