Model reference · open weights
gemma-2 is an open-weight language model from Efficient-Large-Model. gemma-2-2b-it (BF16) weighs 10.5 GB; the smallest configuration that runs it is RTX 4060 Ti 16 GB.
Summary of the Efficient-Large-Model/gemma-2-2b-it model card, 2026-10-01
What it is
| Released by | Efficient-Large-Model |
|---|---|
| Released | 2024-12-12 |
| Parameters | 2.6B |
| VRAM | 10.5 GB for the weights |
What it runs on
| Card | Requests at once | Context max | Memory |
|---|---|---|---|
| 8K each | |||
| RTX 3060 12 GB | — | — | 11.6 GB |
| RTX 4060 Ti 16 GB | 4 | all 8K | 15.4 GB |
| RTX 3090 24 GB | 13 | all 8K | 23.4 GB |
| RTX 4090 24 GB | 13 | all 8K | 23.4 GB |
| RTX 5090 32 GB | 22 | all 8K | 31.0 GB |
| L40S 48 GB | 37 | all 8K | 44.0 GB |
| A100 80 GB | 76 | all 8K | 78.2 GB |
| H100 80 GB | 70 | all 8K | 78.1 GB |
| RTX PRO 6000 Blackwell 96 GB | 88 | all 8K | 93.8 GB |
| DGX Spark (GB10) 128 GB unified | 104 | all 8K | 107 GB |
| H200 141 GB | 139 | all 8K | 138 GB |
| B200 180 GB | 182 | all 8K | 176 GB |
| 2× RTX 3060 12 GB tensor parallel | 12 | all 8K | 11.6 GB a card |
| 2× RTX 4060 Ti 16 GB tensor parallel | 21 | all 8K | 15.4 GB a card |
| Requests at once | 8K tokens each |
|---|---|
| 1 | 12.1 GB |
| 5 | 15.6 GB |
| 8 | 18.2 GB |
| 16 | 25.2 GB |
| 32 | 39.2 GB |
| 64 | 67.1 GB |
One card, with vLLM's small-card settings.
From the model card
Model Page: Gemma
Resources and Technical Documentation:
Terms of Use: [Terms][terms]
Authors: Google
Summary description and brief definition of inputs and outputs.
Gemma is a family of lightweight, state-of-the-art open models from Google, built from the same research and technology used to create the Gemini models. They are text-to-text, decoder-only large language models, available in English, with open weights for both pre-trained variants and instruction-tuned variants. Gemma models are well-suited for a variety of text generation tasks, including question answering, summarization, and reasoning. Their relatively small size makes it possible to deploy them in environments with limited resources such as a laptop, desktop or your own cloud infrastructure, democratizing access to state of the art AI models and helping foster innovation for everyone.
Below we share some code snippets on how to get quickly started with running the model. First, install the Transformers library with:
pip install -U transformers
Then, copy the snippet from the section that is relevant for your usecase.
pipeline APIimport torch
from transformers import pipeline
pipe = pipeline(
"text-generation",
model="google/gemma-2-2b-it",
model_kwargs={"torch_dtype": torch.bfloat16},
device="cuda", # replace with "mps" to run on a Mac device
)
messages = [
{"role": "user", "content": "Who are you? Please, answer in pirate-speak."},
]
outputs = pipe(messages, max_new_tokens=256)
assistant_response = outputs[0]["generated_text"][-1]["content"].strip()
print(assistant_response)
# Ahoy, matey! I be Gemma, a digital scallywag, a language-slingin' parrot of the digital seas. I be here to help ye with yer wordy woes, answer yer questions, and spin ye yarns of the digital world. So, what be yer pleasure, eh? 🦜
# pip install accelerate
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-2b-it")
model = AutoModelForCausalLM.from_pretrained(
"google/gemma-2-2b-it",
device_map="auto",
torch_dtype=torch.bfloat16,
)
input_text = "Write me a poem about Machine Learning."
input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
outputs = model.generate(**input_ids, max_new_tokens=32)
print(tokenizer.decode(outputs[0]))
You can ensure the correct chat template is applied by using tokenizer.apply_chat_template as follows:
messages = [
{"role": "user", "content": "Write me a poem about Machine Learning."},
]
input_ids = tokenizer.apply_chat_template(messages, return_tensors="pt", return_dict=True).to("cuda")
outputs = model.generate(**input_ids, max_new_tokens=256)
print(tokenizer.decode(outputs[0]))
The native weights of this model were exported in bfloat16 precision.
You can also use float32 if you skip the dtype, but no precision increase will occur (model weights will just be upcasted to float32). See examples below.
torch.float32# pip install accelerate
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-2b-it")
model = AutoModelForCausalLM.from_pretrained(
"google/gemma-2-2b-it",
device_map="auto",
)
input_text = "Write me a poem about Machine Learning."
input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
outputs = model.generate(**input_ids, max_new_tokens=32)
print(tokenizer.decode(outputs[0]))
The local-gemma repository contains a lightweight wrapper around Transformers for running Gemma 2 through a command line interface, or CLI. Follow the installation instructions for getting started, then launch the CLI through the following command:
local-gemma --model 2b --preset speed
bitsandbytesUsing 8-bit precision (int8)
# pip install bitsandbytes accelerate
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
quantization_config = BitsAndBytesConfig(load_in_8bit=True)
tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-2b-it")
model = AutoModelForCausalLM.from_pretrained(
"google/gemma-2-2b-it",
quantization_config=quantization_config,
)
input_text = "Write me a poem about Machine Learning."
input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
outputs = model.generate(**input_ids, max_new_tokens=32)
print(tokenizer.decode(outputs[0]))
Using 4-bit precision
# pip install bitsandbytes accelerate
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
quantization_config = BitsAndBytesConfig(load_in_4bit=True)
tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-2b-it")
model = AutoModelForCausalLM.from_pretrained(
"google/gemma-2-2b-it",
quantization_config=quantization_config,
)
input_text = "Write me a poem about Machine Learning."
input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
outputs = model.generate(**input_ids, max_new_tokens=32)
print(tokenizer.decode(outputs[0]))
Torch compile
Torch compile is a method for speeding-up the inference of PyTorch modules. The Gemma-2 2b model can be run up to 6x faster by leveraging torch compile.
Note that two warm-up steps are required before the full in
Quoted from the model card on Hugging Face. The full card is behind the Hugging Face link above.