Skip to main content

Python/Mojo interface for Google Gemma 3

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.
  • Google Cloud Storage — Automatic model download from Google's gemma-data bucket.
  • OpenTelemetry — Optional tracing instrumentation.

Installation

pip install mogemma

For text generation (requires tokenizer):

pip install 'mogemma[llm]'

Quick Start

Text Generation

from mogemma import SyncGemmaModel

model = SyncGemmaModel()
print(model.generate("Write a haiku about a robot discovering coffee:"))

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 EmbeddingModel

model = EmbeddingModel()
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, EmbeddingModel, GenerationConfig, SyncGemmaModel

generation = SyncGemmaModel(
    GenerationConfig(
        model_path="gemma3-1b-it",
        device="cpu",
    )
)

embeddings = EmbeddingModel(
    EmbeddingConfig(
        model_path="gemma3-1b-it",
        device="cpu",
    )
)

Explicit GPU requests are validated strictly:

from mogemma import GenerationConfig, SyncGemmaModel

config = GenerationConfig(
    model_path="gemma3-1b-it",
    device="gpu:0",
)
model = SyncGemmaModel(config)

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.2.0.tar.gz (179.8 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.2.0-cp313-cp313-manylinux_2_34_x86_64.whl (17.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

mogemma-0.2.0-cp313-cp313-manylinux_2_34_aarch64.whl (16.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

mogemma-0.2.0-cp313-cp313-macosx_11_0_arm64.whl (1.5 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

mogemma-0.2.0-cp313-cp313-macosx_10_13_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.13macOS 10.13+ x86-64

mogemma-0.2.0-cp312-cp312-manylinux_2_34_x86_64.whl (17.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

mogemma-0.2.0-cp312-cp312-manylinux_2_34_aarch64.whl (16.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

mogemma-0.2.0-cp312-cp312-macosx_11_0_arm64.whl (1.5 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

mogemma-0.2.0-cp312-cp312-macosx_10_13_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.12macOS 10.13+ x86-64

mogemma-0.2.0-cp311-cp311-manylinux_2_34_x86_64.whl (17.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

mogemma-0.2.0-cp311-cp311-manylinux_2_34_aarch64.whl (16.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

mogemma-0.2.0-cp311-cp311-macosx_11_0_arm64.whl (1.5 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

mogemma-0.2.0-cp311-cp311-macosx_10_9_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

mogemma-0.2.0-cp310-cp310-manylinux_2_34_x86_64.whl (17.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

mogemma-0.2.0-cp310-cp310-manylinux_2_34_aarch64.whl (16.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ ARM64

mogemma-0.2.0-cp310-cp310-macosx_11_0_arm64.whl (1.5 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

mogemma-0.2.0-cp310-cp310-macosx_10_9_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

File details

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

File metadata

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

File hashes

Hashes for mogemma-0.2.0.tar.gz
Algorithm Hash digest
SHA256 126aa69b85d1f16685137582a65d3f0b8f95ff20864b27aac66e1564fb194039
MD5 2d754f1629b39df532baaf9b43fdee4a
BLAKE2b-256 2ab84b238f6b2e02ec1d15075ccf320b04c3d9dcd22ce20a3ba7074b25e565a0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mogemma-0.2.0-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 058ae11539f40426f5aebb35641cf7e35ffe07d279748eb102beb291d32b5abb
MD5 73127ce04762ca418282034193127e3a
BLAKE2b-256 f444c01c19fa5729f69795805ea55ff6277c6ee7ec45b7749802749f71959c16

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mogemma-0.2.0-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 a759a1674d77a8857ee1aa6c15ef5250444be7816f428854d4460a03b2da04f1
MD5 a0a58492513af317d1cf3ca25c92015a
BLAKE2b-256 324f6e83e43d34ac44aa053d5aa10843c4d2a047b7e03616496389fff091b524

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mogemma-0.2.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5a733d101594ad639bff94594f7269f97edaebb7f75421697f820b91119df3a2
MD5 7e5fc31ae2800e58d706ee7e6aaa8fab
BLAKE2b-256 8e6110df9a3bd84c89369c030ee67681414282c6deb9ed86d808d7c27c3037f4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mogemma-0.2.0-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 158d8d27978c2bb8ab22de883a0eb407aa56f72c60e22e48fab94db1e82039c2
MD5 bd4fdeb0d47e757b2f3a6be4fa75f158
BLAKE2b-256 abbb35fdf0ac3dbde0183cb39ff95176ecba4ae64f9cbd6480ae38c9f13b25e0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mogemma-0.2.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 ed9739d2ad6179d4494ae27f5c372685a9271e88a93963c48c68429632976563
MD5 ac3998bdb22442ac197552e5f06fd3ee
BLAKE2b-256 139c689720f838c5e15da07bc4b47ea042e9414ca192233fcb7fc2338252031d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mogemma-0.2.0-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 b02514caa0e0b5613d32a93cfbabd4f431525eabf149cce973e7783fba1e5e4e
MD5 c24935843b1c9dc13e874ad756540b90
BLAKE2b-256 d27efdf86e23bef5e9728585bd162856fa9f726af9eda8aedc17f65a4d1a4478

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mogemma-0.2.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6aeef45fbc6df713fd06d8b3e2baf4a5b46e718358990a0554b44e5825f38924
MD5 7ccfdccf07b48b7fc174457bca852c2e
BLAKE2b-256 05c4b3ab5d2a7f2ad7b249625bd350e948d1638be83d14b347d7a6cced97944b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mogemma-0.2.0-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 dd2338830f39540f83f3739eecc0488e135bcb09803692fde7fb434b7a0ab4d1
MD5 d67c1a1ab515a5114c2bf4ad39f754f0
BLAKE2b-256 c0c8e8f6b39e270cce79de06f584c826775a0b82b92ca373e69f3f40dba5e165

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mogemma-0.2.0-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 072a4f107266fc3d6faa4f23db3c1ce63122c98fb078264fb733cfb3bb8ab07b
MD5 c7b42adb9dfa7aa7bdc94cc745d1f775
BLAKE2b-256 8fa8664cb10fe64a40ecd3df48a61b755c56c5eea1ccdd2a4b25001765c47f7c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mogemma-0.2.0-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 0e8d62f1d462b0af386be6cdf9142852029cd3b8c50133aa71bb0912d5de98cb
MD5 5f8e9a026b753187ca357039d161b9aa
BLAKE2b-256 e8fe30458322983624e7fb8e7086c87758f8c562dac69d3372f3b5121f7094f6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mogemma-0.2.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1d51a951f9e8230405ca45b8f30bc5f67eee59994bb18bf399470db3d8fb929f
MD5 75ccd674c4b4c310c83ba14abf6316b1
BLAKE2b-256 7bc7f27a7cd80b2fc8a1abec14384513efc135622148e92b89837cb7e723be03

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mogemma-0.2.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 37bbfc2c8b6c31f97ba1132cf7631c9af0dc55da63b35f6205e4f08a0e8e0e80
MD5 2ecbb6c3a90d21d383cfa0c68cab5dd8
BLAKE2b-256 c821c3df7bb646d9f8d2f1d511b4a060ad769694be1ab93092a9a29b70f08dcd

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mogemma-0.2.0-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 d72e3f281ed7fb6bcd7b04805b76f5fe0b2a423f9985639f036c30d57e5eee9b
MD5 0296a410b5c4676f4121bf81e854e36e
BLAKE2b-256 1606cbb22bc2f9f802c1f5b30204d8d320c1d93ed9ef337c1d732eb3191d3963

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mogemma-0.2.0-cp310-cp310-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 07d655d0d93c1caecdfa7d3e04286d2a1b9c063db04096a5e54026de5da2c11e
MD5 eb6be70dfc31fd6454360bd4d484b4f0
BLAKE2b-256 bc7ddc6dd3f264eddf77a636616cfe20ad9791de313e98ced86c7d7081794a3f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mogemma-0.2.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4e66d5d804a387fb669383d7856f540536c1b5a25da6036b5d5e0b30162d0cbb
MD5 ad08f4cde463ccb496bb8d982f188b76
BLAKE2b-256 d24dcfe6651dea2eb1aea64e41510b812334a763840b76f45a0dc1c6544c0d30

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for mogemma-0.2.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 301a5a9c2d1f2340e38135dc75389afd0b664e3c30145e22bb52f366a33e30b1
MD5 77f5078fa57d3f0e6cbe53e70f99ded2
BLAKE2b-256 57cc902fb1208e2b51bbf7644c03981dadd95b35e9cfdd37ac1d4cf6d5628dea

See more details on using hashes here.

Provenance

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