Skip to main content

Python/Mojo interface for Google Gemma 4

Project description

🔥 MoGemma

Python/Mojo interface for Google Gemma 3.

Features

  • Embeddings — Dense vector embeddings via a pure Mojo backend.
  • Text generation — Synchronous and async streaming with configurable sampling.
  • Multimodal Vision — Native support for Gemma 3 Vision models with zero-copy image 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

MoGemma supports Gemma 3 multimodal vision models.

  • Install mogemma[vision] to pass image file paths or raw image bytes directly.
from mogemma import SyncGemmaModel

# Initialize a vision-capable model
model = SyncGemmaModel("gemma3-4b-it")

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

All model classes default to gemma3-270m-it. Pass a model ID to use a different variant:

model = SyncGemmaModel("gemma3-1b-it")

For full control over sampling parameters, pass a GenerationConfig:

from mogemma import GenerationConfig, SyncGemmaModel

config = GenerationConfig(model_path="gemma3-1b-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="gemma3-1b-it",
        device="cpu",
    )
)

embeddings = SyncEmbeddingModel(
    EmbeddingConfig(
        model_path="gemma3-1b-it",
        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.4.1.tar.gz (210.3 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.4.1-cp313-cp313-manylinux_2_34_x86_64.whl (19.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

mogemma-0.4.1-cp313-cp313-manylinux_2_34_aarch64.whl (17.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

mogemma-0.4.1-cp313-cp313-macosx_11_0_arm64.whl (954.7 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

mogemma-0.4.1-cp313-cp313-macosx_10_13_x86_64.whl (954.7 kB view details)

Uploaded CPython 3.13macOS 10.13+ x86-64

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

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

mogemma-0.4.1-cp312-cp312-manylinux_2_34_aarch64.whl (17.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

mogemma-0.4.1-cp312-cp312-macosx_11_0_arm64.whl (954.7 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

mogemma-0.4.1-cp312-cp312-macosx_10_13_x86_64.whl (954.7 kB view details)

Uploaded CPython 3.12macOS 10.13+ x86-64

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

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

mogemma-0.4.1-cp311-cp311-manylinux_2_34_aarch64.whl (17.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

mogemma-0.4.1-cp311-cp311-macosx_11_0_arm64.whl (954.7 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

mogemma-0.4.1-cp311-cp311-macosx_10_9_x86_64.whl (954.7 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

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

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

mogemma-0.4.1-cp310-cp310-manylinux_2_34_aarch64.whl (17.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ ARM64

mogemma-0.4.1-cp310-cp310-macosx_11_0_arm64.whl (954.7 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

mogemma-0.4.1-cp310-cp310-macosx_10_9_x86_64.whl (954.7 kB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

File details

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

File metadata

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

File hashes

Hashes for mogemma-0.4.1.tar.gz
Algorithm Hash digest
SHA256 4fa4ee49fed220299f9ddd92e1e5df66a2b5423b609423e799ec052f7ddcc00e
MD5 a5ffdb6b3889157771e116808af7f6c3
BLAKE2b-256 9f38f4c0db33a4553c647d9aa2ec6f5c3e82fb73183fbafcf98be3fb2905259e

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.4.1.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.4.1-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for mogemma-0.4.1-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 f4e784ee65db754eb604d1f1d17161872c4fab0c284e6e337e45623faf21af83
MD5 0a9643d2aa9d2985b06cf620d1557255
BLAKE2b-256 fb0ccb75e1f586bd383f883d3bf1ac26b813072feb83bbd89637d2017e2cc064

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.4.1-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.4.1-cp313-cp313-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for mogemma-0.4.1-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 76794c5887e6b45a733e7d0e60d5712a0761b1cecb6e86b6f3ad3bbbb8eb9ad0
MD5 459f7a48abbf9bcf9f9228dec2de021c
BLAKE2b-256 32beaede043315ad8efd6ea9f276248f8b5e2428f31181ccab70bcd32c23b8e3

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.4.1-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.4.1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for mogemma-0.4.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f370b9d04a39fceb1395d1c83a855cf7cf11c67bf8cec8a9d7403e1622cf7aca
MD5 d985f01b71cf681043929df086bacfa1
BLAKE2b-256 be325d4ad8183f0de30c69716e1aa32398cb24f376ebb7e518d75898f8684560

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.4.1-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.4.1-cp313-cp313-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for mogemma-0.4.1-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 b147b63239c794a5886249ec7816fa80ce98caaa6911c7501ccb37496a12a905
MD5 86444ef5fdc9a3bf18496d2feac07d2c
BLAKE2b-256 ef2f1318dbbf05a85144e2e51c29d705fc975317d8a19943e1a12311b72001e6

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.4.1-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.4.1-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for mogemma-0.4.1-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 799a981c6840ade41bd32f2e94602ca0473192c2e20a9b73a566774d08abe624
MD5 9f69a90c593655e85c2e4b84ec304222
BLAKE2b-256 b7ad767eb5627375407aaa7aa3d69fdbfba5a7d9bf4e4fa48b8da4a7396c976c

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.4.1-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.4.1-cp312-cp312-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for mogemma-0.4.1-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 b92b13e2e1d56082615bf1faace56c1d725fea079bdb452889e42aa0797ae425
MD5 ad33ec05be06180b39d743f5ad21eca5
BLAKE2b-256 316553729d012847b0e26ea754bba7c9a51127be84f2783fece7c553cca80501

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.4.1-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.4.1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for mogemma-0.4.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 772bfa61cfa6568b0175450a84a4b50b9ecbb75336d33d0c6ef7188288397d8d
MD5 8210c33edc9231f2b9565eb1a50fff6f
BLAKE2b-256 437c9dbaf9b4ac0329fc72d6346cff8dd2d57ca7d616ce1a0dc53a2c2ea68e68

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.4.1-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.4.1-cp312-cp312-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for mogemma-0.4.1-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 1bdc220bc43ed871d946cbf5d7555bd14128d155df51b54010a53c09247ce255
MD5 6761e4078d5101b2eb13a3f77e6f665d
BLAKE2b-256 34497b38c6a5f517e4824bcb632946028cdbbf9c4934d2e21ae4b4700a97313f

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.4.1-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.4.1-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for mogemma-0.4.1-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 fcb5dba2097b86dfa510b3ecc5305e7c0ae9690cac3b30a88ce2ffd9f9311c61
MD5 bc1d42588e02e138851f43e2ed88d122
BLAKE2b-256 adff66f4aba5816eead3fd797b3e29ad327f5be5736f7b82dba035905ef0bb7d

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.4.1-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.4.1-cp311-cp311-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for mogemma-0.4.1-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 5b7e64909afec887d03f28c6b721cd35e1dc2b3469cbdca07db4844f51731aee
MD5 f665d9cabf22bb6314cbbadaf8669157
BLAKE2b-256 c250a07dd964c2a0de5dbd5f46755efb04735bbaf63cd5a79a37d6b13986322b

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.4.1-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.4.1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for mogemma-0.4.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a7b3c94e02aa5ca1a134d2e733a4f2ad540b14a075abf32a8c80fe3d401fc7af
MD5 f593620c4f3b08e396da94d3b05d2461
BLAKE2b-256 a52a0ead7b10703637a7ec8e31aa76759d662e04087bd5f6386033e253ab379e

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.4.1-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.4.1-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for mogemma-0.4.1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 2348bcc04edcdb30a0e7e7ea37b85200dc8d8c4045ecf756ccc5043e8bf8e00f
MD5 17046b6469f6c75b054010017b1e87b6
BLAKE2b-256 529e1a3681c83c85a9825f25e26dafe302f6f743f2e00d2e0df0d9570b0ccf70

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.4.1-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.4.1-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for mogemma-0.4.1-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 896d0c98cd39041fce9a2b54f62e7854deedc34098c03bc589d009d675e7c56d
MD5 4cc298c6757e56534ae1d76e7573e51c
BLAKE2b-256 e63337bed75f812ca579e9b27d0c39b5304b15914323d18030e137537a7dc899

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.4.1-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.4.1-cp310-cp310-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for mogemma-0.4.1-cp310-cp310-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 5fcbeab70cf576f5a214a3427f11c3f462f22c267cebba20e8a7b95f5c245803
MD5 0d5b3bf673029f8387cec4370bed992a
BLAKE2b-256 33360a07ebe19a3d4b47bb533d7031ee9284308254f6d36647d867e2d8e1583d

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.4.1-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.4.1-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for mogemma-0.4.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5b1e4f62d562389cbddc3e616ff7100dd33f0db19e35010655b78ae7ec309679
MD5 a83ee040642c3fdf0d693ac82b21eb06
BLAKE2b-256 f51235eb36baf2ea310bba4cc707a07a597c857d13b827b04bfaccf726155462

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.4.1-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.4.1-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for mogemma-0.4.1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 eb50a4cf801f3bd793c1ff57004946a000bc7822d74ba044e7f9230a7a5ee7a4
MD5 71341b22921e559d6b701f6494c54b52
BLAKE2b-256 097766ed25e62d507815de33e54a1546bdfa1d515f189e837a44de8ca982ca5a

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.4.1-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