Instructions to use zeromodels/gemma-2b-it with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- KerasFormers
How to use zeromodels/gemma-2b-it with KerasFormers:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Keras
How to use zeromodels/gemma-2b-it 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-2b-it") - Notebooks
- Google Colab
- Kaggle
| pipeline_tag: text-generation | |
| license: gemma | |
| base_model: google/gemma-2b-it | |
| library_name: kerasformers | |
| extra_gated_heading: Access Gemma on Hugging Face | |
| language: | |
| - en | |
| tags: | |
| - keras | |
| - kerasformers | |
| - gemma | |
| - gemma-2b | |
| - text-generation | |
| - arxiv:2403.08295 | |
| - pytorch | |
| - jax | |
| - tf | |
| *See [our collection](https://huggingface.co/kerasformers) for all Gemma sizes and variants.* | |
| # Run Gemma with Keras 3: JAX, PyTorch, or TensorFlow | |
| [](https://github.com/IMvision12/KerasFormers) [](https://imvision12.github.io/KerasFormers/gemma/) [](https://huggingface.co/kerasformers) | |
| # kerasformers/gemma-2b-it | |
| Pure-**Keras 3** conversion of [`google/gemma-2b-it`](https://huggingface.co/google/gemma-2b-it) for | |
| [kerasformers](https://github.com/IMvision12/KerasFormers). One implementation runs unmodified on | |
| **TensorFlow / Torch / JAX**. This is the instruction-tuned checkpoint, served here as **text -> text** via `GemmaTextGenerate`; weights are | |
| stored in **bfloat16**. | |
| For model details, license, and usage terms, see Google's | |
| [model card](https://huggingface.co/google/gemma-2b-it). | |
| ## ✨ Quick start | |
| ```python | |
| import os | |
| os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow" | |
| from kerasformers.models.gemma import GemmaTextGenerate, GemmaTokenizer | |
| model = GemmaTextGenerate.from_weights("kerasformers/gemma-2b-it") | |
| tokenizer = GemmaTokenizer.from_weights("kerasformers/gemma-2b-it") | |
| 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 variant the same way with `from_weights("kerasformers/<variant>")`: | |
| | Variant | Hub | | |
| | --- | --- | | |
| | `gemma-1.1-2b-it` | [kerasformers/gemma-1.1-2b-it](https://huggingface.co/kerasformers/gemma-1.1-2b-it) | | |
| | `gemma-1.1-7b-it` | [kerasformers/gemma-1.1-7b-it](https://huggingface.co/kerasformers/gemma-1.1-7b-it) | | |
| | `gemma-2b` | [kerasformers/gemma-2b](https://huggingface.co/kerasformers/gemma-2b) | | |
| | `gemma-2b-it` | [kerasformers/gemma-2b-it](https://huggingface.co/kerasformers/gemma-2b-it) | | |
| | `gemma-7b` | [kerasformers/gemma-7b](https://huggingface.co/kerasformers/gemma-7b) | | |
| | `gemma-7b-it` | [kerasformers/gemma-7b-it](https://huggingface.co/kerasformers/gemma-7b-it) | | |
| ## Tips | |
| - Set `KERAS_BACKEND` **before** importing Keras / kerasformers. | |
| - Loads in **bfloat16** by default. Pass `load_dtype="float32"` for full precision, | |
| or `quantization="int8"` to shrink further. | |
| - See the [Gemma docs](https://imvision12.github.io/KerasFormers/gemma/). | |
| - Community / upstream weights still work via the `hf:` prefix: | |
| `GemmaTextGenerate.from_weights("hf:google/gemma-2b-it")`. | |
| ## 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. | |