Open model fine tuning
Checks if fine tuning is worth it, then trains an open model with LoRA or DPO, so it reliably follows your format.
What we improved
Fixed the headline QLoRA example. It passed quantization_config to SFTTrainer, which has no such argument. The 4-bit model is now loaded with AutoModelForCausalLM and BitsAndBytesConfig and handed to SFTTrainer with the LoRA config, as a co
Improved by YourAISkill from the original by ericrisco, under its MIT licence. The download includes the author's licence and a CHANGES.md listing every change. Both Claude reviews read the improved version.
Claude's review
8/10 Sound fine-tune vs RAG decision gate, current TRL and PEFT code with version renames, pre-flight checks, preference stage choices and evaluation discipline.
We asked Claude the question you would ask: would I be glad I installed this? Two separate reviews, the second blind to the first, must both rate a skill 7 or higher before we sell it.
In detail
Use when adapting an open-weight model to a target form or behavior — tone, output format, reasoning pattern — via LoRA/QLoRA or full fine-tuning with TRL SFTTrainer, then preference optimization (DPO/ORPO/KTO/GRPO), and for fine-tune vs prompt vs RAG. NOT adding facts to a model (that is rag); NOT the single-GPU Unsloth backend or GGUF export (that is unsloth).
How you use it
- Add it to your pack, then download your pack (1 credit).
- In Claude, open Customize > Skills and upload the zip. Code execution needs to be on under Settings > Capabilities.
- Ask Claude for the job in your own words. It uses the skill when your request matches what it does. Step by step guide
Safety check
Nothing risky found: no hidden instructions, no download and run, no reading of saved passwords or keys.
An automated scan lowers risk but cannot promise zero risk. How we check skills
Preview
The first lines of SKILL.md
---
name: finetuning
description: "Decide whether to fine-tune an open-weight LLM, then do it with Hugging Face TRL and PEFT: LoRA, QLoRA or full fine-tuning with SFTTrainer, then optional preference optimization (DPO, ORPO, KTO, GRPO with a reward function). Covers the fine-tune vs prompt vs RAG decision, memory sizing, data formats and chat templates, hyperparameters, catastrophic forgetting, held-out evaluation and merging adapters for serving. Use when someone wants a model to reliably adopt a tone, output format or reasoning pattern, asks LoRA vs QLoRA vs full fine-tuning, sets up SFT then DPO or GRPO, or debugs a run (adapter learned nothing, eval loss rising, model forgot general skills). Not for giving a model new or changing facts, which is a retrieval (RAG) job."
tags: [finetuning, lora, qlora, sft, dpo, grpo, peft, trl, preference-optimization]
---
<!-- Modified by YourAISkill (youraiskill.com) on 2 December 2026 from the original by ericrisco. See CHANGES.md. -->
# finetuning: teach an open model a form or behavior, not a fact
You own the discipline of **adapting an open-weight model**: deciding whether to fine-tune at all, then running SFT and (optionally) preference optimization with `trl` + `peft`. You are judged by whether the tuned model reliably produces the target **form or behavior** on a held-out set, not by train loss and not by vibes.
The one sentence that routes half of all "should I fine-tune?" questions correctly: **fine-tuning teaches form and behavior; retrieval (RAG) supplies facts.** "Know our latest prices, docs, tickets" is retrieval. "Sound like us, always emit this JSON, follow this reasoning pattern" is here.
## Decision gate: try this BEFORE reaching for a GPU
Fine-tuning is the last lever, not the first. Each row is a real off-ramp.
| If the goal is... | Do this first | Fine-tune only when... |
|---|---|---|
| The model should *know* current or company facts | **RAG**: retrieve and ground | never for facts; facts go stale, weights don't update |
| One-off format or tone, small volume | **Prompt + few-shot examples** | the prompt is huge, brittle, or you pay for it on every call |
| Behavior depends on a long document | **Put it in the context** | it won't fit, or per-call token cost is the bottleneck |
| Consistent form or behavior at scale, latency or cost sensitive | | prompting plateaus AND you have (or can build) good examples |
| A capability the base model just can't do | | you have demonstrations or a reward signal for it |
> The cheapest fine-tune is the one you didn't need. Prompt + RAG solves most "make it behave" asks at zero training cost and updates instantly. Fine-tune when that ceiling is real and measured, and you can afford to re-run training whenever the base model or data changes.
Before training, also check the base model's licence on its model card (Llama ships under Meta's community licence with usage conditions, Gemma under Google's own terms, Qwen and Mistral vary by model). Licences change, so read the card rather than relying on memory.
## Check versions before copying code
`trl`, `transformers`, `peft` and `bitsandbytes` change argument names often. Run `pip show trl transformers peft bitsandbytes` and read the TRL docs for the installed version. Renames you will meet in older tutorials: `SFTConfig(max_seq_length=...)` is now `max_length`; trainers take `processing_class=` instead of `tokenizer=`; transformers now prefers `dtype=` over `torch_dtype=` (from 4.56); and recent TRL releases moved some trainers (ORPO among them) under `trl.experimental`. If an argument below is rejected, look it up for your version rather than deleting it.
## LoRA vs QLoRA vs full fine-tuning
| Method | What trains | Memory for a 7 to 8B model | Use when |
|---|---|---|---|
| **Full FT** | every weight | roughly 16 bytes per parameter with AdamW in mixed precision, so over 100 GB before activations: multi-GPU or offload | you have the hardware, a large high-quality corpus, and adapters underfit |
| **LoRA** | small low-rank adapters; frozen bf16 base | about 2 bytes per parameter for the base (about 15 GB) plus activations | the base fits in bf16 and you want speed and portable adapters |
| **QLoRA** | LoRA adapters over a frozen **4-bit NF4** base | about 0.5 bytes per parameter for the base (about 5 GB) plus activations; fits a single 24 GB GPU | the default; tune large models on one GPU |
...From ericrisco's repository, MIT licence.
Related skills
-
Checked
ML Training Recipes
Battle tested PyTorch recipes for training and fine tuning models, plus fixes for loss spikes and GPU memory.
8/101 credit -
Checked
PyTorch Geometric GNNs
Builds graph neural networks with PyTorch Geometric, so you pick the right layers and avoid edge index mistakes.
7/101 credit -
Checked
PyTorch training loops
Debugs PyTorch training, catching silent loop bugs and setting up mixed precision, so models actually learn.
7/101 credit -
Checked
AMD GPU PyTorch profiler
Traces slow AMD GPU work back to the PyTorch or Triton layer that caused it, so you know exactly what to optimise.
7/101 credit -
Checked
Hugging Face GPU demos
Writes Gradio code for Hugging Face ZeroGPU Spaces, handling quotas and CUDA limits, so your demo runs.
8/101 credit -
Checked
cuEquivariance in JAX
Runs equivariant tensor-product models in JAX with cuEquivariance, with working CPU and layout recipes.
7/101 credit