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.0.tar.gz (212.2 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.0-cp313-cp313-manylinux_2_34_x86_64.whl (19.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

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

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

mogemma-0.4.0-cp313-cp313-macosx_11_0_arm64.whl (887.6 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

mogemma-0.4.0-cp313-cp313-macosx_10_13_x86_64.whl (887.6 kB view details)

Uploaded CPython 3.13macOS 10.13+ x86-64

mogemma-0.4.0-cp312-cp312-manylinux_2_34_x86_64.whl (19.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

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

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

mogemma-0.4.0-cp312-cp312-macosx_11_0_arm64.whl (887.6 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

mogemma-0.4.0-cp312-cp312-macosx_10_13_x86_64.whl (887.6 kB view details)

Uploaded CPython 3.12macOS 10.13+ x86-64

mogemma-0.4.0-cp311-cp311-manylinux_2_34_x86_64.whl (19.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

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

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

mogemma-0.4.0-cp311-cp311-macosx_11_0_arm64.whl (887.6 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

mogemma-0.4.0-cp311-cp311-macosx_10_9_x86_64.whl (887.6 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

mogemma-0.4.0-cp310-cp310-manylinux_2_34_x86_64.whl (19.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

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

Uploaded CPython 3.10manylinux: glibc 2.34+ ARM64

mogemma-0.4.0-cp310-cp310-macosx_11_0_arm64.whl (887.6 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

mogemma-0.4.0-cp310-cp310-macosx_10_9_x86_64.whl (887.6 kB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: mogemma-0.4.0.tar.gz
  • Upload date:
  • Size: 212.2 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.0.tar.gz
Algorithm Hash digest
SHA256 ad3bf099a75d8dc4f51fd4dea37797a6540600ec0a924e9d6277114c2c627e33
MD5 5f7c8492d9b05786953ce784da620255
BLAKE2b-256 1c420b8dfcab17e8e67e51425ffffb91ffa4aaf99f566c9678bbeccd47d173ef

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mogemma-0.4.0-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 fd4187fa2bbadba5ff34b0a2d493f2f4d9ba8b6350d399733208658254afa622
MD5 9e50838d02f0c8c690714c82559de09c
BLAKE2b-256 4cf097aa805f168045e194b231f51f11a536889a2a7918cbadf76d438f801708

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mogemma-0.4.0-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 e8161c28fd3e874c09b573000c65896e1f7e8d5d39c2251711c0893306288af7
MD5 62d7bb8f27df90bf5b5d66ac68e8cfd6
BLAKE2b-256 ddd20ee4773b06f521755fa5c1d2039240eccbd74b6f2d70a9af8f4ca203e9de

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mogemma-0.4.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 136b69ab2b4ebe5e038bfd2df4c855839a220b169cb6ed0fb9a026cd42dd6c7f
MD5 c77db9629af1b5238bbd3baa4237f9b3
BLAKE2b-256 daa0545ec3b43b5906e3a5ff1ac04d997467c669c4606e25763d32bcef44b802

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mogemma-0.4.0-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 867a5f00ddf98776547bc77b7e61b78f02ba2074d6f16d169277987de91ab44b
MD5 ae959f5312288db93bd0b89486a21842
BLAKE2b-256 30af3445ffc9c83ea76e52c3c57673a4dd69d65276c0660cfe1eef79b9d48511

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mogemma-0.4.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 980172d063a62d9775393556789f05f341936901c74bce5d95d521d52cc1a13d
MD5 d081e840e69a44f66b8f53f9abe7b084
BLAKE2b-256 a48d5c0e8346e4ac03d9ea977c2c7d617a7a231b40c70159cc63dc1d572383d1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mogemma-0.4.0-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 b2c14ed424ac8b122b8b487c275972b22648f1df10687260978208192c9f202e
MD5 2496c2798890e633c3a7db42282839a5
BLAKE2b-256 a8577ce8e496fe2d94b15cc9017250c105c15ff84b42b27a0cdb561039a3c088

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mogemma-0.4.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 707715b9feb2a57934a3d261a7bf7a1a6eca72844f250e34e60f541ed86af419
MD5 a912620a4c287c856f24831e80f57733
BLAKE2b-256 e69c518c0a247cc4e328428e183abe135082bfa1853a2e88db5f9f9c81f2e51b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mogemma-0.4.0-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 309ae5bfbce310b24aed13350bd798e69be61add5d8b91b0172064b4568d08b1
MD5 18a114dbe60515cd5d37cda2aec560fa
BLAKE2b-256 b975e9d48d856f67a25418698b86e1a647132b704adafdecd8fb4bd7c2f7dfcc

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mogemma-0.4.0-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 4b45d64f72e70a332cff438da3127fab12aaddbecd16f31545910b2d99938115
MD5 13eb8ea144db38e6f8c78859e9c37598
BLAKE2b-256 f14f6602fa83a02063a51bd607a20ab3b9d713b9bce57c87be096b6d0de79970

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mogemma-0.4.0-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 f696298b642e8f29d0067a8ca83b0390a034a7e900bb0198c590342a8ab736d1
MD5 a278e2e2338bc86b4b4e8528065260bb
BLAKE2b-256 31c9f79f8e6974bb5773d74367475b2d9fd091c6079271af2372ec6f556a1933

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mogemma-0.4.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1f4a4cd07d9688c9bac3fa6574871b15895f29145754cf9b83237a9f94f8bf97
MD5 7a29f3fb477e42fb38333b773d81a11d
BLAKE2b-256 2c01fd95a38674640243ae7afc51f8927600d475c03a7ac0fa02f18e66b3ecbe

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mogemma-0.4.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 66410cdae00df9a94665b133c5d9d556ae86f98fbc73ff3da3173022cbb3cb27
MD5 d6cf25962c8fa8b6b4f542611a313c75
BLAKE2b-256 3891cc93896c78d9dc6c713f4e52c8a0661ff528fd857c6bda34c73e1531a838

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mogemma-0.4.0-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 16f72e4466e8d1d6a377568bf93a84fad2e4aa14ec8dd39356c790f2d76e55a1
MD5 b76dd18ff6eab1cf25278051ccb7201e
BLAKE2b-256 257c39cb404ae8df52b0ec73d780c304836008775a52417af4319143c77896e1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mogemma-0.4.0-cp310-cp310-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 8f0d1c3ffc824b40164ad2d0f48973527a43040b782a83b03e38de9965bad9d0
MD5 ffda6e037b5e767dbe27b6b54b55c6b6
BLAKE2b-256 ed985e3ad492173aece9c9438a9c987b2e7c925654172f5d3409177c032602ca

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mogemma-0.4.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7e3c1898a1a1d427e9497028630a62376bfd9c8f3f0884d2effa35ef96222de6
MD5 f42ed8d291a02db12db38727ef9e7e12
BLAKE2b-256 720caceabfce870d0fb4a0a1a782ed26288160199f83f53d39124c1666e5ee74

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mogemma-0.4.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 cc083ae1a8cfd93d57a2155d14f93133e8856065b2d0999feaf4e4e3c381ac62
MD5 449f161a097ff31c0082f8f2c36c395c
BLAKE2b-256 a7984edb9c993e0eaebb67616107a40077c032b5d50a07995eda2d6250e110aa

See more details on using hashes here.

Provenance

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