Text Generation
Keras
PyTorch
JAX
TensorFlow
English
zeromodels
gemma2
gemma
gemma-2-2b
arxiv:2408.00118
Instructions to use zeromodels/gemma-2-2b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use zeromodels/gemma-2-2b with Keras:
# Available backend options are: "jax", "torch", "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" import keras model = keras.saving.load_model("hf://zeromodels/gemma-2-2b") - Notebooks
- Google Colab
- Kaggle
File size: 3,073 Bytes
fee156e 28ce893 fee156e 28ce893 fee156e 28ce893 fee156e 28ce893 fee156e 28ce893 fee156e 28ce893 fee156e 28ce893 fee156e 28ce893 fee156e 28ce893 fee156e 28ce893 fee156e 28ce893 fee156e 28ce893 fee156e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | ---
pipeline_tag: text-generation
license: gemma
base_model: google/gemma-2-2b
library_name: zeromodels
extra_gated_heading: Access Gemma on Hugging Face
language:
- en
tags:
- keras
- zeromodels
- gemma2
- gemma
- gemma-2-2b
- text-generation
- arxiv:2408.00118
- pytorch
- jax
- tf
---
*See [our collection](https://huggingface.co/zeromodels) for all Gemma 2 sizes and variants.*
# Run Gemma 2 with Keras 3: JAX, PyTorch, or TensorFlow
[](https://github.com/IMvision12/ZeroModels) [](https://imvision12.github.io/ZeroModels/gemma2/) [](https://huggingface.co/zeromodels)
# zeromodels/gemma-2-2b
Pure-**Keras 3** conversion of [`google/gemma-2-2b`](https://huggingface.co/google/gemma-2-2b) for
[zeromodels](https://github.com/IMvision12/ZeroModels). One implementation runs unmodified on
**TensorFlow / Torch / JAX**. This is a base (pretrained) checkpoint, served here as **text -> text** via `Gemma2TextGenerate`; weights are
stored in **bfloat16**.
For model details, license, and usage terms, see Google's
[model card](https://huggingface.co/google/gemma-2-2b).
## ✨ Quick start
```python
import os
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
from zeromodels.models.gemma2 import Gemma2TextGenerate, Gemma2Tokenizer
model = Gemma2TextGenerate.from_weights("zeromodels/gemma-2-2b")
tokenizer = Gemma2Tokenizer.from_weights("zeromodels/gemma-2-2b")
inputs = tokenizer([{"role": "user", "content": "Hello, who are you?"}])
outputs = model.generate(**inputs, max_new_tokens=64)
print(tokenizer.decode(outputs[0]))
```
Load any Gemma 2 variant the same way with `from_weights("zeromodels/<variant>")`:
| Variant | Hub |
| --- | --- |
| `gemma-2-27b` | [zeromodels/gemma-2-27b](https://huggingface.co/zeromodels/gemma-2-27b) |
| `gemma-2-27b-it` | [zeromodels/gemma-2-27b-it](https://huggingface.co/zeromodels/gemma-2-27b-it) |
| `gemma-2-2b` | [zeromodels/gemma-2-2b](https://huggingface.co/zeromodels/gemma-2-2b) |
| `gemma-2-2b-it` | [zeromodels/gemma-2-2b-it](https://huggingface.co/zeromodels/gemma-2-2b-it) |
| `gemma-2-9b` | [zeromodels/gemma-2-9b](https://huggingface.co/zeromodels/gemma-2-9b) |
| `gemma-2-9b-it` | [zeromodels/gemma-2-9b-it](https://huggingface.co/zeromodels/gemma-2-9b-it) |
## Tips
- Set `KERAS_BACKEND` **before** importing Keras / zeromodels.
- Loads in **bfloat16** by default. Pass `load_dtype="float32"` for full precision,
or `quantization="int8"` to shrink further.
- See the [Gemma 2 docs](https://imvision12.github.io/ZeroModels/gemma2/).
- Community / upstream weights still work via the `hf:` prefix:
`Gemma2TextGenerate.from_weights("hf:google/gemma-2-2b")`.
## Special Thanks
A huge thank you to the Google Gemma authors for creating and releasing these models.
License: Gemma (gated). Accept the license on the upstream Hub card before downloading.
|