Fine-tuning
The official training entry is Trainer. This chapter first fine-tunes DistilBERT on rotten_tomatoes (a short run works on CPU), then sketches PEFT LoRA. Full-parameter 7B training is not a beginner task.
VRAM warning: DistilBERT classification fits a 4 GB GPU or a CPU (slowly). Full-parameter causal-LM fine-tunes OOM easily—use LoRA, or revisit batches and gradients in the PyTorch course. Without a GPU, set a tiny max_steps so the script merely runs.
Trainer: review sentiment
On CPU, try per_device_train_batch_size=4 and raw["train"].select(range(512)). For loop internals, compare this site’s PyTorch tutorial.
Infer the fine-tuned model
Labels may show up as LABEL_0 / LABEL_1. Pass id2label={0: "NEGATIVE", 1: "POSITIVE"} into from_pretrained.
Minimal PEFT LoRA sketch
Train low-rank adapters; freeze the base. Fits a small causal LM such as Qwen/Qwen2.5-0.5B-Instruct (GPU recommended):
pip install peft. After training, model.save_pretrained("./qwen-lora") stores only the adapter (MBs). Reload with PeftModel.from_pretrained(base, "./qwen-lora"). Data wrangling is outlined in Practical Examples.
When not to use Trainer
Agents can draft training scripts via Hugging Face Skills; you still own VRAM and licenses.