File size: 4,750 Bytes
cc5734b
 
 
 
b51e234
cc5734b
 
 
 
b51e234
cc5734b
 
 
 
 
 
 
 
b51e234
cc5734b
 
 
b51e234
cc5734b
b51e234
cc5734b
 
b51e234
cc5734b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b51e234
cc5734b
b51e234
 
cc5734b
 
 
 
 
 
 
 
 
 
 
 
 
b51e234
cc5734b
b51e234
 
cc5734b
 
 
 
 
 
 
 
 
 
 
 
b51e234
cc5734b
 
 
b51e234
 
 
 
 
 
 
 
 
 
cc5734b
 
 
b51e234
cc5734b
 
b51e234
cc5734b
 
 
 
 
 
 
 
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
---
pipeline_tag: any-to-any
license: apache-2.0
base_model: google/gemma-4-E2B
library_name: zeromodels
language:
- en
tags:
- keras
- zeromodels
- gemma4
- gemma-4
- any-to-any
- pytorch
- jax
- tf
---

*See [our collection](https://huggingface.co/zeromodels) for all Gemma 4 sizes and variants.*

# Run Gemma 4 with Keras 3: JAX, PyTorch, or TensorFlow

[![GitHub](https://img.shields.io/badge/GitHub-ZeroModels-181717?logo=github)](https://github.com/IMvision12/ZeroModels) [![Docs](https://img.shields.io/badge/Docs-Gemma_4-1f6feb)](https://imvision12.github.io/ZeroModels/gemma4/) [![HuggingFace](https://img.shields.io/badge/HuggingFace-Gemma_4-ffd21e?logo=huggingface&logoColor=black)](https://huggingface.co/zeromodels)

# zeromodels/gemma-4-e2b

Pure-**Keras 3** conversion of [`google/gemma-4-E2B`](https://huggingface.co/google/gemma-4-E2B) for
[zeromodels](https://github.com/IMvision12/ZeroModels). One implementation runs unmodified on
**TensorFlow / Torch / JAX**. This is the **5B** variant, served here as
**image + audio + text -> text** via `Gemma4Processor`; weights are stored in **bfloat16**.

For model details, license, and usage terms, see Google's
[model card](https://huggingface.co/google/gemma-4-E2B).

## Gemma 4 family

| Property | E2B | E4B | 12B Unified | 31B Dense |
| --- | --- | --- | --- | --- |
| Total Parameters | 2.3B effective (5.1B with embeddings) | 4.5B effective (8B with embeddings) | 11.95B | 30.7B |
| Layers | 35 | 42 | 48 | 60 |
| Sliding Window | 512 tokens | 512 tokens | 1024 tokens | 1024 tokens |
| Context Length | 128K tokens | 128K tokens | 256K tokens | 256K tokens |
| Vocabulary Size | 262K | 262K | 262K | 262K |
| Supported Modalities | Text, Image, Audio | Text, Image, Audio | Text, Image, Audio | Text, Image |
| Vision Encoder Parameters | ~150M | ~150M | - | ~550M |
| Audio Encoder Parameters | ~300M | ~300M | - | No Audio |

## ✨ Quick start

### Text-only

```python
import os
os.environ["KERAS_BACKEND"] = "torch"  # or "jax" / "tensorflow"

from zeromodels.models.gemma4 import Gemma4TextGenerate, Gemma4Tokenizer

model = Gemma4TextGenerate.from_weights("zeromodels/gemma-4-e2b")
tokenizer = Gemma4Tokenizer.from_weights("zeromodels/gemma-4-e2b")

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
import os
os.environ["KERAS_BACKEND"] = "torch"  # or "jax" / "tensorflow"

from PIL import Image
from zeromodels.models.gemma4 import Gemma4ConditionalGenerate, Gemma4Processor

model = Gemma4ConditionalGenerate.from_weights("zeromodels/gemma-4-e2b")
processor = Gemma4Processor.from_weights("zeromodels/gemma-4-e2b")

inputs = processor(conversation=[
    {"role": "user", "content": [
        {"type": "image", "image": Image.open("cat.jpg")},
        {"type": "audio", "path": "clip.wav"},
        {"type": "text", "text": "Describe the image and what you hear."},
    ]}
])
outputs = model.generate(**inputs, max_new_tokens=64)
print(processor.decode(outputs[0]))
```

Load any Gemma 4 variant the same way with `from_weights("zeromodels/<variant>")`:

| Variant | Hub |
| --- | --- |
| `gemma-4-12b` | [zeromodels/gemma-4-12b](https://huggingface.co/zeromodels/gemma-4-12b) |
| `gemma-4-12b-it` | [zeromodels/gemma-4-12b-it](https://huggingface.co/zeromodels/gemma-4-12b-it) |
| `gemma-4-26b-a4b` | [zeromodels/gemma-4-26b-a4b](https://huggingface.co/zeromodels/gemma-4-26b-a4b) |
| `gemma-4-26b-a4b-it` | [zeromodels/gemma-4-26b-a4b-it](https://huggingface.co/zeromodels/gemma-4-26b-a4b-it) |
| `gemma-4-31b` | [zeromodels/gemma-4-31b](https://huggingface.co/zeromodels/gemma-4-31b) |
| `gemma-4-31b-it` | [zeromodels/gemma-4-31b-it](https://huggingface.co/zeromodels/gemma-4-31b-it) |
| `gemma-4-e2b` | [zeromodels/gemma-4-e2b](https://huggingface.co/zeromodels/gemma-4-e2b) |
| `gemma-4-e2b-it` | [zeromodels/gemma-4-e2b-it](https://huggingface.co/zeromodels/gemma-4-e2b-it) |
| `gemma-4-e4b` | [zeromodels/gemma-4-e4b](https://huggingface.co/zeromodels/gemma-4-e4b) |
| `gemma-4-e4b-it` | [zeromodels/gemma-4-e4b-it](https://huggingface.co/zeromodels/gemma-4-e4b-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 4 docs](https://imvision12.github.io/ZeroModels/gemma4/).
- Community / upstream weights still work via the `hf:` prefix:
  `Gemma4ConditionalGenerate.from_weights("hf:google/gemma-4-E2B")`.

## Special Thanks

A huge thank you to the Google Gemma authors for creating and releasing these models.

License: Apache 2.0.