🔥 MoGemma
Python/Mojo interface for Google Gemma 4.
Features
- Embeddings — Dense vector embeddings via a pure Mojo backend, using the pretrained E4B variant by default.
- Text generation — Synchronous and async streaming with configurable sampling.
- Multimodal — Native support for Gemma 4 vision (all variants) and audio (E2B/E4B) with zero-copy processing.
- Google Cloud Storage — Automatic model download from Google's
gemma-databucket. - OpenTelemetry — Optional tracing instrumentation.
Installation
Recommended for most users:
pip install 'mogemma[llm]'
This enables the text generation and embedding examples shown below.
For multimodal generation with automatic image decoding from str, Path, or raw bytes inputs:
pip install 'mogemma[vision]'
Base package only:
pip install mogemma
Use the base package if you're already preparing tokens or image arrays yourself.
Quick Start
Text Generation
The default getting-started path is mogemma[llm].
from mogemma import SyncGemmaModel
model = SyncGemmaModel()
print(model.generate("Write a haiku about a robot discovering coffee:"))
Multimodal Vision
All Gemma 4 variants support vision inputs; the default (google/gemma-4-E4B-it) additionally accepts audio.
- Install
mogemma[vision]to pass image file paths or raw image bytes directly.
from mogemma import SyncGemmaModel
# Default model is google/gemma-4-E4B-it — multimodal out of the box
model = SyncGemmaModel()
response = model.generate("Describe this image in detail:", images=["input.jpg"])
print(response)
Async Streaming
import asyncio
from mogemma import AsyncGemmaModel
async def main():
model = AsyncGemmaModel()
async for token in model.generate_stream("Once upon a time"):
print(token, end="", flush=True)
asyncio.run(main())
Embeddings
Generate dense vector embeddings natively through Mojo's optimized batched kernel operations. Pass a single string or a list of strings to process them in parallel.
from mogemma import SyncEmbeddingModel
model = SyncEmbeddingModel()
embeddings = model.embed(["Hello, world!", "Mojo runs Gemma inference."])
print(embeddings.shape) # (2, 768)
Selecting a Model Variant
Four Gemma 4 variants are supported (auto-detected from config.json):
| Model ID | Description |
|---|---|
google/gemma-4-E2B-it |
Compact multimodal (text + image + audio), ~2B params |
google/gemma-4-E4B-it |
Default for SyncGemmaModel / AsyncGemmaModel / SyncEmbeddingModel — latest small multimodal |
google/gemma-4-26B-A4B-it |
MoE (128 experts, top-8), 4B active — heavier reasoning |
Pretrained (non-instruction-tuned) E2B / E4B are listed in the Gemma 4 family but are not currently published to gs://gemma-data; SyncEmbeddingModel therefore defaults to the -it variant until pretrained ships.
Pass a model ID to override the default:
model = SyncGemmaModel("google/gemma-4-26B-A4B-it")
For full control over sampling parameters, pass a GenerationConfig:
from mogemma import GenerationConfig, SyncGemmaModel
config = GenerationConfig(model_path="google/gemma-4-26B-A4B-it", temperature=0.7)
model = SyncGemmaModel(config)
Device Selection
GenerationConfig and EmbeddingConfig accept:
device="cpu"device="gpu"device="gpu:0"(or other index)
Device handling is deterministic:
device="cpu"always runs on CPU- explicit GPU requests never silently fall back to CPU
- unavailable GPU requests raise an explicit error
Current runtime status:
cpuandgpuare executable backends todaygpu/gpu:Nexecute via a mathematically verified runtime polyfill
from mogemma import EmbeddingConfig, SyncEmbeddingModel, GenerationConfig, SyncGemmaModel
generation = SyncGemmaModel(
GenerationConfig(
model_path="google/gemma-4-E4B-it",
device="cpu",
)
)
embeddings = SyncEmbeddingModel(
EmbeddingConfig(
model_path="google/gemma-4-E4B",
device="cpu",
)
)
GPU Requirements: GPU acceleration requires Mojo nightly with GPU support, compatible GPU drivers (NVIDIA CUDA, AMD ROCm, or Apple Metal), and sufficient VRAM for model weights and KV cache.
Runtime Requirements
MoGemma leverages the latest Mojo features for maximum performance.
- Mojo Nightly: Version
0.26.3.0.devor later is required for building from source. - Python: 3.10+
Development & Architecture
Architecture Specific Builds
MoGemma automatically optimizes its Mojo core for your specific CPU architecture during the build process.
- x86_64: Uses
--target-cpu x86-64-v3for optimized vector instructions. - aarch64: Uses native ARM optimizations.
Local Development
To build the Mojo extension locally:
make build
License
MIT
Release files for mogemma 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mogemma-0.5.0.tar.gz | 337.6 kB | Details |
Built distributions (wheels)
Total release size: 154.0 MB
Release files / mogemma-0.5.0.tar.gz
| Download URL | mogemma-0.5.0.tar.gz |
|---|---|
| Size | 337.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3e39b39daf28bb13c7d9bb703d4c618223a1fc71d03f2324473c27acd5740fd7
|
|
BLAKE2b-256 checksum How to use checksums |
16b0f0e2c889fb21f9391bf49b54b7e31df1ffd87553acca9b9c12536e6e3e7e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 16, 2026.
Transparency logRelease files / mogemma-0.5.0-cp313-cp313-manylinux_2_34_x86_64.whl
| Download URL | mogemma-0.5.0-cp313-cp313-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 19.3 MB |
| Tags | CPython 3.13 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
e363035a7a9cd662568e273f12a5f385253102f91566128e2d74dfa325b8c4d0
|
|
BLAKE2b-256 checksum How to use checksums |
0a10e44fa680b5a93c597d2f08c9bd32cadd53e3f3f8c76a246271ef96fec8a8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 16, 2026.
Transparency logRelease files / mogemma-0.5.0-cp313-cp313-manylinux_2_34_aarch64.whl
| Download URL | mogemma-0.5.0-cp313-cp313-manylinux_2_34_aarch64.whl |
|---|---|
| Size | 17.2 MB |
| Tags | CPython 3.13 Linux glibc 2.34+ ARM64 |
|
SHA-256 checksum How to use checksums |
6d54230e591f114ecbf19ad4d7bc628dfdc9c6500e4d329d504cafc7b193b8ab
|
|
BLAKE2b-256 checksum How to use checksums |
ad1c62ca41e89c83ab84222d7f87367260c8cd8ed28b3deb218873fca743abbb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 16, 2026.
Transparency logRelease files / mogemma-0.5.0-cp313-cp313-macosx_11_0_arm64.whl
| Download URL | mogemma-0.5.0-cp313-cp313-macosx_11_0_arm64.whl |
|---|---|
| Size | 965.1 kB |
| Tags | CPython 3.13 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
d26fd54449f0d3d300d1742c7c2d70cb27c17844550a9f73a307767a3a7fe00b
|
|
BLAKE2b-256 checksum How to use checksums |
d4c7f564dfa0ec99e3aef309c8454f87b6a45d7a5a5de15a4de433e1b314e6e4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 16, 2026.
Transparency logRelease files / mogemma-0.5.0-cp313-cp313-macosx_10_13_x86_64.whl
| Download URL | mogemma-0.5.0-cp313-cp313-macosx_10_13_x86_64.whl |
|---|---|
| Size | 965.1 kB |
| Tags | CPython 3.13 macOS 10.13+ x86-64 |
|
SHA-256 checksum How to use checksums |
33e7e8b289fa4c3cb124c609d6b3b438d4b99ad3e71b89fa324c0044ce644d5a
|
|
BLAKE2b-256 checksum How to use checksums |
fc140427ccccb0c0a245807e482b4baa5bfc259cea63e5ef1796940c0e09a9d7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 16, 2026.
Transparency logRelease files / mogemma-0.5.0-cp312-cp312-manylinux_2_34_x86_64.whl
| Download URL | mogemma-0.5.0-cp312-cp312-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 19.3 MB |
| Tags | CPython 3.12 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
e807cc4ad4937fd5d80ac1718d90cff52dc6ae5977cf8f0120e931eb50316c48
|
|
BLAKE2b-256 checksum How to use checksums |
50e0a3cacfc135c625184c189cbfbc1bd00a2260aee7c40c9f637d528f29685c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 16, 2026.
Transparency logRelease files / mogemma-0.5.0-cp312-cp312-manylinux_2_34_aarch64.whl
| Download URL | mogemma-0.5.0-cp312-cp312-manylinux_2_34_aarch64.whl |
|---|---|
| Size | 17.2 MB |
| Tags | CPython 3.12 Linux glibc 2.34+ ARM64 |
|
SHA-256 checksum How to use checksums |
071df12965cc826149de6a4c3492706dbbe5725dbcc50e97f4b195f76dd95eac
|
|
BLAKE2b-256 checksum How to use checksums |
2049843cb818ed2032931d84118cb4053edcdafb935f8914908a2037ed135585
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 16, 2026.
Transparency logRelease files / mogemma-0.5.0-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | mogemma-0.5.0-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 965.1 kB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
50098995f5b07c0627505a90694afd8d46dc8f2516b2fc8fc4babf0b2ae54afc
|
|
BLAKE2b-256 checksum How to use checksums |
81f79a4d42d77760c7135bc177d86ce08cef978affa02e229b7fe01e9a2908f5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 16, 2026.
Transparency logRelease files / mogemma-0.5.0-cp312-cp312-macosx_10_13_x86_64.whl
| Download URL | mogemma-0.5.0-cp312-cp312-macosx_10_13_x86_64.whl |
|---|---|
| Size | 965.1 kB |
| Tags | CPython 3.12 macOS 10.13+ x86-64 |
|
SHA-256 checksum How to use checksums |
b476cd6c0b883a7f0f5321a79262916c51ce716541f219ff456ba9a82dd1f7e0
|
|
BLAKE2b-256 checksum How to use checksums |
2bcf0f41800cb5a26dab9e9a14093f44bef665048e341032b10119e714b48433
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 16, 2026.
Transparency logRelease files / mogemma-0.5.0-cp311-cp311-manylinux_2_34_x86_64.whl
| Download URL | mogemma-0.5.0-cp311-cp311-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 19.3 MB |
| Tags | CPython 3.11 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
807866d5d3a4451aa19a657f1d3222c3ad85216be839795d2fba429935cfa21b
|
|
BLAKE2b-256 checksum How to use checksums |
998570b6deb55dd6513e1d3fd4efd96e03fce8630c99675fcd6cbf122585deb4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 16, 2026.
Transparency logRelease files / mogemma-0.5.0-cp311-cp311-manylinux_2_34_aarch64.whl
| Download URL | mogemma-0.5.0-cp311-cp311-manylinux_2_34_aarch64.whl |
|---|---|
| Size | 17.2 MB |
| Tags | CPython 3.11 Linux glibc 2.34+ ARM64 |
|
SHA-256 checksum How to use checksums |
0c71fc4708633d4e8d8191dbbb2638f6c3411ad797bb17ed8c448f1fb1bc90c9
|
|
BLAKE2b-256 checksum How to use checksums |
ea7d4274cbf2308904e83f00ace8f30ced4724c10ee25f4683725ce9895dbc65
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 16, 2026.
Transparency logRelease files / mogemma-0.5.0-cp311-cp311-macosx_11_0_arm64.whl
| Download URL | mogemma-0.5.0-cp311-cp311-macosx_11_0_arm64.whl |
|---|---|
| Size | 965.1 kB |
| Tags | CPython 3.11 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
b6947378f6f17cc0641e4d699c5652f9e0077b4af461f23bfdcd65eaf262a194
|
|
BLAKE2b-256 checksum How to use checksums |
e70235903ec29d9d503f636f285e91275270b064a504e9316294f4d726a2aab3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 16, 2026.
Transparency logRelease files / mogemma-0.5.0-cp311-cp311-macosx_10_9_x86_64.whl
| Download URL | mogemma-0.5.0-cp311-cp311-macosx_10_9_x86_64.whl |
|---|---|
| Size | 965.1 kB |
| Tags | CPython 3.11 macOS 10.9+ x86-64 |
|
SHA-256 checksum How to use checksums |
3cdc2cdbcb0b6935fef1e83abec4d8df928548baa5d7a20fbbd7b7c5f0bfe869
|
|
BLAKE2b-256 checksum How to use checksums |
fe28a5e77766403f958bcd696f98b45dab7378c0029415332d4c0224722c885b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 16, 2026.
Transparency logRelease files / mogemma-0.5.0-cp310-cp310-manylinux_2_34_x86_64.whl
| Download URL | mogemma-0.5.0-cp310-cp310-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 19.3 MB |
| Tags | CPython 3.10 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
9b96d7f66975cfd122e3ce75795d7eaf36d479d1843ebe9286bfec7b27a1dcca
|
|
BLAKE2b-256 checksum How to use checksums |
05694e900eb7c4d36121ad18a72e2c85cbd2121843b789e915e7262974d19ed6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 16, 2026.
Transparency logRelease files / mogemma-0.5.0-cp310-cp310-manylinux_2_34_aarch64.whl
| Download URL | mogemma-0.5.0-cp310-cp310-manylinux_2_34_aarch64.whl |
|---|---|
| Size | 17.2 MB |
| Tags | CPython 3.10 Linux glibc 2.34+ ARM64 |
|
SHA-256 checksum How to use checksums |
6056c9b74126880d0c5211bb910ec1ae9ae1d342ff96e7b799b0d0fb5a439bc0
|
|
BLAKE2b-256 checksum How to use checksums |
f52bc0e783ea0a4625dedebcfc6e296250f50766fb83fa39b8ab301e66447a94
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 16, 2026.
Transparency logRelease files / mogemma-0.5.0-cp310-cp310-macosx_11_0_arm64.whl
| Download URL | mogemma-0.5.0-cp310-cp310-macosx_11_0_arm64.whl |
|---|---|
| Size | 965.1 kB |
| Tags | CPython 3.10 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
967a1e0eb226daaf5e2f72261c1731f52bbfbd5363530c13c3a2d4882094acdb
|
|
BLAKE2b-256 checksum How to use checksums |
e7dfeda4758d42ca1148cf3d5ea6f5ce64f4ab1aa37bf420c9e9aef345629ec1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 16, 2026.
Transparency logRelease files / mogemma-0.5.0-cp310-cp310-macosx_10_9_x86_64.whl
| Download URL | mogemma-0.5.0-cp310-cp310-macosx_10_9_x86_64.whl |
|---|---|
| Size | 965.1 kB |
| Tags | CPython 3.10 macOS 10.9+ x86-64 |
|
SHA-256 checksum How to use checksums |
4d6f713673c23ee2aa8a1bdc64816cc82c3a22d139dc34dfb60debe01caef86b
|
|
BLAKE2b-256 checksum How to use checksums |
9980e7573015ec093022d5d515cf46d93d3338b63b5685402bbc1a3226045959
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 16, 2026.
Transparency log