llm-trainer / README.md
Nekochu's picture
add CPU bold in header, update short_description
713bdc3 verified
|
Raw
History Blame Contribute Delete
3.24 kB
---
title: LLM Trainer
emoji: "\U0001F3CB"
colorFrom: yellow
colorTo: red
sdk: gradio
sdk_version: 6.15.2
python_version: "3.13"
app_file: app.py
pinned: false
license: mit
tags:
- llm
- lora
- qlora
- sft
- fine-tuning
- fine-tuning-tools
- training
- cpu
- deslop
- gradio-theme
short_description: QLoRA SFT training + deslop - CPU
---
# LLM QLoRA SFT Trainer
QLoRA training pipeline for any HuggingFace causal LM. Works on CPU (HF Space) or GPU (local). Uses 4-bit quantization when model is pre-quantized (bnb-4bit). Default model: unsloth/gemma-4-E2B-it.
## Steps (each optional)
1. **Deslop** -- Remove AI slop phrases via FTPO training ([auto-antislop](https://github.com/sam-paech/auto-antislop)-style)
2. **SFT QLoRA** -- Fine-tune on your chat dataset (TRL SFTTrainer + Adafactor + gradient checkpointing)
## Web UI
- Upload a dataset or enter a HuggingFace dataset ID (supports `[:N]` slicing, e.g. `HuggingFaceH4/no_robots[:500]`)
- Select model from dropdown (auto-populated from unsloth org) or type any model ID
- Auto-detects dataset format: messages, ShareGPT, Alpaca, text
- Check which steps to run, click "Start Training"
- Stop training anytime with the red "Stop Training" button
- Download the QLoRA adapter ZIP
- Chat tab with streaming inference and thinking mode toggle
## CLI Usage
```bash
pip install -r requirements.txt
# SFT on GPU
python app.py --sft --dataset data.jsonl --device cuda
# SFT on CPU (use 4-bit model for faster training)
python app.py --sft --dataset data.jsonl --device cpu
# Deslop + SFT
python app.py --deslop --sft --dataset data.jsonl
# From HuggingFace dataset
python app.py --sft --hf-dataset HuggingFaceH4/no_robots
# No args = launch Gradio web UI
python app.py
```
### CLI Options
| Flag | Default | Description |
|------|---------|-------------|
| `--model` | unsloth/gemma-4-E2B-it-unsloth-bnb-4bit | HuggingFace model ID |
| `--dataset` | | Path to .jsonl/.csv/.parquet/.txt |
| `--hf-dataset` | | HuggingFace dataset ID |
| `--device` | auto | `auto`, `cpu`, or `cuda` |
| `--deslop` | | Run deslop FTPO |
| `--sft` | | Run SFT QLoRA |
| `--epochs` | 1 | Training epochs |
| `--lr` | 2e-4 | Learning rate |
| `--rank` | 16 | LoRA rank |
| `--max-seq` | 1024 | Max sequence length |
## Performance (300 samples, 1 epoch)
| Model Gemma-4 | CPU (Space) | GPU (local) | Peak RAM |
|---|---|---|---|
| E2B 4-bit | ~5h | ~15 min | ~8 GB |
| E4B 4-bit | ~8h | ~30 min | ~13 GB |
Note: [Heretic abliteration](https://github.com/p-e-w/heretic) with winsorization q=0.95 (default mlabonne dataset) was too slow on CPU, full run ~25h (20 trials).
## Features
- Model-agnostic: works with any HF causal LM
- Auto GPU/CPU detection with per-device optimized configs
- 4-bit QLoRA on CPU via bitsandbytes
- Auto-detect dataset format (messages, ShareGPT, Alpaca, text)
- Dynamic model dropdown from unsloth org (filtered, <12B params)
- Chat with streaming, thinking mode toggle, system prompt
- Browser disconnect auto-stops training
- Configurable training time limit via `MAX_HOUR_TRAINING_TIME` env var
- RAM estimation from HF API before model download
- Per-session logs (private, not shared between users)
- chunked_nll loss for lower peak memory