Google ships the gemma-trainer skill: let AI fine-tune your own Gemma on your own machine

An open-source training playbook that locks down supervised fine-tuning, preference alignment, and reward scoring — plus LoRA parameters — paired with Unsloth, so a consumer GPU with 8GB of VRAM is enough to get started.
By DEV · Google AI07-18 · 8 min read⚑ Tutorial / how-to
🎧 Listen to the podcast0:00 / --:--
0:00 / --:--
Tool Tutorial · Xiaohu Explains
60-second briefing
  • Google added a skill called gemma-trainer to its open-source gemma-skills repo, built to teach AI assistants how to fine-tune Gemma models locally on your own machine.
  • It's essentially a playbook written for AI agents to read (SKILL.md), plus 5 ready-made Python scripts. You describe what you want in plain language, and the assistant picks parameters and runs the training.
  • It covers three training paths: SFT for teaching new knowledge, DPO for tuning style preferences, and RM for training a scoring model — each with its data format and key parameters locked in.
  • It defaults to Unsloth, which Unsloth claims cuts VRAM use by up to 70% and runs 2x faster — enough for a single consumer GPU to fine-tune 12B models or larger, including image and audio training.
  • Once trained, models can be converted to lightweight formats like GGUF and run on phones and IoT devices via LiteRT-LM.
⚑This is Google's own introduction of its tool, published on the DEV community. The performance figures (70% VRAM savings, 2x speed) are Unsloth's own claims. The mechanism details below come from the code in the open-source repo google-gemma/gemma-skills.
What you can do

Fine-tune a Gemma that only speaks your niche, on your own machine

You want a model of your own — one that knows the jargon of your obscure field, matches your tone, and only handles your specific job. Open Gemma was built for exactly this kind of customization, but actually fine-tuning it has always meant wading through a maze of environment setup and unreadable guides first.

Google's Gemma team recently smoothed out that first step: a new skill called gemma-trainer, added to the open-source gemma-skills repo.

With it, you can tell your AI assistant something like "fine-tune Gemma 4 E2B on this dataset," and it knows to validate your data first, pick the right LoRA parameters, kick off training with resource-friendly defaults, and evaluate the results. The whole local fine-tuning workflow becomes a playbook the assistant can read and execute directly.
💡Why it matters: it locks the whole decision tree for local Gemma fine-tuning — which training method to use, how to configure LoRA parameters, how to avoid blowing out your VRAM, how to convert the result for on-device deployment — into a single skill file. Paired with Unsloth, a consumer GPU with 8GB of VRAM is enough to get started, and it covers text, image, and audio training all at once.
📦 Open-source repo · Free
github.com/google-gemma/gemma-skills
What it actually is

It's essentially a playbook written for AI

gemma-trainer's core is a SKILL.md file plus 5 ready-made Python script templates. It's not an app, and it's not a training library you're meant to call directly yourself.

SKILL.md is a blueprint written specifically for AI agents to read. It locks down the best practices for local fine-tuning — what value each parameter should take, which pitfalls to avoid — all in one place. Once your assistant has read it, it goes from "roughly knowing how fine-tuning works" to "knowing exactly which script to adjust on this machine, and which knob to turn to what setting." The 5 scripts in the repo each handle one job: one runs supervised fine-tuning, one runs preference alignment, one trains a scoring model, one validates data formatting, and one handles data distillation.

You describe it"Fine-tune Gemma 4 E2B"
→
Agent reads
gemma-trainer
→
Picks the right script
sets parameters
→
Runs training
→
Evaluates
and iterates

The skill isn't tied to any particular AI tool — it works with anything from Gemini to Claude, and also works with Google's own Antigravity CLI tool (agy). Setup is a one-liner: copy the gemma-trainer folder into your AI assistant's skills directory, and it immediately knows how to guide you.

What's more interesting is that the assistant doesn't just blindly execute — it also catches your mistakes based on the capability constraints written into the skill. One real example: a training request accidentally specified Gemma 4 31B for an audio task, and the assistant flagged it on the spot, pointing out that 31B only handles text and images and has no audio capability, suggesting E2B or 12B instead.

