Instructions to use zeromodels/gemma-3-4b-it with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use zeromodels/gemma-3-4b-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-3-4b-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,13 +2,13 @@
|
|
| 2 |
pipeline_tag: image-text-to-text
|
| 3 |
license: gemma
|
| 4 |
base_model: google/gemma-3-4b-it
|
| 5 |
-
library_name:
|
| 6 |
extra_gated_heading: Access Gemma on Hugging Face
|
| 7 |
language:
|
| 8 |
- en
|
| 9 |
tags:
|
| 10 |
- keras
|
| 11 |
-
-
|
| 12 |
- gemma3
|
| 13 |
- gemma-3
|
| 14 |
- image-text-to-text
|
|
@@ -18,16 +18,16 @@ tags:
|
|
| 18 |
- tf
|
| 19 |
---
|
| 20 |
|
| 21 |
-
*See [our collection](https://huggingface.co/
|
| 22 |
|
| 23 |
# Run Gemma 3 with Keras 3: JAX, PyTorch, or TensorFlow
|
| 24 |
|
| 25 |
-
[ for
|
| 30 |
-
[
|
| 31 |
**TensorFlow / Torch / JAX**. This is the instruction-tuned checkpoint, served here as **image + text -> text** via `Gemma3ConditionalGenerate`; weights are
|
| 32 |
stored in **bfloat16**.
|
| 33 |
|
|
@@ -42,10 +42,10 @@ For model details, license, and usage terms, see Google's
|
|
| 42 |
import os
|
| 43 |
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
|
| 44 |
|
| 45 |
-
from
|
| 46 |
|
| 47 |
-
model = Gemma3TextGenerate.from_weights("
|
| 48 |
-
tokenizer = Gemma3Tokenizer.from_weights("
|
| 49 |
|
| 50 |
inputs = tokenizer([{"role": "user", "content": "Hello, who are you?"}])
|
| 51 |
outputs = model.generate(**inputs, max_new_tokens=64)
|
|
@@ -55,10 +55,10 @@ print(tokenizer.decode(outputs[0]))
|
|
| 55 |
### Image + text
|
| 56 |
|
| 57 |
```python
|
| 58 |
-
from
|
| 59 |
|
| 60 |
-
model = Gemma3ConditionalGenerate.from_weights("
|
| 61 |
-
processor = Gemma3Processor.from_weights("
|
| 62 |
|
| 63 |
conversation = [
|
| 64 |
{"role": "user", "content": [
|
|
@@ -71,27 +71,27 @@ outputs = model.generate(**inputs, max_new_tokens=64)
|
|
| 71 |
print(processor.decode(outputs[0]))
|
| 72 |
```
|
| 73 |
|
| 74 |
-
Load any Gemma 3 variant the same way with `from_weights("
|
| 75 |
|
| 76 |
| Variant | Hub |
|
| 77 |
| --- | --- |
|
| 78 |
-
| `gemma-3-12b-it` | [
|
| 79 |
-
| `gemma-3-12b-pt` | [
|
| 80 |
-
| `gemma-3-1b-it` | [
|
| 81 |
-
| `gemma-3-1b-pt` | [
|
| 82 |
-
| `gemma-3-270m` | [
|
| 83 |
-
| `gemma-3-270m-it` | [
|
| 84 |
-
| `gemma-3-27b-it` | [
|
| 85 |
-
| `gemma-3-27b-pt` | [
|
| 86 |
-
| `gemma-3-4b-it` | [
|
| 87 |
-
| `gemma-3-4b-pt` | [
|
| 88 |
|
| 89 |
## Tips
|
| 90 |
|
| 91 |
-
- Set `KERAS_BACKEND` **before** importing Keras /
|
| 92 |
- Loads in **bfloat16** by default. Pass `load_dtype="float32"` for full precision,
|
| 93 |
or `quantization="int8"` to shrink further.
|
| 94 |
-
- See the [Gemma 3 docs](https://imvision12.github.io/
|
| 95 |
- Community / upstream weights still work via the `hf:` prefix:
|
| 96 |
`Gemma3ConditionalGenerate.from_weights("hf:google/gemma-3-4b-it")`.
|
| 97 |
|
|
|
|
| 2 |
pipeline_tag: image-text-to-text
|
| 3 |
license: gemma
|
| 4 |
base_model: google/gemma-3-4b-it
|
| 5 |
+
library_name: zeromodels
|
| 6 |
extra_gated_heading: Access Gemma on Hugging Face
|
| 7 |
language:
|
| 8 |
- en
|
| 9 |
tags:
|
| 10 |
- keras
|
| 11 |
+
- zeromodels
|
| 12 |
- gemma3
|
| 13 |
- gemma-3
|
| 14 |
- image-text-to-text
|
|
|
|
| 18 |
- tf
|
| 19 |
---
|
| 20 |
|
| 21 |
+
*See [our collection](https://huggingface.co/zeromodels) for all Gemma 3 sizes and variants.*
|
| 22 |
|
| 23 |
# Run Gemma 3 with Keras 3: JAX, PyTorch, or TensorFlow
|
| 24 |
|
| 25 |
+
[](https://github.com/IMvision12/ZeroModels) [](https://imvision12.github.io/ZeroModels/gemma3/) [](https://huggingface.co/zeromodels)
|
| 26 |
|
| 27 |
+
# zeromodels/gemma-3-4b-it
|
| 28 |
|
| 29 |
Pure-**Keras 3** conversion of [`google/gemma-3-4b-it`](https://huggingface.co/google/gemma-3-4b-it) for
|
| 30 |
+
[zeromodels](https://github.com/IMvision12/ZeroModels). One implementation runs unmodified on
|
| 31 |
**TensorFlow / Torch / JAX**. This is the instruction-tuned checkpoint, served here as **image + text -> text** via `Gemma3ConditionalGenerate`; weights are
|
| 32 |
stored in **bfloat16**.
|
| 33 |
|
|
|
|
| 42 |
import os
|
| 43 |
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
|
| 44 |
|
| 45 |
+
from zeromodels.models.gemma3 import Gemma3TextGenerate, Gemma3Tokenizer
|
| 46 |
|
| 47 |
+
model = Gemma3TextGenerate.from_weights("zeromodels/gemma-3-4b-it")
|
| 48 |
+
tokenizer = Gemma3Tokenizer.from_weights("zeromodels/gemma-3-4b-it")
|
| 49 |
|
| 50 |
inputs = tokenizer([{"role": "user", "content": "Hello, who are you?"}])
|
| 51 |
outputs = model.generate(**inputs, max_new_tokens=64)
|
|
|
|
| 55 |
### Image + text
|
| 56 |
|
| 57 |
```python
|
| 58 |
+
from zeromodels.models.gemma3 import Gemma3ConditionalGenerate, Gemma3Processor
|
| 59 |
|
| 60 |
+
model = Gemma3ConditionalGenerate.from_weights("zeromodels/gemma-3-4b-it")
|
| 61 |
+
processor = Gemma3Processor.from_weights("zeromodels/gemma-3-4b-it")
|
| 62 |
|
| 63 |
conversation = [
|
| 64 |
{"role": "user", "content": [
|
|
|
|
| 71 |
print(processor.decode(outputs[0]))
|
| 72 |
```
|
| 73 |
|
| 74 |
+
Load any Gemma 3 variant the same way with `from_weights("zeromodels/<variant>")`:
|
| 75 |
|
| 76 |
| Variant | Hub |
|
| 77 |
| --- | --- |
|
| 78 |
+
| `gemma-3-12b-it` | [zeromodels/gemma-3-12b-it](https://huggingface.co/zeromodels/gemma-3-12b-it) |
|
| 79 |
+
| `gemma-3-12b-pt` | [zeromodels/gemma-3-12b-pt](https://huggingface.co/zeromodels/gemma-3-12b-pt) |
|
| 80 |
+
| `gemma-3-1b-it` | [zeromodels/gemma-3-1b-it](https://huggingface.co/zeromodels/gemma-3-1b-it) |
|
| 81 |
+
| `gemma-3-1b-pt` | [zeromodels/gemma-3-1b-pt](https://huggingface.co/zeromodels/gemma-3-1b-pt) |
|
| 82 |
+
| `gemma-3-270m` | [zeromodels/gemma-3-270m](https://huggingface.co/zeromodels/gemma-3-270m) |
|
| 83 |
+
| `gemma-3-270m-it` | [zeromodels/gemma-3-270m-it](https://huggingface.co/zeromodels/gemma-3-270m-it) |
|
| 84 |
+
| `gemma-3-27b-it` | [zeromodels/gemma-3-27b-it](https://huggingface.co/zeromodels/gemma-3-27b-it) |
|
| 85 |
+
| `gemma-3-27b-pt` | [zeromodels/gemma-3-27b-pt](https://huggingface.co/zeromodels/gemma-3-27b-pt) |
|
| 86 |
+
| `gemma-3-4b-it` | [zeromodels/gemma-3-4b-it](https://huggingface.co/zeromodels/gemma-3-4b-it) |
|
| 87 |
+
| `gemma-3-4b-pt` | [zeromodels/gemma-3-4b-pt](https://huggingface.co/zeromodels/gemma-3-4b-pt) |
|
| 88 |
|
| 89 |
## Tips
|
| 90 |
|
| 91 |
+
- Set `KERAS_BACKEND` **before** importing Keras / zeromodels.
|
| 92 |
- Loads in **bfloat16** by default. Pass `load_dtype="float32"` for full precision,
|
| 93 |
or `quantization="int8"` to shrink further.
|
| 94 |
+
- See the [Gemma 3 docs](https://imvision12.github.io/ZeroModels/gemma3/).
|
| 95 |
- Community / upstream weights still work via the `hf:` prefix:
|
| 96 |
`Gemma3ConditionalGenerate.from_weights("hf:google/gemma-3-4b-it")`.
|
| 97 |
|
kf_config.json → zm_config.json
RENAMED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
{
|
| 2 |
-
"library_name": "
|
| 3 |
-
"
|
| 4 |
-
"model_module": "
|
| 5 |
"model_class": "Gemma3ConditionalGenerate",
|
| 6 |
"variant": "gemma-3-4b-it",
|
| 7 |
"weights": "model.weights.json",
|
|
|
|
| 1 |
{
|
| 2 |
+
"library_name": "zeromodels",
|
| 3 |
+
"zeromodels_version": "1.2.1",
|
| 4 |
+
"model_module": "zeromodels.models.gemma3",
|
| 5 |
"model_class": "Gemma3ConditionalGenerate",
|
| 6 |
"variant": "gemma-3-4b-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": "Gemma3ImageProcessor",
|
| 6 |
"variant": "gemma-3-4b-it",
|
| 7 |
"size": 896,
|
|
|
|
| 1 |
{
|
| 2 |
+
"library_name": "zeromodels",
|
| 3 |
+
"zeromodels_version": "1.2.1",
|
| 4 |
+
"preprocessor_module": "zeromodels.models.gemma3",
|
| 5 |
"preprocessor_class": "Gemma3ImageProcessor",
|
| 6 |
"variant": "gemma-3-4b-it",
|
| 7 |
"size": 896,
|