keepcalculator

06 Numbers and Powers

Gemma 3: Google’s Lightweight Open-Source AI

Card No. 06·48047 · Updated · Standard formula, shown below

Approx. VRAM needed (GB) 8.0 GB
Approx. FLOPs per token (GFLOPs)
8.0 GFLOPs
Result
Context length (tokens)
8192 tokens
You entered
Model size (billions of params)
4 B
You entered
You enter
Context length (tokens), Model size (billions of params)
You get
Approx. VRAM needed (GB), Approx. FLOPs per token (GFLOPs)
Rounding
1 dp

Yes, Google introduced Gemma, a family of lightweight, open-source AI models designed for developers and researchers who need capable AI that runs efficiently on limited hardware. You can download the model weights, fine-tune them for your own tasks, and deploy them on a laptop, workstation, or cloud VM without the massive infrastructure required by frontier models like Gemini. This article explains what Gemma is, how it differs from other open models, and how to start using it today.

Formula

The calculator estimates the minimum GPU memory (VRAM) required to run a Gemma model in inference mode (not training). The formula is:

VRAM (GB) ≈ Model size (billions of parameters) × 2

This assumes 16-bit (FP16/BF16) precision, which is the standard for inference. Each parameter is stored as a 2-byte number, so a 4-billion-parameter model needs about 8 GB of VRAM. The FLOPs estimate is even rougher: it assumes roughly 2 GFLOPs per token per billion parameters, which is a common rule of thumb for transformer inference.

Worked Example

Using the default values: a 4B model with 8192 tokens context.

  • Model size: 4 billion parameters
  • VRAM ≈ 4 × 2 = 8 GB
  • FLOPs per token ≈ 4 × 2 = 8 GFLOPs

So a 4B Gemma model fits comfortably in a GPU with 8 GB VRAM, like an NVIDIA RTX 3060 or a cloud instance with a T4. For a 9B model, you’d need about 18 GB, which pushes you toward a 24 GB GPU or CPU offloading.

Background: What Is Gemma?

Gemma is a family of open-weight AI models released by Google in February 2024, built from the same research and technology that powers Gemini. The name comes from the Latin gemma, meaning “precious stone.” Unlike Gemini, which is a closed API service, Gemma models are distributed as downloadable weights under a permissive license (the Gemma Terms of Use). The initial release included 2B and 7B parameter models; in 2025, Google expanded the family with Gemma 3, adding 1B, 4B, and 12B sizes, plus a 27B version.

These models are designed to be lightweight: they can run on a single GPU, a laptop, or even a Raspberry Pi (for the 1B model). This makes them attractive for prototyping, edge deployment, and research where sending data to a cloud API is impractical or undesirable.

How Gemma Works

Gemma models are transformer-based, similar to other large language models (LLMs). They are pre-trained on a large corpus of text (including web documents, code, and mathematical content) and then fine-tuned for instruction following and safety. The architecture includes:

  • Multi-head attention to process relationships between tokens.
  • Rotary position embeddings to understand token order.
  • GeGLU activations for improved non-linearity.
  • Normalization (RMSNorm) for stable training.

Inference works by taking a prompt, tokenizing it into subword units, and then predicting the next token iteratively until an end-of-sequence token is produced. The process is autoregressive: each new token depends on all previous ones. This is why context length matters—longer context means more tokens to process, which increases memory and compute.

How to Choose a Model Size

Choosing between the 1B, 4B, 12B, or 27B versions depends on your hardware and task complexity. Here are the key factors:

  • Hardware: Check your GPU VRAM. Use the calculator above. For CPU-only, you can run 1B or 4B with quantization (e.g., 4-bit) but expect slower speeds.
  • Task: Simple classification or extraction works with 1B/4B. Complex reasoning, code generation, or creative writing benefits from 12B or 27B.
  • Latency: Smaller models generate tokens faster. A 1B model can produce ~50 tokens/sec on a modern CPU, while a 27B model might only manage 5 tokens/sec on a GPU.
  • Fine-tuning: If you plan to fine-tune, remember that training requires 3-4 times more VRAM than inference. A 4B model might need 24 GB for full fine-tuning, but LoRA (Low-Rank Adaptation) can reduce that to ~8 GB.

Common Problems and Misconceptions

One major misconception is that “open-source” means you can do anything. Gemma’s license is permissive but includes restrictions: you cannot use the models for certain high-risk applications (like weapons or surveillance) and you must include attribution. Also, the training data is not fully disclosed, so there may be biases or inaccuracies.

Another common issue is out-of-memory errors. If you try to load a 12B model on an 8 GB GPU, you’ll get an OOM. Solutions:

  • Use quantization (e.g., 4-bit) via libraries like Hugging Face Transformers with load_in_4bit=True.
  • Offload layers to CPU (slow but works).
  • Use a smaller model.

