
Minicpm5 Finetune Trl
Fine-tune MiniCPM5-1B or MiniCPM5-2B with bare-metal TRL + PEFT, including...
Install
npx skills add OpenBMB/MiniCPM --skill minicpm5-finetune-trl -g -a claude-code -y- Repository
- OpenBMB/MiniCPM11.8k
- Category
- Engineering
- Updated
- 1mo ago
- License
- Apache-2.0
- Context cost
- Lightabout 1,472 tokens
- Runs scripts
- No, instructions only
What it does
Fine-tune MiniCPM5-1B or MiniCPM5-2B with bare-metal TRL + PEFT, including assistant-only loss via a chat-template patch. Use when the user wants minimal Python, no YAML, full control, or asks for "TRL", "SFTTrainer", "PEFT", "LoraConfig", "assistant_only_loss".
Fine-tune MiniCPM5-1B and MiniCPM5-2B with TRL + PEFT
Bare-metal Python recipe with assistant-only loss mask. Minimal abstractions, full control.
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_trl | required |
Steps
1. Install (once)
# latest (CUDA 13.x driver hosts)
pip install "torch>=2.11" "torchvision" \
"trl>=0.21" "peft>=0.13" "transformers>=5.6,<6" \
datasets accelerate
# fallback for CUDA 12.x driver hosts:
# pip install "torch==2.7.1" "torchvision==0.22.1" \
# "trl==0.20.0" "peft==0.11.1" "transformers==4.57.3" \
# datasets accelerate
2. Patch the tokenizer with a training-only chat template
Save as train_lora.py:
import json, os, torch
from datasets import Dataset
from peft import LoraConfig, get_peft_model
from transformers import AutoModelForCausalLM, AutoTokenizer, set_seed
from trl import SFTConfig, SFTTrainer
BASE = os.environ["BASE_MODEL"]
DATA = os.environ["DATA"]
OUT = os.environ["OUTPUT_DIR"]
