gemma

GitHub

Gemma open-weight LLM library, from Google DeepMind

5,433 stars Python
RAW Doc

Index

``{eval-rst}

.. toctree::
:hidden:
:caption: Guides

colab_sampling
colab_multimodal
colab_finetuning
colab_tool_use
colab_sharding
colab_tokenizer
colab_lora_sampling
colab_lora_finetuning
peft
checkpoints
research

.. toctree::
:hidden:
:caption: Links

GitHub <https://github.com/google-deepmind/gemma>
Issues <https://github.com/google-deepmind/gemma/issues>
Ecosystem <https://ai.google.dev/gemma>

.. toctree::
:hidden:
:caption: API

api/gm/index
api/peft/index

text
{include} ../README.md
text
---

Checkpoints

Checkpoints

Kaggle Hub

Gemma models are available on Kaggle Hub for various formats:

* Gemma 4
* Gemma 3
* Gemma 2
* Gemma 1

To manually download the model:

* Select one of the Flax model variations
* Click the "Download" button to download the model archive
* Extract the model files from the archive

The archive contains both the model weights and the tokenizer, like:


2b/ # Directory containing model weights
tokenizer.model # Tokenizer
text
To programmatically download the model:
python
import kagglehub

kagglehub.login()

weights_dir = kagglehub.model_download(f'google/gemma-3/flax/gemma3-4b-it')

text

v4

NOTE: Gemma 4 Flax checkpoints will be updated on Kaggle when possible.

<section class="zippy" markdown="1">

v3

| Size | Variant | Quantized | Name |
| ---- | ----------- | --------- | ---------------------------------------- |
| 1B | Pre-trained | |
google/gemma-3/flax/gemma3-1b |
: : (PT) : : :
| 4B | Pre-trained | |
google/gemma-3/flax/gemma3-4b |
: : (PT) : : :
| 12B | Pre-trained | |
google/gemma-3/flax/gemma3-12b |
: : (PT) : : :
| 27B | Pre-trained | |
google/gemma-3/flax/gemma3-27b |
: : (PT) : : :
| 1B | Instruction | |
google/gemma-3/flax/gemma3-1b-it |
: : Tuned (IT) : : :
| 4B | Instruction | |
google/gemma-3/flax/gemma3-4b-it |
: : Tuned (IT) : : :
| 12B | Instruction | |
google/gemma-3/flax/gemma3-12b-it |
: : Tuned (IT) : : :
| 27B | Instruction | |
google/gemma-3/flax/gemma3-27b-it |
: : Tuned (IT) : : :
| 1B | Instruction | Y |
google/gemma-3/flax/gemma3-1b-it-int4 |
: : Tuned (IT) : : :
| 4B | Instruction | Y |
google/gemma-3/flax/gemma3-4b-it-int4 |
: : Tuned (IT) : : :
| 12B | Instruction | Y |
google/gemma-3/flax/gemma3-12b-it-int4 |
: : Tuned (IT) : : :
| 27B | Instruction | Y |
google/gemma-3/flax/gemma3-27b-it-int4 |
: : Tuned (IT) : : :

</section>

<section class="zippy" markdown="1">

v2

Size | Variant | Name
---- | ---------------------- | -----------------------------------
2.6B | Pre-trained (PT) |
google/gemma-2/flax/gemma2-2b
9B | Pre-trained (PT) |
google/gemma-2/flax/gemma2-9b
27B | Pre-trained (PT) |
google/gemma-2/flax/gemma2-27b
2.6B | Instruction Tuned (IT) |
google/gemma-2/flax/gemma2-2b-it
9B | Instruction Tuned (IT) |
google/gemma-2/flax/gemma2-9b-it
27B | Instruction Tuned (IT) |
google/gemma-2/flax/gemma2-27b-it

</section>

---

Research

Research

Custom transformer

For experimentation, you might want to create smaller custom versions of
Transformer, rather than using the default official "Gemma" pre-trained ones.

Here is an example to create a text-only, 12 layers transformer:

python
class MyTinyTransformer(gm.nn.Transformer):
config: gm.nn.config.TransformerConfig = gm.nn.config.TransformerConfig(
final_logit_softcap=None,
num_embed=262144, # Vocab size, matching the tokenizer
embed_dim=896,
hidden_dim=4 * 896,
num_heads=4,
head_dim=256,
num_kv_heads=1,
use_post_attn_norm=True,
use_post_ffw_norm=True,
use_qk_norm=True,
attention_types=gm.nn.config.make_attention_layers_types(
pattern=gm.nn.config.GEMMA3_ATTENTION_PATTERN,
num_layers=12,
),
query_pre_attn_norm=gm.nn.config.QueryPreAttentionNormalisation.BY_ONE_OVER_SQRT_HEAD_DIM,
attn_logits_soft_cap=None,
sliding_window_size=512,
transpose_gating_einsum=True,
local_base_frequency=10_000,
global_base_frequency=1_000_000,
vision_encoder=None, # Text-only
)