Agent flags that Gemma 4 31B has no audio capability and suggests switching to E2B or 12B
If you ask for audio fine-tuning on a model with no audio capability, the assistant will catch it and offer viable alternatives. Source: DEV / Google AI
Three training paths

Teach knowledge, tune preference, or train a scorer — how to choose

The skill splits fine-tuning into three methods, each aimed at a different goal. Once you're clear on what you want the model to learn, the right path becomes obvious.

SFT
Supervised fine-tuning
What it doesTeaches new domain knowledge, specialized tasks, fixed output formats
Feed itQuestion-and-answer conversation data
ProducesAn adapter that attaches to the original model
DPO
Direct preference optimization
What it doesTunes style, tone, and safety boundaries to align with human preference
Feed itA prompt, paired with a better answer and a worse answer
PrerequisiteMust run SFT first, or it tends to break down
RM
Reward modeling
What it doesTrains a dedicated model to score how good an answer is
Feed itSame good/bad paired format as DPO
ProducesThe model plus a new head that outputs a score

DPO has one hard rule: you must complete SFT on your domain before doing DPO. Running DPO directly on a base model that's never seen your data will usually fail, or wreck the output format.

Learning rates differ by orders of magnitude across the three methods

Here's a detail that's easy to overlook but tells you a lot: the recommended learning rate (how far each step nudges the parameters) varies enormously across the three paths, and it's not simply "more teaching means bigger steps." DPO only lightly corrects style on top of what the model already knows — too big a step and it wrecks the formatting it already learned, so its learning rate has to be two hundred times smaller than SFT's. RM, by contrast, trains a brand-new scoring head from scratch, and ends up with the largest step size of the three.

RMtrains a scorer
1e-3
SFTteaches new knowledge
2e-4
DPOtunes preference
1e-6

Bars illustrate relative magnitude only, not a linear scale. Actual values: RM uses 1e-3, SFT uses 2e-4, DPO uses 1e-6 — DPO is two hundred times smaller than SFT.

Here's what the two data formats look like, straight from the skill's standard examples — you can model your own dataset on these.

SFT data format · one conversation, one question and one answer
{
  "messages": [
    {"role": "user", "content": "Tell me a joke."},
    {"role": "model", "content": "Why did the computer go to the doctor? It had a virus!"}
  ]
}
DPO data format · one prompt paired with a good answer and a bad answer
{
  "prompt": "Write a python function to compute factorial.",
  "chosen": "def factorial(n):\n    return 1 if n <= 1 else n * factorial(n - 1)",
  "rejected": "factorial is computed using recursion or loops. Just import math."
}

During training, it only learns "how to respond" — not your prompt

There's another subtlety buried in the scripts. What gets fed in is the full "user prompt plus model response" pair, but training doesn't learn from both halves equally. The script first locates where the model's response begins, and only computes loss on the response halfLoss is how the model gets penalized for wrong answers. Computing loss only on the response means the model learns "how to respond," without memorizing your prompt — the user's prompt is skipped entirely. That way the model learns "how to answer this kind of question," rather than memorizing your question itself.

User prompt
Model response
Why did the computer go to the doctor? It had a virus!
Skipped, not learnedOnly this half is learned
Top cause of failure

Bad data formatting is the number one reason fine-tuning underperforms. That's why the skill ships a dedicated validation script, dataset_prep.py, that checks your data before training starts: for SFT data, it verifies the last turn is the model's response; for DPO data, it checks that the "chosen" and "rejected" answers aren't identical — otherwise the model has no preference signal to learn from. It also tokenizes the prompt separately and confirms that prefix matches exactly across the "chosen" and "rejected" answers, specifically to catch the kind of tokenizer misalignment that quietly derails training.

No dataset on hand? Let a bigger model generate one for you

The thing fine-tuning is most often short on is data. The skill also includes a data distillation script, distill_dataset.py: the idea is to have a large "teacher" model (say, Gemma 4 31B) generate high-quality training data, then use that data to train a small "student" model (say, E2B). It offers two ways to generate data:

response mode
Fill in answers
You supply a batch of questions; the teacher model fills in high-quality answers for each, forming a Q&A dataset
synthesize mode
Generate its own prompts
Even less hands-on: the teacher model brainstorms a batch of instructions and matching answers itself, generating the whole dataset directly

