Skip to main content

Python/Mojo interface for Google Gemma 4

Project description

🔥 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-data bucket.
  • 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:

  • cpu and gpu are executable backends today
  • gpu / gpu:N execute 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.dev or 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-v3 for optimized vector instructions.
  • aarch64: Uses native ARM optimizations.

Local Development

To build the Mojo extension locally:

make build

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mogemma-0.5.0.tar.gz (337.6 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

mogemma-0.5.0-cp313-cp313-manylinux_2_34_x86_64.whl (19.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

mogemma-0.5.0-cp313-cp313-manylinux_2_34_aarch64.whl (17.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

mogemma-0.5.0-cp313-cp313-macosx_11_0_arm64.whl (965.1 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

mogemma-0.5.0-cp313-cp313-macosx_10_13_x86_64.whl (965.1 kB view details)

Uploaded CPython 3.13macOS 10.13+ x86-64

mogemma-0.5.0-cp312-cp312-manylinux_2_34_x86_64.whl (19.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

mogemma-0.5.0-cp312-cp312-manylinux_2_34_aarch64.whl (17.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

mogemma-0.5.0-cp312-cp312-macosx_11_0_arm64.whl (965.1 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

mogemma-0.5.0-cp312-cp312-macosx_10_13_x86_64.whl (965.1 kB view details)

Uploaded CPython 3.12macOS 10.13+ x86-64

mogemma-0.5.0-cp311-cp311-manylinux_2_34_x86_64.whl (19.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

mogemma-0.5.0-cp311-cp311-manylinux_2_34_aarch64.whl (17.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

mogemma-0.5.0-cp311-cp311-macosx_11_0_arm64.whl (965.1 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

mogemma-0.5.0-cp311-cp311-macosx_10_9_x86_64.whl (965.1 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

mogemma-0.5.0-cp310-cp310-manylinux_2_34_x86_64.whl (19.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

mogemma-0.5.0-cp310-cp310-manylinux_2_34_aarch64.whl (17.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ ARM64

mogemma-0.5.0-cp310-cp310-macosx_11_0_arm64.whl (965.1 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

mogemma-0.5.0-cp310-cp310-macosx_10_9_x86_64.whl (965.1 kB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

File details

Details for the file mogemma-0.5.0.tar.gz.

File metadata

  • Download URL: mogemma-0.5.0.tar.gz
  • Upload date:
  • Size: 337.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mogemma-0.5.0.tar.gz
Algorithm Hash digest
SHA256 3e39b39daf28bb13c7d9bb703d4c618223a1fc71d03f2324473c27acd5740fd7
MD5 bcbf6722341b410714b7280f0ed672bf
BLAKE2b-256 16b0f0e2c889fb21f9391bf49b54b7e31df1ffd87553acca9b9c12536e6e3e7e

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.5.0.tar.gz:

Publisher: publish.yml on cofin/mogemma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mogemma-0.5.0-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for mogemma-0.5.0-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 e363035a7a9cd662568e273f12a5f385253102f91566128e2d74dfa325b8c4d0
MD5 f0e9a6b413d21e17cccaab414b90e2e2
BLAKE2b-256 0a10e44fa680b5a93c597d2f08c9bd32cadd53e3f3f8c76a246271ef96fec8a8

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.5.0-cp313-cp313-manylinux_2_34_x86_64.whl:

Publisher: publish.yml on cofin/mogemma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mogemma-0.5.0-cp313-cp313-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for mogemma-0.5.0-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 6d54230e591f114ecbf19ad4d7bc628dfdc9c6500e4d329d504cafc7b193b8ab
MD5 182862da7cb695c14d83fca0cdbd4a2d
BLAKE2b-256 ad1c62ca41e89c83ab84222d7f87367260c8cd8ed28b3deb218873fca743abbb

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.5.0-cp313-cp313-manylinux_2_34_aarch64.whl:

Publisher: publish.yml on cofin/mogemma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mogemma-0.5.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for mogemma-0.5.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d26fd54449f0d3d300d1742c7c2d70cb27c17844550a9f73a307767a3a7fe00b
MD5 5334cc0049decb3e44eceb352f977e48
BLAKE2b-256 d4c7f564dfa0ec99e3aef309c8454f87b6a45d7a5a5de15a4de433e1b314e6e4

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.5.0-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: publish.yml on cofin/mogemma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mogemma-0.5.0-cp313-cp313-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for mogemma-0.5.0-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 33e7e8b289fa4c3cb124c609d6b3b438d4b99ad3e71b89fa324c0044ce644d5a
MD5 86edf0f1fa4de8a54cabd7322a8c35ce
BLAKE2b-256 fc140427ccccb0c0a245807e482b4baa5bfc259cea63e5ef1796940c0e09a9d7

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.5.0-cp313-cp313-macosx_10_13_x86_64.whl:

Publisher: publish.yml on cofin/mogemma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mogemma-0.5.0-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for mogemma-0.5.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 e807cc4ad4937fd5d80ac1718d90cff52dc6ae5977cf8f0120e931eb50316c48
MD5 df8eaf078873ca29180996f2da7b4da3
BLAKE2b-256 50e0a3cacfc135c625184c189cbfbc1bd00a2260aee7c40c9f637d528f29685c

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.5.0-cp312-cp312-manylinux_2_34_x86_64.whl:

Publisher: publish.yml on cofin/mogemma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mogemma-0.5.0-cp312-cp312-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for mogemma-0.5.0-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 071df12965cc826149de6a4c3492706dbbe5725dbcc50e97f4b195f76dd95eac
MD5 29c319489b7ac66f961a9dc38d988fce
BLAKE2b-256 2049843cb818ed2032931d84118cb4053edcdafb935f8914908a2037ed135585

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.5.0-cp312-cp312-manylinux_2_34_aarch64.whl:

Publisher: publish.yml on cofin/mogemma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mogemma-0.5.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for mogemma-0.5.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 50098995f5b07c0627505a90694afd8d46dc8f2516b2fc8fc4babf0b2ae54afc
MD5 b5131a09aae70bc975e89f64ac1d52b0
BLAKE2b-256 81f79a4d42d77760c7135bc177d86ce08cef978affa02e229b7fe01e9a2908f5

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.5.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: publish.yml on cofin/mogemma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mogemma-0.5.0-cp312-cp312-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for mogemma-0.5.0-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 b476cd6c0b883a7f0f5321a79262916c51ce716541f219ff456ba9a82dd1f7e0
MD5 3bfb0a866f635f5033a0d9ecb2b576f7
BLAKE2b-256 2bcf0f41800cb5a26dab9e9a14093f44bef665048e341032b10119e714b48433

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.5.0-cp312-cp312-macosx_10_13_x86_64.whl:

Publisher: publish.yml on cofin/mogemma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mogemma-0.5.0-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for mogemma-0.5.0-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 807866d5d3a4451aa19a657f1d3222c3ad85216be839795d2fba429935cfa21b
MD5 a5d74d3f854a924a93ff59ed973ec65a
BLAKE2b-256 998570b6deb55dd6513e1d3fd4efd96e03fce8630c99675fcd6cbf122585deb4

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.5.0-cp311-cp311-manylinux_2_34_x86_64.whl:

Publisher: publish.yml on cofin/mogemma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mogemma-0.5.0-cp311-cp311-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for mogemma-0.5.0-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 0c71fc4708633d4e8d8191dbbb2638f6c3411ad797bb17ed8c448f1fb1bc90c9
MD5 3e921a07399fcc50e41494dfe2d2515f
BLAKE2b-256 ea7d4274cbf2308904e83f00ace8f30ced4724c10ee25f4683725ce9895dbc65

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.5.0-cp311-cp311-manylinux_2_34_aarch64.whl:

Publisher: publish.yml on cofin/mogemma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mogemma-0.5.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for mogemma-0.5.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b6947378f6f17cc0641e4d699c5652f9e0077b4af461f23bfdcd65eaf262a194
MD5 2b332086fe5061713510e415cab93168
BLAKE2b-256 e70235903ec29d9d503f636f285e91275270b064a504e9316294f4d726a2aab3

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.5.0-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: publish.yml on cofin/mogemma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mogemma-0.5.0-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for mogemma-0.5.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 3cdc2cdbcb0b6935fef1e83abec4d8df928548baa5d7a20fbbd7b7c5f0bfe869
MD5 3483d12fa0129670506a4f2059e1eef4
BLAKE2b-256 fe28a5e77766403f958bcd696f98b45dab7378c0029415332d4c0224722c885b

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.5.0-cp311-cp311-macosx_10_9_x86_64.whl:

Publisher: publish.yml on cofin/mogemma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mogemma-0.5.0-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for mogemma-0.5.0-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 9b96d7f66975cfd122e3ce75795d7eaf36d479d1843ebe9286bfec7b27a1dcca
MD5 3006d80b9f7a83b96361089a4dae8828
BLAKE2b-256 05694e900eb7c4d36121ad18a72e2c85cbd2121843b789e915e7262974d19ed6

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.5.0-cp310-cp310-manylinux_2_34_x86_64.whl:

Publisher: publish.yml on cofin/mogemma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mogemma-0.5.0-cp310-cp310-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for mogemma-0.5.0-cp310-cp310-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 6056c9b74126880d0c5211bb910ec1ae9ae1d342ff96e7b799b0d0fb5a439bc0
MD5 b5f6e872d6583b4657ba752da35d7a2c
BLAKE2b-256 f52bc0e783ea0a4625dedebcfc6e296250f50766fb83fa39b8ab301e66447a94

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.5.0-cp310-cp310-manylinux_2_34_aarch64.whl:

Publisher: publish.yml on cofin/mogemma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mogemma-0.5.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for mogemma-0.5.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 967a1e0eb226daaf5e2f72261c1731f52bbfbd5363530c13c3a2d4882094acdb
MD5 328a9fc9757b3a1e564e6f7193f0484b
BLAKE2b-256 e7dfeda4758d42ca1148cf3d5ea6f5ce64f4ab1aa37bf420c9e9aef345629ec1

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.5.0-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: publish.yml on cofin/mogemma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mogemma-0.5.0-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for mogemma-0.5.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 4d6f713673c23ee2aa8a1bdc64816cc82c3a22d139dc34dfb60debe01caef86b
MD5 914badb5bafc0185c8cc3e4b41827a19
BLAKE2b-256 9980e7573015ec093022d5d515cf46d93d3338b63b5685402bbc1a3226045959

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.5.0-cp310-cp310-macosx_10_9_x86_64.whl:

Publisher: publish.yml on cofin/mogemma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page