DEV Community

albe_sf
albe_sf

Posted on

Gemma 2 is here. It's time to pay attention to open models.

Google has released Gemma 2, the next generation of its open models, and it's a release that warrants a closer look from builders. The key takeaway is this: the 27B parameter model delivers performance competitive with models more than twice its size, while running on a single GPU. This isn't just an incremental update; it's a shift in the cost-to-performance ratio for high-quality open models.

what's new under the hood

Gemma 2 comes in 9 billion and 27 billion parameter sizes, with a smaller 2B version also available. The architecture introduces some notable changes from the first generation. It now uses a combination of local and global attention, allowing it to focus on both immediate context and the broader meaning of a text. It also implements Grouped Query Attention (GQA) to improve inference speed and parameter efficiency.

The training data for the 27B model consisted of 13 trillion tokens, while the 9B model was trained on 8 trillion tokens, sourced from a diverse mix of web documents and code. For the smaller 2B and 9B models, Google used knowledge distillation from the larger 27B model, which they report leads to significant performance gains compared to training from scratch with the same token count.

performance and efficiency claims

The headline claim is that the 27B model provides a competitive alternative to much larger, closed-source models. Google states that the 9B model also delivers class-leading performance, outperforming other open models in its size category like Llama 3 8B.

Crucially, the 27B model is designed for efficient inference on a single NVIDIA H100 or even an A100 80GB GPU. This significantly lowers the barrier to entry for deploying a high-performance model, moving it out of the realm of large-scale clusters and onto a single machine. This focus on efficiency makes self-hosting and running local inference for product development much more feasible.

how to get started

Getting up and running with Gemma 2 is straightforward. The model weights are available on Hugging Face, Kaggle, and through Google AI Studio. For local development, tools like Ollama provide a simple way to pull and run the models with a single command.

Here's a basic example of how you might run the 9B instruction-tuned model locally after installing Ollama:

# Pull the Gemma 2 9B model
ollama run gemma2:9b

# After pulling, you can interact with it directly
# or use it via the Ollama API
Enter fullscreen mode Exit fullscreen mode

For more integrated use cases, you can use libraries like transformers from Hugging Face. Here's a Python snippet to load the model and tokenizer, using 4-bit quantization to manage memory usage on consumer hardware.

from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
import torch

model_id = "google/gemma-2-9b-it"

# Configure 4-bit quantization
quantization_config = BitsAndBytesConfig(
    load_in_4bit=True,
    bnb_4bit_quant_type="nf4",
    bnb_4bit_compute_dtype=torch.bfloat16
)

tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    quantization_config=quantization_config,
    device_map="auto"
)

input_text = "Explain the key architectural changes in Gemma 2."
input_ids = tokenizer(input_text, return_tensors="pt").to(model.device)

outputs = model.generate(**input_ids, max_new_tokens=150)
print(tokenizer.decode(outputs[0]))

Enter fullscreen mode Exit fullscreen mode

This approach makes it possible to run a powerful model on a developer's laptop or a single cloud GPU, which is a game-changer for rapid prototyping and building privacy-sensitive applications.

the so-what for builders

The release of Gemma 2 is another sign that the performance gap between state-of-the-art proprietary models and open models is closing, especially when you factor in efficiency. For builders, this means more freedom. You can fine-tune and deploy a capable model without being locked into a specific API provider or facing unpredictable usage bills.

The ability to run a 27B parameter model that competes with 50B+ models on a single GPU is the real story here. It changes the economics of building AI features and products. It makes local, private, and cost-effective AI applications a more realistic goal for a wider range of developers and organizations. This is a good week to re-evaluate your stack and see where an open model might fit.

Sources

https://blog.google/

Top comments (0)