gemma-3n-e2b-it / README.md
IMvision12's picture
Standardize README to the kerasformers structure
1b0986b verified
|
Raw
History Blame Contribute Delete
3.98 kB
---
pipeline_tag: image-text-to-text
license: gemma
base_model: google/gemma-3n-E2B-it
library_name: kerasformers
extra_gated_heading: Access Gemma on Hugging Face
extra_gated_prompt: >-
To access Gemma on Hugging Face, you're required to review and agree to
Google's usage license. To do this, please ensure you're logged in to Hugging
Face and click below. Requests are processed immediately.
extra_gated_button_content: Acknowledge license
license_link: https://ai.google.dev/gemma/terms
language:
- en
tags:
- keras
- kerasformers
- gemma3n
- gemma-3n
- image-text-to-text
- audio-text-to-text
- multimodal
- pytorch
- jax
- tf
---
*See [our collection](https://huggingface.co/kerasformers) for all Gemma 3n sizes and variants.*
# Run Gemma 3n with Keras 3: JAX, PyTorch, or TensorFlow
[![GitHub](https://img.shields.io/badge/GitHub-KerasFormers-181717?logo=github)](https://github.com/IMvision12/KerasFormers) [![Docs](https://img.shields.io/badge/Docs-Gemma_3n-1f6feb)](https://imvision12.github.io/KerasFormers/gemma3n/) [![HuggingFace](https://img.shields.io/badge/HuggingFace-Gemma_3n-ffd21e?logo=huggingface&logoColor=black)](https://huggingface.co/kerasformers)
# kerasformers/gemma-3n-e2b-it
Pure-**Keras 3** conversion of [`google/gemma-3n-E2B-it`](https://huggingface.co/google/gemma-3n-E2B-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 **image + audio + text -> text** via `Gemma3nConditionalGenerate`; weights are
stored in **bfloat16**.
For model details, license, and usage terms, see Google's
[model card](https://huggingface.co/google/gemma-3n-E2B-it).
## ✨ Quick start
### Text-only
```python
import os
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
from kerasformers.models.gemma3n import Gemma3nTextGenerate, Gemma3nTokenizer
model = Gemma3nTextGenerate.from_weights("kerasformers/gemma-3n-e2b-it")
tokenizer = Gemma3nTokenizer.from_weights("kerasformers/gemma-3n-e2b-it")
inputs = tokenizer([{"role": "user", "content": "Hello, who are you?"}])
outputs = model.generate(**inputs, max_new_tokens=64)
print(tokenizer.decode(outputs[0]))
```
### Image + audio + text
```python
from kerasformers.models.gemma3n import Gemma3nConditionalGenerate, Gemma3nProcessor
model = Gemma3nConditionalGenerate.from_weights("kerasformers/gemma-3n-e2b-it")
processor = Gemma3nProcessor.from_weights("kerasformers/gemma-3n-e2b-it")
conversation = [
{"role": "user", "content": [
{"type": "image", "url": "https://.../image.jpg"},
{"type": "text", "text": "Describe this image."},
]},
]
inputs = processor(conversation)
outputs = model.generate(**inputs, max_new_tokens=64)
print(processor.decode(outputs[0]))
```
Load any Gemma 3n variant the same way with `from_weights("kerasformers/<variant>")`:
| Variant | Hub |
| --- | --- |
| `gemma-3n-e2b` | [kerasformers/gemma-3n-e2b](https://huggingface.co/kerasformers/gemma-3n-e2b) |
| `gemma-3n-e2b-it` | [kerasformers/gemma-3n-e2b-it](https://huggingface.co/kerasformers/gemma-3n-e2b-it) |
| `gemma-3n-e4b` | [kerasformers/gemma-3n-e4b](https://huggingface.co/kerasformers/gemma-3n-e4b) |
| `gemma-3n-e4b-it` | [kerasformers/gemma-3n-e4b-it](https://huggingface.co/kerasformers/gemma-3n-e4b-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 3n docs](https://imvision12.github.io/KerasFormers/gemma3n/).
- Community / upstream weights still work via the `hf:` prefix:
`Gemma3nConditionalGenerate.from_weights("hf:google/gemma-3n-E2B-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.