The teacher model can run locally through Ollama, so the whole process — from data generation to training — never has to leave your machine.

How it fits your GPU

How to squeeze a large model onto your GPU

The biggest fear in local fine-tuning is running out of VRAM and having training crash outright (an out-of-memory error, or OOM). gemma-trainer relies on three things to fit large models onto consumer GPUs: LoRA, QLoRA, and a training engine called Unsloth.

An analogy

Fine-tuning a large model isn't like rewriting the whole book. LoRA leaves the original book untouched and clips a small stack of trainable sticky notes to the side — all your edits go on the notes. QLoRA goes further: it first reprints the original book in a more compact format (4-bit compression) to shrink its size, then clips on the sticky notes for training. The original model stays frozen; what you're actually training is that small stack of notes — which is exactly why VRAM use drops.

Frozen large model 🧊 Original params untouched 4-bit compressed to save VRAM LoRA adapter This small stack is what you actually train
The original model stays frozen and compressed; only the small stack of adapters attached alongside it gets trained, cutting VRAM needs dramatically

The division of labor works like this: on a single GPU, default to Unsloth, which has native support for Gemma 4 and, per its own claims, cuts VRAM use by up to 70% and runs 2x faster than standard Hugging Face training; only in multi-GPU setups, or when Unsloth can't be installed, does it fall back to Hugging Face's TRL plus PEFT. Either way, it recommends enabling QLoRA (4-bit quantization)Compresses model parameters from the usual 16-bit precision down to 4 bits — roughly a quarter of the size and VRAM footprint, at the cost of a small amount of precision, which is the key to fitting Gemma variants as large as 12B or 31B onto consumer-grade VRAM.

One more pitfall to watch for: Gemma 4 natively supports context windows up to 256K, but don't get greedy with that locally — the skill recommends capping it at 2048 to 8192, or you'll blow out your VRAM easily.

What kind of machine do you actually need

With QLoRA and Unsloth enabled, the bar is lower than most people assume. Per Unsloth's own figures, fine-tuning different Gemma 4 sizes can start on a single consumer GPU, and the smallest model can even run on free Google Colab:

ModelFine-tuning VRAM (QLoRA)What GPU is enough
Gemma 4 E2B~8 GBEntry-level consumer, e.g. RTX 3060 12G, or free Colab's T4
Gemma 4 E4B10–17 GBMid-range consumer GPU
Gemma 4 31B~22 GBHigh-end consumer, e.g. RTX 4090 / 3090 (24G)
Gemma 4 26B-A4B40 GB+Needs a professional card like an A100

VRAM figures come from Unsloth's official Gemma 4 training docs, as reference values for QLoRA/LoRA fine-tuning; full fine-tuning (uncompressed) needs several times more and usually requires multiple GPUs.

A LoRA parameter recipe you can just copy

The skill hardcodes default values for the common LoRA parameters, so you can just fill them in when you're ready to train:

ParameterRecommended valueWhat it controls
Rank (r)16 or 32How "thick" the sticky notes are. Higher lets it learn more complex behavior, but costs more VRAM
lora_alpha32 or 64A scaling factor; rule of thumb is to set it to 2x the rank
lora_dropout0.05Forces the model to learn more robust features instead of relying on fixed patterns
Learning rateSFT 2e-4
DPO 1e-6
RM 1e-3
How far each step moves. The three methods differ by orders of magnitude — don't mix them up
Context length2048–8192Prevents OOM locally — don't run the full 256K

Once the parameters are set, running it is a single command. If you want to skip the AI assistant and drive the scripts yourself, that works too — for instance, running a supervised fine-tune on E2B with default settings:

Run an SFT pass · calling the script directly
python sft_train.py \
  --model google/gemma-4-E2B \
  --dataset your_data.json \
  --lora-r 16 --lora-alpha 32 \
  --epochs 3 --lr 2e-4

DPO and reward modeling have their own dpo_train.py and reward_train.py scripts, with the same parameter style. When Unsloth can't be installed, adding --force-hf falls back automatically to Hugging Face.

Going deeper: how DPO saves an entire model's worth of VRAM

