Building with AI

Gemma 4 fine-tuning guide: memory needs and training stages

Google’s documentation outlines four training stages for Gemma 4, details GPU memory requirements for QLoRA and full fine-tuning, and advises when to use RAG instead of weight updates.

Glass cubes representing model layers next to a memory usage gauge
Illustration generated for this article

Google has released official documentation detailing how to adapt its Gemma 4 large language models for specific tasks. Published in late November 2026, the guide breaks down the computational costs, training stages, and strategic choices developers face when customizing these models. It serves as a practical manual for engineers looking to move beyond basic inference into specialized model tuning.

What happened

The documentation clarifies that large language models are not static entities but are built through distinct phases of learning. It outlines a four-stage process that begins with pre-training on vast amounts of web text, code, and media, where the model learns to predict the next token. This is followed by continued pre-training on domain-specific raw text, such as medical literature or internal codebases, to absorb specialized terminology. The third stage involves supervised fine-tuning using example conversations, while the final stage uses reinforcement learning to refine outputs based on scored preferences or verifiable rewards.

Most teams do not need to execute all four stages. The guide suggests that starting from an instruction-tuned checkpoint, identified by the -it suffix, is the standard approach for most applications. These checkpoints already understand how to follow instructions and recognize conversation turns. Developers typically layer supervised fine-tuning or reinforcement learning on top of these bases rather than teaching instruction-following behavior from scratch. Pre-trained checkpoints without the suffix are reserved for deep domain shifts or custom chat template creation, which require significant compute resources.

How it works

Before updating any model weights, engineers must decide between Retrieval-Augmented Generation (RAG), Low-Rank Adaptation (LoRA), or full fine-tuning. RAG leaves the model untouched and injects relevant documents into the prompt, making it ideal for facts that change frequently, such as live inventory. LoRA freezes the base model and trains small adapter matrices, updating only about 1% to 2% of parameters. QLoRA extends this by storing base weights in 4-bit precision to save memory. Full fine-tuning updates every weight in the model, which is necessary for deep structural changes but demands substantial hardware.

Memory consumption is a critical constraint during training. For every parameter being trained, the GPU must store the weight itself, its gradient, and optimizer states. In bfloat16 precision, weights and gradients each take 2 bytes per parameter. Optimizer states vary from 2 bytes with an 8-bit optimizer to 8 bytes in 32-bit precision. Activations, which are intermediate values from the forward pass, also consume significant memory. Consequently, training requires far more VRAM than inference. For example, full fine-tuning the 12B parameter model requires approximately 80 GB of VRAM, whereas QLoRA reduces this to roughly 11 GB.

Key details

  • Gemma 4 models are available in five sizes: E2B, E4B, 12B, 26B A4B, and 31B parameters.
  • QLoRA training for the 31B model requires approximately 22 GB of VRAM, while full fine-tuning needs around 200 GB.
  • Instruction-tuned checkpoints (-it) should be used for supervised fine-tuning, tool use, and vision or audio tuning.
  • Pre-trained checkpoints are recommended only for continued pre-training on new languages or large domain corpora.
  • Supported training frameworks include TRL, Unsloth, Axolotl, Vertex AI, and Google Cloud GKE.
  • RAG is preferred for dynamic data like user records, while fine-tuning is better for learning new skills or formats.

Why it matters

For software teams building AI products, understanding the distinction between RAG and fine-tuning prevents wasted engineering effort. Many organizations attempt to fine-tune models to remember factual data that changes daily, which is inefficient and error-prone. By reserving weight updates for learning stable skills, personas, or output formats, and using RAG for dynamic facts, developers can create more maintainable and accurate systems. This separation of concerns also reduces the computational burden, allowing smaller teams to operate effectively with limited GPU resources.

The detailed memory breakdowns provided in the documentation allow technical leads to make informed hardware purchasing or cloud provisioning decisions. Knowing that QLoRA can fit the 31B model into 22 GB of VRAM enables the use of consumer-grade or single-cloud-instance GPUs for experimentation. Conversely, knowing that full fine-tuning the same model requires 200 GB highlights the need for multi-GPU clusters or managed services like Vertex AI. This transparency helps avoid costly infrastructure mistakes early in the development cycle.

What you can do

  • Evaluate your data type: use RAG for frequently changing facts and fine-tuning for stable skills or formats.
  • Start with instruction-tuned (-it) checkpoints for most supervised fine-tuning and reinforcement learning tasks.
  • Calculate your VRAM requirements using the provided table before selecting a model size or training method.
  • Use QLoRA to reduce memory usage if you are limited to single-GPU environments or smaller cloud instances.
  • Select a supported framework like TRL or Unsloth to streamline the setup of your training pipeline.
  • Combine LoRA for domain adaptation with RAG for recent information to leverage the strengths of both approaches.
  • #gemma 4
  • #fine-tuning
  • #llm ops
  • #gpu memory
  • #machine learning

Tools from the Bytechap store

$89

DocBento

Self-hosted document management that reads every scan and answers with page citations.

Live demo

Keep reading

All stories