Fine-tune a model

Requires GPU / real compute

Adapt a small language model to your own data on a GPU.

The notebook

A read-only preview. Nothing here runs.

  1. # 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.

  2. import torch
    
    print(torch.cuda.is_available(), torch.cuda.get_device_name(0) if torch.cuda.is_available() else "no GPU")
  3. 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