Instructions to use zeromodels/gemma-4-e2b-it with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- ZeroModels
How to use zeromodels/gemma-4-e2b-it with ZeroModels:
# pip install -U zeromodels # ZeroModels is pure Keras 3, so pick a backend: "jax", "torch" or "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" from zeromodels import AutoZModel # AutoZModel reads the repo's model_type and loads the matching class. # For a task head use the matching loader, e.g. AutoZMImageClassify / AutoZMDetect / # AutoZMSemanticSegment / AutoZMTextGenerate (see zeromodels.auto). model = AutoZModel.from_weights("zeromodels/gemma-4-e2b-it") - Keras
How to use zeromodels/gemma-4-e2b-it with Keras:
# !pip install -U keras tensorflow huggingface_hub # Keras needs TensorFlow installed to read "hf://" paths, so the tensorflow backend is selected here; # "jax" and "torch" also work for computation once TensorFlow is installed. import os os.environ["KERAS_BACKEND"] = "tensorflow" import keras model = keras.saving.load_model("hf://zeromodels/gemma-4-e2b-it") - Notebooks
- Google Colab
- Kaggle
Migrate to zeromodels (rename kf_*.json -> zm_*.json, fix refs in config + README, ensure tag + badge)
Browse files- README.md +25 -25
- kf_config.json → zm_config.json +3 -3
- kf_preprocessor.json → zm_preprocessor.json +3 -3
README.md
CHANGED
|
@@ -2,12 +2,12 @@
|
|
| 2 |
pipeline_tag: any-to-any
|
| 3 |
license: apache-2.0
|
| 4 |
base_model: google/gemma-4-E2B-it
|
| 5 |
-
library_name:
|
| 6 |
language:
|
| 7 |
- en
|
| 8 |
tags:
|
| 9 |
- keras
|
| 10 |
-
-
|
| 11 |
- gemma4
|
| 12 |
- gemma-4
|
| 13 |
- any-to-any
|
|
@@ -16,16 +16,16 @@ tags:
|
|
| 16 |
- tf
|
| 17 |
---
|
| 18 |
|
| 19 |
-
*See [our collection](https://huggingface.co/
|
| 20 |
|
| 21 |
# Run Gemma 4 with Keras 3: JAX, PyTorch, or TensorFlow
|
| 22 |
|
| 23 |
-
[ for
|
| 28 |
-
[
|
| 29 |
**TensorFlow / Torch / JAX**. This is the **5B** variant, served here as
|
| 30 |
**image + audio + text -> text** via `Gemma4Processor`; weights are stored in **bfloat16**.
|
| 31 |
|
|
@@ -53,10 +53,10 @@ For model details, license, and usage terms, see Google's
|
|
| 53 |
import os
|
| 54 |
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
|
| 55 |
|
| 56 |
-
from
|
| 57 |
|
| 58 |
-
model = Gemma4TextGenerate.from_weights("
|
| 59 |
-
tokenizer = Gemma4Tokenizer.from_weights("
|
| 60 |
|
| 61 |
inputs = tokenizer([{"role": "user", "content": "Hello, who are you?"}])
|
| 62 |
outputs = model.generate(**inputs, max_new_tokens=64)
|
|
@@ -70,10 +70,10 @@ import os
|
|
| 70 |
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
|
| 71 |
|
| 72 |
from PIL import Image
|
| 73 |
-
from
|
| 74 |
|
| 75 |
-
model = Gemma4ConditionalGenerate.from_weights("
|
| 76 |
-
processor = Gemma4Processor.from_weights("
|
| 77 |
|
| 78 |
inputs = processor(conversation=[
|
| 79 |
{"role": "user", "content": [
|
|
@@ -86,27 +86,27 @@ outputs = model.generate(**inputs, max_new_tokens=64)
|
|
| 86 |
print(processor.decode(outputs[0]))
|
| 87 |
```
|
| 88 |
|
| 89 |
-
Load any Gemma 4 variant the same way with `from_weights("
|
| 90 |
|
| 91 |
| Variant | Hub |
|
| 92 |
| --- | --- |
|
| 93 |
-
| `gemma-4-12b` | [
|
| 94 |
-
| `gemma-4-12b-it` | [
|
| 95 |
-
| `gemma-4-26b-a4b` | [
|
| 96 |
-
| `gemma-4-26b-a4b-it` | [
|
| 97 |
-
| `gemma-4-31b` | [
|
| 98 |
-
| `gemma-4-31b-it` | [
|
| 99 |
-
| `gemma-4-e2b` | [
|
| 100 |
-
| `gemma-4-e2b-it` | [
|
| 101 |
-
| `gemma-4-e4b` | [
|
| 102 |
-
| `gemma-4-e4b-it` | [
|
| 103 |
|
| 104 |
## Tips
|
| 105 |
|
| 106 |
-
- Set `KERAS_BACKEND` **before** importing Keras /
|
| 107 |
- Loads in **bfloat16** by default. Pass `load_dtype="float32"` for full precision,
|
| 108 |
or `quantization="int8"` to shrink further.
|
| 109 |
-
- See the [Gemma 4 docs](https://imvision12.github.io/
|
| 110 |
- Community / upstream weights still work via the `hf:` prefix:
|
| 111 |
`Gemma4ConditionalGenerate.from_weights("hf:google/gemma-4-E2B-it")`.
|
| 112 |
|
|
|
|
| 2 |
pipeline_tag: any-to-any
|
| 3 |
license: apache-2.0
|
| 4 |
base_model: google/gemma-4-E2B-it
|
| 5 |
+
library_name: zeromodels
|
| 6 |
language:
|
| 7 |
- en
|
| 8 |
tags:
|
| 9 |
- keras
|
| 10 |
+
- zeromodels
|
| 11 |
- gemma4
|
| 12 |
- gemma-4
|
| 13 |
- any-to-any
|
|
|
|
| 16 |
- tf
|
| 17 |
---
|
| 18 |
|
| 19 |
+
*See [our collection](https://huggingface.co/zeromodels) for all Gemma 4 sizes and variants.*
|
| 20 |
|
| 21 |
# Run Gemma 4 with Keras 3: JAX, PyTorch, or TensorFlow
|
| 22 |
|
| 23 |
+
[](https://github.com/IMvision12/ZeroModels) [](https://imvision12.github.io/ZeroModels/gemma4/) [](https://huggingface.co/zeromodels)
|
| 24 |
|
| 25 |
+
# zeromodels/gemma-4-e2b-it
|
| 26 |
|
| 27 |
Pure-**Keras 3** conversion of [`google/gemma-4-E2B-it`](https://huggingface.co/google/gemma-4-E2B-it) for
|
| 28 |
+
[zeromodels](https://github.com/IMvision12/ZeroModels). One implementation runs unmodified on
|
| 29 |
**TensorFlow / Torch / JAX**. This is the **5B** variant, served here as
|
| 30 |
**image + audio + text -> text** via `Gemma4Processor`; weights are stored in **bfloat16**.
|
| 31 |
|
|
|
|
| 53 |
import os
|
| 54 |
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
|
| 55 |
|
| 56 |
+
from zeromodels.models.gemma4 import Gemma4TextGenerate, Gemma4Tokenizer
|
| 57 |
|
| 58 |
+
model = Gemma4TextGenerate.from_weights("zeromodels/gemma-4-e2b-it")
|
| 59 |
+
tokenizer = Gemma4Tokenizer.from_weights("zeromodels/gemma-4-e2b-it")
|
| 60 |
|
| 61 |
inputs = tokenizer([{"role": "user", "content": "Hello, who are you?"}])
|
| 62 |
outputs = model.generate(**inputs, max_new_tokens=64)
|
|
|
|
| 70 |
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
|
| 71 |
|
| 72 |
from PIL import Image
|
| 73 |
+
from zeromodels.models.gemma4 import Gemma4ConditionalGenerate, Gemma4Processor
|
| 74 |
|
| 75 |
+
model = Gemma4ConditionalGenerate.from_weights("zeromodels/gemma-4-e2b-it")
|
| 76 |
+
processor = Gemma4Processor.from_weights("zeromodels/gemma-4-e2b-it")
|
| 77 |
|
| 78 |
inputs = processor(conversation=[
|
| 79 |
{"role": "user", "content": [
|
|
|
|
| 86 |
print(processor.decode(outputs[0]))
|
| 87 |
```
|
| 88 |
|
| 89 |
+
Load any Gemma 4 variant the same way with `from_weights("zeromodels/<variant>")`:
|
| 90 |
|
| 91 |
| Variant | Hub |
|
| 92 |
| --- | --- |
|
| 93 |
+
| `gemma-4-12b` | [zeromodels/gemma-4-12b](https://huggingface.co/zeromodels/gemma-4-12b) |
|
| 94 |
+
| `gemma-4-12b-it` | [zeromodels/gemma-4-12b-it](https://huggingface.co/zeromodels/gemma-4-12b-it) |
|
| 95 |
+
| `gemma-4-26b-a4b` | [zeromodels/gemma-4-26b-a4b](https://huggingface.co/zeromodels/gemma-4-26b-a4b) |
|
| 96 |
+
| `gemma-4-26b-a4b-it` | [zeromodels/gemma-4-26b-a4b-it](https://huggingface.co/zeromodels/gemma-4-26b-a4b-it) |
|
| 97 |
+
| `gemma-4-31b` | [zeromodels/gemma-4-31b](https://huggingface.co/zeromodels/gemma-4-31b) |
|
| 98 |
+
| `gemma-4-31b-it` | [zeromodels/gemma-4-31b-it](https://huggingface.co/zeromodels/gemma-4-31b-it) |
|
| 99 |
+
| `gemma-4-e2b` | [zeromodels/gemma-4-e2b](https://huggingface.co/zeromodels/gemma-4-e2b) |
|
| 100 |
+
| `gemma-4-e2b-it` | [zeromodels/gemma-4-e2b-it](https://huggingface.co/zeromodels/gemma-4-e2b-it) |
|
| 101 |
+
| `gemma-4-e4b` | [zeromodels/gemma-4-e4b](https://huggingface.co/zeromodels/gemma-4-e4b) |
|
| 102 |
+
| `gemma-4-e4b-it` | [zeromodels/gemma-4-e4b-it](https://huggingface.co/zeromodels/gemma-4-e4b-it) |
|
| 103 |
|
| 104 |
## Tips
|
| 105 |
|
| 106 |
+
- Set `KERAS_BACKEND` **before** importing Keras / zeromodels.
|
| 107 |
- Loads in **bfloat16** by default. Pass `load_dtype="float32"` for full precision,
|
| 108 |
or `quantization="int8"` to shrink further.
|
| 109 |
+
- See the [Gemma 4 docs](https://imvision12.github.io/ZeroModels/gemma4/).
|
| 110 |
- Community / upstream weights still work via the `hf:` prefix:
|
| 111 |
`Gemma4ConditionalGenerate.from_weights("hf:google/gemma-4-E2B-it")`.
|
| 112 |
|
kf_config.json → zm_config.json
RENAMED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
{
|
| 2 |
-
"library_name": "
|
| 3 |
-
"
|
| 4 |
-
"model_module": "
|
| 5 |
"model_class": "Gemma4ConditionalGenerate",
|
| 6 |
"variant": "gemma-4-e2b-it",
|
| 7 |
"weights": "model.weights.json",
|
|
|
|
| 1 |
{
|
| 2 |
+
"library_name": "zeromodels",
|
| 3 |
+
"zeromodels_version": "1.2.1",
|
| 4 |
+
"model_module": "zeromodels.models.gemma4",
|
| 5 |
"model_class": "Gemma4ConditionalGenerate",
|
| 6 |
"variant": "gemma-4-e2b-it",
|
| 7 |
"weights": "model.weights.json",
|
kf_preprocessor.json → zm_preprocessor.json
RENAMED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
{
|
| 2 |
-
"library_name": "
|
| 3 |
-
"
|
| 4 |
-
"preprocessor_module": "
|
| 5 |
"preprocessor_class": "Gemma4ImageProcessor",
|
| 6 |
"variant": "gemma-4-e2b-it",
|
| 7 |
"patch_size": 16,
|
|
|
|
| 1 |
{
|
| 2 |
+
"library_name": "zeromodels",
|
| 3 |
+
"zeromodels_version": "1.2.1",
|
| 4 |
+
"preprocessor_module": "zeromodels.models.gemma4",
|
| 5 |
"preprocessor_class": "Gemma4ImageProcessor",
|
| 6 |
"variant": "gemma-4-e2b-it",
|
| 7 |
"patch_size": 16,
|