
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):
transformers==4.57.3, required if vLLM is in the same env (unsloth's vLLM coexistence patch only handles transformers ≤ 4.57.x).torch==2.7.1+torchvision==0.22.1,pip install unslothmay 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
| Var | Example | Default |
|---|---|---|
BASE_MODEL | openbmb/MiniCPM5-2B | required; openbmb/MiniCPM5-1B also works |
DATA | path to messages-format jsonl | required |
OUTPUT_DIR | ./runs/minicpm5_unsloth | required |
LOAD_IN_4BIT | True (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.3is 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 adataclasserror 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,
)
