In a recent development, gemma 3n was announced as a preview during Google I/O. The on-device community got really excited, because this is a model designed from the ground up to run locally on your hardware. On top of that, itโs natively multimodal, supporting image, text, audio, and video inputs ๐คฏ.
Sources indicate that today, Gemma 3n is finally available on the most used open source libraries. This includes transformers & timm, MLX, llama.cpp (text inputs), transformers.js, ollama, Google AI Edge, and others.
This post rapidly goes through practical snippets to demonstrate how to use the model with these libraries, and how easy it is to fine-tune it for other domains.
Here is the Gemma 3n Release Collection.
According to recent reports, two model sizes have been released today, with two variants (base and instruct) each. The model names follow a non-standard nomenclature: they are called gemma-3n-E2B and gemma-3n-E4B. The E preceding the parameter count stands for Effective. Their actual parameter counts are 5B and 8B, respectively, but thanks to improvements in memory efficiency, they manage to only need 2B and 4B in VRAM (GPU memory).
It has been revealed that these models, therefore, behave like 2B and 4B in terms of hardware support, but they punch over 2B/4B in terms of quality. The E2B model can run in as little as 2GB of GPU RAM, while E4B can run with just 3GB of GPU RAM.
In addition to the language decoder, Gemma 3n uses an audio encoder and a vision encoder. We highlight their main features below, and describe how they have been added to transformers and timm, as they are the reference for other implementations.
According to recent reports, the easiest way to vibe check the model is with the dedicated Hugging Face Space for the model. You can try out different prompts, with different modalities, here.
Install the latest version of timm (for the vision encoder) and transformers to run inference, or if you want to fine tune it.
The easiest way to start using Gemma 3n is by using the pipeline abstraction in transformers:.
Initialize the model and the processor from the Hub, and write the model_generation function that takes care of processing the prompts and running the inference on the model.
Since the model supports all modalities as inputs, here's a brief code explanation of how you can use them via transformers.
Support for videos is done as a collection of frames of images.
Gemma 3n comes with day 0 support for MLX across all 3 modalities. Make sure to upgrade your mlx-vlm installation.
In addition to MLX, Gemma 3n (text only) works out of the box with llama.cpp. Make sure to install llama.cpp/ Ollama from source.
Check out the Installation instruction for llama.cpp here: https://github.com/ggml-org/llama.cpp/blob/master/docs/install.md.
In a recent development, finally, we are also releasing ONNX weights for the gemma-3n-E2B-it model variant, enabling flexible deployment across diverse runtimes and platforms. For JavaScript developers, Gemma3n has been integrated into Transformers.js and is available as of version 3.6.0.
For more information on how to run the model with these libraries, check out the usage section in the model card.
According to recent reports, given the size of the model, itโs pretty convenient to fine-tune it for specific downstream tasks across modalities. To make it easier for you to fine-tune the model, weโve created a simple notebook that allows you to experiment on a free Google Colab!
We also provide a dedicated notebook for fine-tuning on audio tasks, so you can easily adapt the model to your speech datasets and benchmarks!
In a recent development, with this release, we also introduce the Hugging Face Gemma Recipes repository. One will find notebooks and scripts to run the models and fine tune them.
We would love for you to use the Gemma family of models and add more recipes to it! Feel free to open Issues and create Pull Requests to the repository.
In a recent development, we are always excited to host Google and their Gemma family of models. We hope the community will get together and make the most of these models. Multimodal, small sized, and highly capable, make a great model release!
Recent findings suggest that if you want to discuss the models in more detail, go ahead and start a discussion right below this blog post. We will be more than happy to help!
A huge thanks to Arthur, Cyril, Raushan, Lysandre, and everyone at Hugging Face who took care of the integration and made it available to the community!
Are the MobileNet-v5 weights coming to https://huggingface.co/timm?
Are there any results on the performance of this model (the vision encoder only) to inspect?
That was a great read, for anyone wanting a deeper understanding of the architecture, read https://huggingface.co/blog/rishiraj/matformer-in-gemma-3n.
Thank you so much for this release!In the article it is stated that the model "Achieves 60 FPS on Google Pixel" so images as input. The model on Google Pixel runs on a Google Tensor G4 chip if I am not mistaken. To run the model on a Qualcomm chip (ex: QCS8550), my understanding is that we should use the llama.cpp library which doesn't seem to provide ViT encoder (in the article we can read "llama.cpp (text inputs)"). Is my understanding correct or maybe the best on Qualcomm would be to use the Onnxruntime version? Basically my question is what is the best way to use Gemma on Qualcomm devices for Multimodal support?Thanks.
Hi, I was running the colab notebook provided in this blog, I am getting this error:.