Fine-tune a model
Adapt a small language model to your own data on a GPU.
The notebook
# Fine-tune a model Checks the GPU is visible, then sets up a small LoRA run. **This notebook needs a GPU compute attached to run.** Click the compute button in the top-right of the notebook header (it reads **Attach compute** until something is attached) to open the Attach compute dialog, then pick a running GPU compute. Running a cell without compute attached opens the same dialog.
import torch print(torch.cuda.is_available(), torch.cuda.get_device_name(0) if torch.cuda.is_available() else "no GPU")from transformers import AutoModelForCausalLM, AutoTokenizer MODEL = "Qwen/Qwen2.5-0.5B" tokenizer = AutoTokenizer.from_pretrained(MODEL) model = AutoModelForCausalLM.from_pretrained(MODEL).to("cuda")
Runtime requirements
- Python
- Python 3.11 (GenAI environment)
- Packages
- torch, transformers
- Sample data
- None
- Environment
- GenAI ยท GPU
Requires GPU / real compute
Training a language model needs a GPU, which a browser tab cannot provide.
The free trial includes 3 projects and 30 hours of compute within 60 days on CPU machines, so this template opens on a CPU machine. Attaching a GPU needs a paid plan.
Get this template