Also, people often expect Gemma to match Gemini’s capabilities. It won’t—Gemma is a fraction of the size and lacks the massive training compute. It’s a tool for specific tasks, not a replacement for a frontier model.

Comparison with Other Open Models

Gemma competes with other open-weight models like Meta’s Llama 3, Mistral’s Mixtral, and Microsoft’s Phi-3. Here’s a quick comparison:

  • Llama 3: Sizes 8B and 70B. The 8B is similar to Gemma 9B in performance but requires more VRAM (16 GB). Llama 3 has a more permissive license (custom) and a larger community.
  • Mistral 7B: Often outperforms Gemma 7B on some benchmarks, but Gemma 3 12B is competitive. Mistral has a separate commercial license.
  • Phi-3: Microsoft’s 3.8B model is extremely efficient and runs on phones. Gemma 4B is comparable, but Phi-3 has a more restrictive license for commercial use.

In practice, the best model depends on your specific benchmark and hardware. Gemma’s advantage is its strong integration with Google’s ecosystem (e.g., Vertex AI, Colab) and its focus on safety.

Costs and Deployment

Gemma itself is free to download and use, but you’ll incur costs for hardware or cloud compute. For a hobbyist, running a 4B model on a local PC is essentially free (electricity aside). For production, you might use a cloud GPU:

  • An 8 GB GPU instance (e.g., NVIDIA T4) costs roughly $0.50/hour on major clouds.
  • A 24 GB GPU (e.g., A10) costs around $1.50/hour.
  • For CPU-only serving, you could use a standard VM for $0.10/hour, but latency will be high.

You can also use Google’s Vertex AI to deploy Gemma with a managed endpoint, but that comes with usage fees. For most developers, downloading the model and running it locally is the most cost-effective approach.

Safety and Limitations

Google has implemented safety measures in Gemma, including fine-tuning to refuse harmful requests and a safety classifier for inputs/outputs. However, as with any open model, these are not foolproof. The model can produce biased, inaccurate, or harmful content, especially if fine-tuned on malicious data. You are responsible for your deployment’s safety.

Limitations include:

  • Knowledge cutoff: Gemma 3 has a knowledge cutoff in 2024, so it doesn’t know recent events.
  • Context length: While 8192 tokens is standard, some models support 128K. Gemma 3 supports up to 128K with a special configuration, but that increases memory usage.
  • Multilinguality: Gemma is primarily English-centric, though it has some multilingual capability.

Frequently Asked Questions

Is Gemma truly open-source?

It’s open-weight, not fully open-source. The model weights are publicly downloadable, and you can use them under a permissive license. However, the training data and training code are not released, so you cannot reproduce the model from scratch. This is similar to Llama and Mistral.

How do I run Gemma on my computer?

You can use Hugging Face’s Transformers library. Install with pip install transformers, then load the model with AutoModelForCausalLM.from_pretrained("google/gemma-3-4b-it"). You’ll need Python 3.10+, PyTorch, and at least 8 GB RAM (or VRAM). For a simpler option, use Ollama or LM Studio for a chat interface.

Can I fine-tune Gemma for my own data?

Yes, you can fine-tune using libraries like Hugging Face’s PEFT (LoRA) or Axolotl. You’ll need a GPU with enough VRAM—for a 4B model, 8 GB is sufficient for LoRA, but full fine-tuning needs ~24 GB. Google also offers a fine-tuning API on Vertex AI.

What is the difference between Gemma and Gemini?

Gemini is Google’s proprietary, frontier AI model available only via API. Gemma is a lightweight, open-weight model you can run yourself. They share research, but Gemma is much smaller and less capable. Think of Gemini as a sports car and Gemma as a reliable bicycle—both get you places, but at different speeds and costs.

Does Gemma support non-English languages?

Yes, but with limitations. Gemma 3 was trained on data from over 140 languages, but its performance is best in English. For high-quality non-English output, you may need to fine-tune on your target language.

What are the hardware requirements for Gemma 3 4B?

For inference, you need about 8 GB of VRAM (or 8 GB RAM with quantization). A modern CPU with 16 GB RAM can run it, but expect 10-20 tokens per second. For fine-tuning, you’ll need at least 16 GB VRAM (with LoRA) or 24 GB for full fine-tuning.

Related

Formula used
in t | Context length (tokens) | tokens | 8192 | 1 | 1000000
in m | Model size (billions of params) | B | 4 | 1 | 100
out mem | Approx. VRAM needed (GB) | GB | m * 2 | 1
out flops | Approx. FLOPs per token (GFLOPs) | GFLOPs | m * 2 | 1

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →