Skills

Minicpm5 Finetune Unsloth

Fine-tune MiniCPM5-1B or MiniCPM5-2B with unsloth for tight-VRAM single-GPU LoRA / QLoRA.

Install

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

What it does

Fine-tune MiniCPM5-1B or MiniCPM5-2B with unsloth for tight-VRAM single-GPU LoRA / QLoRA. Use when the user wants "unsloth", "FastLanguageModel", QLoRA on a 24 GB consumer GPU, or asks for the smallest VRAM footprint.

Fine-tune MiniCPM5-1B and MiniCPM5-2B with unsloth

Single-GPU LoRA / QLoRA. Heavy custom kernels for memory savings (~2× reduction at 4-bit).

⚠️ Two install-time pins (read this BEFORE running):

  1. transformers==4.57.3, required if vLLM is in the same env (unsloth's vLLM coexistence patch only handles transformers ≤ 4.57.x).
  2. torch==2.7.1 + torchvision==0.22.1, pip install unsloth may pull a cu13 torch wheel that fails on cu12.x drivers (cuda.is_available() returns False).
pip install --force-reinstall "torch==2.7.1" "torchvision==0.22.1" "transformers==4.57.3"

Required input

VarExampleDefault
BASE_MODELopenbmb/MiniCPM5-2Brequired; openbmb/MiniCPM5-1B also works
DATApath to messages-format jsonlrequired
OUTPUT_DIR./runs/minicpm5_unslothrequired
LOAD_IN_4BITTrue (QLoRA, lowest VRAM) / False (LoRA bf16)False

Steps

1. Install (once), pin transformers to 4.57.3

pip install "unsloth>=2026.5"
pip install --force-reinstall "transformers==4.57.3"

🔑 transformers==4.57.3 is required if vLLM is in the same env. unsloth's vLLM coexistence patch only handles transformers ≤ 4.57.x; if you skip this pin you'll get a dataclass error at import time.

2. Train, save as train_unsloth.py

import json, os, torch
os.environ.setdefault("CUDA_VISIBLE_DEVICES", "0")

from unsloth import FastLanguageModel
from datasets import Dataset
from trl import SFTTrainer, SFTConfig

BASE = os.environ["BASE_MODEL"]
DATA = os.environ["DATA"]
OUT  = os.environ["OUTPUT_DIR"]

# 1. Load with unsloth's fast wrapper
model, tok = FastLanguageModel.from_pretrained(
    model_name=BASE,
    max_seq_length=2048,
    dtype=torch.bfloat16,
    load_in_4bit=os.environ.get("LOAD_IN_4BIT", "False") == "True",
    full_finetuning=False,
)
Read the whole SKILL.md on GitHub

More in Engineering