In theory, DPO training needs two copies of the model loaded at once: one being trained, and one as a "reference" (to check whether the new model has drifted). That doubles VRAM use. gemma-trainer's approach is to set the reference model to nothing at all — when a reference output is needed, it temporarily switches off the LoRA stack currently being trained, lets the model fall back to its original state to compute the output, then switches the stack back on. One model doing the job of two, at a substantial VRAM savings. When using Unsloth, it also applies an extra patch to speed up the DPO trainer.

See, hear, and fit in your pocket

Teaching it to see and hear, then fitting it in your pocket

Gemma 4 is natively multimodal — it can already handle images and audio. Training it to see or hear takes a smaller change than you'd expect: just swap the content block's type from text to image or audio in the data format.

Teaching it to hear · swap type from text to audio (same for image)
{
  "messages": [
    {"role": "user", "content": [
        {"type": "text", "text": "Describe this audio."},
        {"type": "audio", "url": "path/to/audio.wav"}
    ]},
    {"role": "assistant", "content": [
        {"type": "text", "text": "This is an audio file of a bird chirping."}
    ]}
  ]
}

Audio has a few quirks: it needs 16kHz mono sampling, and the scripts include a specific patch fixing an old bug where a mismatched audio data type caused training to error out, saving you from hitting it yourself. Which model sizes support image and audio fine-tuning is also spelled out clearly — audio only works on E2B, E4B, and 12B; 31B doesn't support it, which is exactly the reason the assistant flagged the earlier example.

After training, the model can travel all the way into your pocket. Using Unsloth's native export or llama.cpp, you can convert the model to a lightweight format like GGUF, then hand it off to LiteRT-LM to run on phones, the web, and IoT devices — with hardware acceleration on CPU, GPU, or NPU. "Fine-tune locally, deploy locally" becomes one continuous chain.

Related on this site
Google runs Gemma 4 on the Pixel 10: putting AI on-device in practice
Curious how a fine-tuned Gemma actually performs once it's on your phone? This piece covers exactly that part.
Hands-on · Getting started

Hands-on: turning Gemma into an old Korean literature translator

Here's a real working example: fine-tuning Gemma 4 E2B into a translation specialist for The Tale of Hong Gildong, a classic of old Korean literature. The entire process boils down to a single sentence to the assistant.

Running a real fine-tune · all you need to say is this
Fine-tune Gemma 4 E2B on the dataset bebechien/HongGildongJeon.

From there, the assistant walks you through four steps: first it uses the validation script to check your data against the required format, then it picks a set of LoRA parameters that can teach the model subtle linguistic nuance without blowing out VRAM, then it kicks off training with resource-friendly defaults, and finally it evaluates the results and tunes parameters for another round based on performance. You can even have it write a custom evaluation script on the spot — say, one that checks transcription similarity. Once training finishes, the assistant hands you a full report laying out how this round performed and what to change in the next one.

A comprehensive report after training finishes, pointing out where the next round could improve
Once training wraps up, the assistant produces a comprehensive report noting performance and what to improve in the next round. Source: DEV / Google AI

How do you get started? Copy the gemma-trainer folder into your AI assistant's skills directory, and it immediately knows how to guide you. The full gemma-skills repo is open source on GitHub: github.com/google-gemma/gemma-skills.

Related on this site
The Gemma 4 technical report: how an open model does more with fewer parameters
Want to know what the model being fine-tuned here is actually capable of first? This is our breakdown of the official technical report.
✅ Decision checklist for fine-tuning Gemma on your own machine
Data formats for all three training paths, a one-line trigger prompt, a LoRA parameter cheat sheet, and a local fine-tuning decision checklist — copy it all and get started.
Source: bebechien, "Master Local Fine-Tuning with 'gemma-trainer'," DEV Community, 2026-07-07. Mechanism details from the SKILL.md and training scripts in the open-source repo google-gemma/gemma-skills. Performance figures are Unsloth's own claims.
Source
DEV · Google AIDEV · Google AI·Read the source
↑ End of article
✓ This article is free to read in full

Members can copy or download the full Markdown, and let their AI subscribe and ask.

Read the original ↗
📮 New explainers, straight to your inbox

Found this useful? Leave your email — every new explainer, the moment it's out. Unsubscribe anytime.