--- pipeline_tag: image-text-to-text license: gemma base_model: google/gemma-3-4b-it library_name: zeromodels extra_gated_heading: Access Gemma on Hugging Face language: - en tags: - keras - zeromodels - gemma3 - gemma-3 - image-text-to-text - arxiv:2503.19786 - pytorch - jax - tf --- *See [our collection](https://huggingface.co/zeromodels) for all Gemma 3 sizes and variants.* # Run Gemma 3 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_3-1f6feb)](https://imvision12.github.io/ZeroModels/gemma3/) [![HuggingFace](https://img.shields.io/badge/HuggingFace-Gemma_3-ffd21e?logo=huggingface&logoColor=black)](https://huggingface.co/zeromodels) # zeromodels/gemma-3-4b-it Pure-**Keras 3** conversion of [`google/gemma-3-4b-it`](https://huggingface.co/google/gemma-3-4b-it) for [zeromodels](https://github.com/IMvision12/ZeroModels). One implementation runs unmodified on **TensorFlow / Torch / JAX**. This is the instruction-tuned checkpoint, served here as **image + text -> text** via `Gemma3ConditionalGenerate`; weights are stored in **bfloat16**. For model details, license, and usage terms, see Google's [model card](https://huggingface.co/google/gemma-3-4b-it). ## ✨ Quick start ### Text-only ```python import os os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow" from zeromodels.models.gemma3 import Gemma3TextGenerate, Gemma3Tokenizer model = Gemma3TextGenerate.from_weights("zeromodels/gemma-3-4b-it") tokenizer = Gemma3Tokenizer.from_weights("zeromodels/gemma-3-4b-it") inputs = tokenizer([{"role": "user", "content": "Hello, who are you?"}]) outputs = model.generate(**inputs, max_new_tokens=64) print(tokenizer.decode(outputs[0])) ``` ### Image + text ```python from zeromodels.models.gemma3 import Gemma3ConditionalGenerate, Gemma3Processor model = Gemma3ConditionalGenerate.from_weights("zeromodels/gemma-3-4b-it") processor = Gemma3Processor.from_weights("zeromodels/gemma-3-4b-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 3 variant the same way with `from_weights("zeromodels/")`: | Variant | Hub | | --- | --- | | `gemma-3-12b-it` | [zeromodels/gemma-3-12b-it](https://huggingface.co/zeromodels/gemma-3-12b-it) | | `gemma-3-12b-pt` | [zeromodels/gemma-3-12b-pt](https://huggingface.co/zeromodels/gemma-3-12b-pt) | | `gemma-3-1b-it` | [zeromodels/gemma-3-1b-it](https://huggingface.co/zeromodels/gemma-3-1b-it) | | `gemma-3-1b-pt` | [zeromodels/gemma-3-1b-pt](https://huggingface.co/zeromodels/gemma-3-1b-pt) | | `gemma-3-270m` | [zeromodels/gemma-3-270m](https://huggingface.co/zeromodels/gemma-3-270m) | | `gemma-3-270m-it` | [zeromodels/gemma-3-270m-it](https://huggingface.co/zeromodels/gemma-3-270m-it) | | `gemma-3-27b-it` | [zeromodels/gemma-3-27b-it](https://huggingface.co/zeromodels/gemma-3-27b-it) | | `gemma-3-27b-pt` | [zeromodels/gemma-3-27b-pt](https://huggingface.co/zeromodels/gemma-3-27b-pt) | | `gemma-3-4b-it` | [zeromodels/gemma-3-4b-it](https://huggingface.co/zeromodels/gemma-3-4b-it) | | `gemma-3-4b-pt` | [zeromodels/gemma-3-4b-pt](https://huggingface.co/zeromodels/gemma-3-4b-pt) | ## 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 3 docs](https://imvision12.github.io/ZeroModels/gemma3/). - Community / upstream weights still work via the `hf:` prefix: `Gemma3ConditionalGenerate.from_weights("hf:google/gemma-3-4b-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.