INFO = gm.nn.config.ModelInfo(
tokenizer_version=3, # Auto-select the tokenizer in the sampler
)

text

The Gemma repository also contain various non-official research projects around
Gemma, located in the research/
directory:

* t5gemma:
Encoder/decoder Gemma architecture, based on Gemma 2.

---

CHANGELOG

Changelog

[Unreleased]

[4.1.0] - 2026-06-11

- Release Diffusion Gemma

[4.0.1] - 2026-05-20

- Fix dialog dependency requirement to be >= 1.1.0.

[4.0.0] - 2026-04-17

* Add Gemma 4.

[1.0.0] - 2022-01-01

* Initial release

[Unreleased]: https://github.com/google-deepmind/gemma/compare/v4.1.0...HEAD
[4.1.0]: https://github.com/google-deepmind/gemma/compare/v4.0.1...v4.1.0
[4.0.1]: https://github.com/google-deepmind/gemma/compare/v4.0.0...v4.0.1
[4.0.0]: https://github.com/google-deepmind/gemma/compare/v0.1.0...v4.0.0
[1.0.0]: https://github.com/google-deepmind/gemma/releases/tag/v0.1.0

---

CONTRIBUTING

How to Contribute

We would love to accept your patches and contributions to this project.

Before you begin

Sign our Contributor License Agreement

Contributions to this project must be accompanied by a
Contributor License Agreement (CLA).
You (or your employer) retain the copyright to your contribution; this simply
gives us permission to use and redistribute your contributions as part of the
project.

If you or your current employer have already signed the Google CLA (even if it
was for a different project), you probably don't need to do it again.

Visit <https://cla.developers.google.com/> to see your current agreements or to
sign a new one.

Review our Community Guidelines

This project follows Google's Open Source Community
Guidelines
.

Contribution process

Code Reviews

All submissions, including submissions by project members, require review. We
use GitHub pull requests
for this purpose.

---

README

Gemma

[](https://github.com/google-deepmind/gemma/actions/workflows/pytest_and_autopublish.yml)
[](https://badge.fury.io/py/gemma)
[](https://gemma-llm.readthedocs.io/en/latest/?badge=latest)

Gemma is a family of open-weights Large Language
Model (LLM) by Google DeepMind, based on Gemini
research and technology.

This repository contains the implementation of the
gemma PyPI package. A
JAX library to use and fine-tune Gemma.

For examples and use cases, see our
documentation. Please
report issues and feedback in
our GitHub.

Installation

1. Install JAX for CPU, GPU or TPU. Follow the instructions on
the JAX website.
1. Run

sh
pip install gemma
text

Examples

Here is a minimal example to have a multi-turn, multi-modal conversation with
Gemma:

python
from gemma import gm

Model and parameters (Gemma 4)


model = gm.nn.Gemma4_E4B()
params = gm.ckpts.load_params(gm.ckpts.CheckpointPath.GEMMA4_E4B_IT)

Example of multi-turn conversation


sampler = gm.text.ChatSampler(
model=model,
params=params,
multi_turn=True,
)

prompt = """Which of the 2 images do you prefer ?

Image 1: <|image|>
Image 2: <|image|>

Write your answer as a poem."""
out0 = sampler.chat(prompt, images=[image1, image2])

out1 = sampler.chat('What about the other image ?')
`

The same ChatSampler` API works with all Gemma versions (2, 3, 3n, 4).

Our documentation contains various Colabs and tutorials, including:

* Sampling
* Multi-modal
* Fine-tuning
* LoRA
* ...

Additionally, our
examples/ folder
contain additional scripts to fine-tune and sample with Gemma.

Learn more about Gemma

* To use this library: Gemma documentation
* Technical reports for metrics and model capabilities:
* Gemma 1
* Gemma 2
* Gemma 3
* Gemma 4
* Other Gemma implementations and doc on the
Gemma ecosystem

Downloading the models

To download the model weights. See
our documentation.

System Requirements

Gemma can run on a CPU, GPU and TPU. For GPU, we recommend 8GB+ RAM on GPU for
The 2B checkpoint and 24GB+ RAM on GPU are used for the 7B checkpoint.

Contributing

We welcome contributions! Please read our Contributing Guidelines before submitting a pull request.

This is not an official Google product.

---