Download tt-model.yaml from changh95/embeddinggemma-2: direct link, hf CLI and curl.
- Browser
- Download file 27.2 kB
-
https://huggingface.co/changh95/embeddinggemma-2/resolve/main/tt-model.yaml
- Command line
-
hf download hf://changh95/embeddinggemma-2/tt-model.yaml
-
curl -L -o tt-model.yaml https://huggingface.co/changh95/embeddinggemma-2/resolve/main/tt-model.yaml
27.2 kB
| # SPDX-License-Identifier: Apache-2.0 | |
| # tt-model-manager container manifest (schema 5.1): google/embeddinggemma-2 multimodal embeddings (text incl. code, | |
| # images, video, audio -> one 768-d space, Matryoshka 512 / 256 / 128) on one Tenstorrent Blackhole p150. The | |
| # published README.md is GENERATED from the `card:` block below by `tt-model package`. | |
| # | |
| # v1: tt-nn engines for every stage (text, vision, audio); gates and benchmarks in OPT_REPORT.md. | |
| # | |
| # Run EVERY tt-model command FROM THIS DIRECTORY: extra_code[].root resolves against the process CWD; --out must point | |
| # OUTSIDE this directory (package deletes <out>/<name> first). | |
| # ~/.local/share/uv/tools/tt-model/bin/python -c "from tt_kernel.container_manifest import load_container_manifest as L; L('tt-model.yaml', check_sources=True)" | |
| # sg docker -c "tt-model package --container tt-model.yaml --out <workspace>/build" | |
| # (serve + smoke + stop under the device lock: code/scripts/container_smoke.sh <staged dir> 20000) | |
| # tt-model push <staged dir> --publish # HF_TOKEN from the environment only | |
| schema: "5.1" | |
| repo: changh95/embeddinggemma-2 | |
| name: embeddinggemma-2 # docker image / container / cache names must be lowercase | |
| # A POINTER, never baked into the image and never redistributed: `serve` / `pull --with-weights` download exactly | |
| # these files at this commit into the host HF cache (mounted at /hf). The repository is public and ungated. | |
| weights: | |
| repo: google/embeddinggemma-2 | |
| revision: f9972ac22e696a105c482202646979e33e4b5a1e | |
| allow_patterns: [model.safetensors, config.json, tokenizer.json, tokenizer_config.json, tokenizer.model, chat_template.jinja, preprocessor_config.json, processor_config.json, config_sentence_transformers.json, sentence_bert_config.json, modules.json, 1_Pooling/config.json, 2_Normalize/config.json, README.md] # 1.52 GB | |
| kind: tt-dit-server # the model's own FastAPI app under uvicorn (its /v1/embeddings is OpenAI-compatible) | |
| arch: blackhole | |
| source: | |
| # tt-metal main 44d6650 (v0.80.0-dev20261006) WITH patches/tt-metal-eth-dispatch.patch and | |
| # patches/tt-metal-reshape-rm-sys1419.patch applied: a dirty tree, packaged as-is. torch 2.11.0 pin read from it. | |
| tt_metal: /home/ubuntu/experiments/tt-models/tt-metal | |
| # Schema minimum (>= 1 path relative to the tt-metal tree). The port imports nothing from tt-metal's models/. | |
| code: | |
| - models/common/lightweightmodule.py | |
| # The port itself: copied over /opt/tt-metal/<path> in the image (PYTHONPATH=/opt/tt-metal); code/ on the Hub | |
| # becomes exactly this set at every push. Never a tt-metal build input (pyproject.toml lives at the repo root). | |
| extra_code: | |
| - root: code | |
| paths: | |
| - tt_embgemma # API, server, smoke test, ttnn engines, reference, front ends, tests, samples, licences | |
| - scripts/bench.py # latency / throughput per stage and bucket | |
| - scripts/device_server_smoke.sh # serving gate on a host checkout (server on the device + smoke test) | |
| - scripts/container_smoke.sh # serve, smoke, always stop | |
| - conftest.py | |
| - PYTHON.md | |
| ubuntu: "22.04" | |
| python: "3.12" | |
| runtime: | |
| app: tt_embgemma.server.app:app | |
| mesh_shape_env: TT_MESH_SHAPE | |
| # On top of the kind defaults (fastapi, uvicorn, pydantic>=2, pillow) and the auto-pinned torch==2.11.0+cpu: every | |
| # third-party module on the serve path, pinned to the versions the host tests ran with. scipy: polyphase audio | |
| # resampling (optional; linear interpolation without it). soundfile: FLAC / OGG / MP3 audio (optional; WAV and raw | |
| # float32 PCM are decoded by the standard library). PyAV is NOT installed: videos are sent as decoded frames. | |
| packages: | |
| - "numpy>=1.24.4,<2" | |
| - safetensors==0.8.0 | |
| - huggingface_hub==1.16.1 # the snapshot of the pinned weights | |
| - tokenizers==0.22.2 # the model's SentencePiece-BPE tokenizer.json | |
| - orjson==3.12.0 # fast exact float32 JSON of the embeddings | |
| - scipy==1.17.1 | |
| - soundfile==0.14.0 | |
| - fastapi==0.142.2 | |
| - uvicorn==0.54.0 | |
| serve: | |
| port: 20000 | |
| hardware: p150 | |
| mesh_device: P150 | |
| env: | |
| TT_WEIGHTS_REVISION: "f9972ac22e696a105c482202646979e33e4b5a1e" # == weights.revision | |
| TT_METAL_VISIBLE_DEVICES: "0" | |
| TT_DEVICE_ID: "0" | |
| # the weights repo is public and ungated: never send a token (serve mounts the host HF cache at /hf) | |
| HF_HUB_DISABLE_IMPLICIT_TOKEN: "1" | |
| EMBGEMMA_DISPATCH: "eth" # 12 x 10 compute grid | |
| EMBGEMMA_NUM_CQS: "1" | |
| # the configuration, read once when the server starts (a bad value refuses to start); SERVING.md lists all | |
| EMBGEMMA_MODALITIES: "text,image,video,audio" | |
| EMBGEMMA_TEXT_ENGINE: "ttnn" # engine of every stage: ttnn | cpu (float32 reference, no device) | |
| EMBGEMMA_VISION_ATTN: "sdpa" # one-image vision launches: sdpa (ttnn) | mk (the mk_vattn kernel) | |
| EMBGEMMA_MAX_BATCH: "32" # sequences per text launch | |
| EMBGEMMA_MAX_INPUTS: "2048" # inputs per HTTP request | |
| EMBGEMMA_MAX_IMAGES: "64" # images + video frames per HTTP request (host memory) | |
| EMBGEMMA_MAX_SEQ_LEN: "2048" # tokens per input (text + media soft tokens) | |
| EMBGEMMA_IMAGE_TOKENS_MAX: "280" # largest per-image budget compiled (70 / 140 / 280; 560 / 1120 opt-in) | |
| EMBGEMMA_VIDEO_MAX_FRAMES: "32" | |
| EMBGEMMA_AUDIO_MAX_SECONDS: "30" | |
| EMBGEMMA_WEIGHTS: "bf16" | |
| EMBGEMMA_FIDELITY: "HiFi4" | |
| EMBGEMMA_BATCH_WINDOW_MS: "2" | |
| EMBGEMMA_QUEUE_DEPTH: "256" | |
| EMBGEMMA_QUEUE_TIMEOUT_S: "120" | |
| # Build-time assertions, run INSIDE the finished image as uid 1000, without a device or weights. | |
| verify: | |
| - "assert 'single_chip_arch_1cq_no_dispatch_s' in open('/opt/tt-metal/tt_metal/impl/dispatch/topology.cpp').read()" | |
| - "assert 'dual_kernel_min_dram_dest_page_bytes' in open('/opt/tt-metal/ttnn/cpp/ttnn/operations/data_movement/reshape_view/device/reshape_rm_program_factory.cpp').read()" | |
| - "from tt_embgemma.ttaw.device import eth_dispatch_patch_present as p; assert p(), 'ttaw does not see the ETH patch'" | |
| - "import sys, tt_embgemma.server.app as a; assert a.app and 'ttnn' not in sys.modules and 'torch' not in sys.modules, 'the server module must import without ttnn / torch'" | |
| - "from tt_embgemma.server.app import load_config; c = load_config({'EMBGEMMA_MAX_BATCH': '32', 'EMBGEMMA_MAX_SEQ_LEN': '2048', 'EMBGEMMA_IMAGE_TOKENS_MAX': '280', 'EMBGEMMA_DISPATCH': 'eth'}); assert (c.max_batch, c.max_seq_len, c.image_tokens_max, c.dispatch, c.vision_buckets) == (32, 2048, 280, 'eth', (864, 1440, 2592)), c" | |
| - "from tt_embgemma.server.app import load_config as L\nfor bad in ({'EMBGEMMA_TEXT_ENGINE': 'mk'}, {'EMBGEMMA_VISION_ENGINE': 'cpu'}, {'EMBGEMMA_WEIGHTS': 'bfp8'}, {'EMBGEMMA_MAX_IMAGES': '0'}, {'EMBGEMMA_MAX_BATCH': '64'}, {'EMBGEMMA_MAX_SEQ_LEN': '9000'}, {'EMBGEMMA_IMAGE_TOKENS_MAX': '300'}, {'EMBGEMMA_MODALITIES': 'text,smell'}, {'EMBGEMMA_DISPATCH': 'pcie'}, {'TT_MESH_SHAPE': '1x2'}):\n try:\n L(bad)\n except RuntimeError:\n continue\n raise AssertionError(bad)" | |
| - "from tt_embgemma import model_spec as S; assert S.audio_tokens_for_samples(16000) == 25 and S.audio_tokens_for_samples(10**7) == 750" | |
| - "from PIL import Image; from tt_embgemma.preprocess.image import to_rgb_pil; assert to_rgb_pil(Image.new('RGBA', (4, 4), (0, 0, 0, 0))).getpixel((0, 0)) == (255, 255, 255), 'transparency must composite onto white'" | |
| - "from pathlib import Path; d = Path('/opt/tt-metal/tt_embgemma/licenses'); assert 'Apache License' in (d / 'LICENSE-APACHE-2.0.txt').read_text() and 'embeddinggemma-2' in (d / 'NOTICE.md').read_text()" | |
| - "import json; from pathlib import Path; r = json.loads(Path('/opt/tt-metal/tt_embgemma/samples/smoke_reference.json').read_text()); assert len(r['texts']) >= 6 and len(r['text_embeddings'][0]) == 768" | |
| - "from pathlib import Path; assert all(Path('/opt/tt-metal', p).is_file() for p in ('tt_embgemma/server/smoke_test.py', 'tt_embgemma/server/client.py', 'tt_embgemma/samples/transparent.png', 'scripts/container_smoke.sh', 'scripts/bench.py', 'PYTHON.md'))" | |
| - "import numpy; assert int(numpy.__version__.split('.')[0]) < 2, numpy.__version__" | |
| - "import safetensors, huggingface_hub, fastapi, uvicorn, tokenizers, orjson, scipy, soundfile" | |
| - "import torch; assert torch.__version__.startswith('2.11.0'), torch.__version__" | |
| - "import ttnn; assert all(hasattr(ttnn, a) for a in ('DispatchCoreConfig', 'begin_trace_capture', 'end_trace_capture', 'execute_trace', 'release_trace', 'copy_host_to_device_tensor', 'gather', 'conv2d'))" | |
| card: | |
| attribution: >- | |
| Derived from [google/embeddinggemma-2](https://huggingface.co/google/embeddinggemma-2) (Google DeepMind), with | |
| unmodified weights downloaded from that repository. Official code: the `embedding_gemma2` model of Hugging Face | |
| [transformers](https://github.com/huggingface/transformers) and [sentence-transformers](https://github.com/UKPLab/sentence-transformers). | |
| This is a third-party port, not affiliated with or endorsed by Google. See the original model card for training | |
| details, the evaluation and the Gemma Prohibited Use Policy. | |
| description: >- | |
| EmbeddingGemma 2 maps text (100+ languages and code), images, video, audio and interleaved mixtures of them into | |
| one 768-dimensional embedding space for retrieval, classification, clustering and similarity; vectors can be | |
| truncated to 512, 256 or 128 dimensions (Matryoshka) and re-normalized. A 24-layer bidirectional Gemma-4 encoder | |
| (hidden size 512, per-layer embeddings, 270 M parameters with the token table) reads the text tokens and the soft | |
| tokens of a 16-layer vision tower (images at 70 to 1120 tokens, video at one frame per second) and a 12-layer | |
| conformer audio tower (25 tokens per second), and the token outputs are mean-pooled and L2-normalized, exactly | |
| `SentenceTransformer.encode`. On the device every stage runs in tt-nn operations with one trace per shape bucket; | |
| the sequences of a batch are packed end to end (no padding) with block-diagonal attention. Tokenization, image | |
| resizing, the log-mel front end, the token-table lookup and the final normalization run on the host CPU and are | |
| bit-exact with the official processors. The server speaks the OpenAI embeddings API for text and a native API for | |
| every modality, and merges concurrent requests into shared device launches. | |
| intended_use: >- | |
| Embedding text, code, images, video and audio on one Tenstorrent p150 for multimodal semantic search, | |
| retrieval-augmented generation, classification, clustering and similarity, from single low-latency queries to | |
| batches of documents. | |
| prerequisites: | | |
| - About 1.6 GB of free disk for the weights (fetched once into the Hugging Face cache), plus the container image | |
| - Time for the first start: it compiles about 2,200 device kernels (18 min measured on a busy 8-core host, less on | |
| an idle one); they are cached, and later starts are ready in about 1 minute | |
| quickstart: | | |
| On the port `tt serve` reported: | |
| ```bash | |
| curl -s localhost:20000/v1/embeddings -H 'Content-Type: application/json' \ | |
| -d '{"input": ["What causes the northern lights?"], "prompt_name": "SearchQuery", "dimensions": 256}' | head -c 300 | |
| IMG=$(base64 -w0 photo.jpg) | |
| curl -s localhost:20000/embed -H 'Content-Type: application/json' \ | |
| -d "{\"inputs\": [{\"image\": \"$IMG\"}, {\"text\": \"a photo of a cat\"}]}" | head -c 300 | |
| ``` | |
| usage: | | |
| `POST /v1/embeddings` is OpenAI-compatible for text (`input`, `model`, `encoding_format` `float` | `base64`, | |
| `dimensions` 768 | 512 | 256 | 128, `user`; extensions `prompt_name` / `prompt`); `POST /embed` takes every | |
| modality; `POST /similarity` scores `targets` against `source`; `GET /health`, `GET /info` (engines, device, | |
| configuration, limits, the 20 task prompts), `GET /v1/models`. | |
| The model is trained with task prefixes for text: queries `task: search result | query: ...` | |
| (`prompt_name: SearchQuery`), documents `title: none | text: ...` (`Document`), and `Classification`, | |
| `Clustering`, `SentenceSimilarity`, `QuestionAnswering`, `FactChecking`, `CodeRetrieval`, ... (`GET /info` | |
| lists all). Images, video and audio are sent without a prefix. | |
| | request field (`/embed`) | values | default | meaning | | |
| | --- | --- | --- | --- | | |
| | `inputs` | list of up to `EMBGEMMA_MAX_INPUTS` inputs: a string, or an object with `text`, `image` (base64 file), `audio` (base64 WAV, or `{"array": [...], "sampling_rate": sr}`), `video` (`{"frames": [base64 images], "fps": f}`) keys (lists allowed; key order = sequence order), or `{"content": [{"type": "text", "text"}, {"type": "image", "image"}, ...]}` | required | one embedding per input; placeholders `<\|image\|>` / `<\|audio\|>` / `<\|video\|>` in the text place the media | | |
| | `prompt_name` / `prompt` | a task name / any text | none | task prefix | | |
| | `dimensions` | 768, 512, 256, 128 | 768 | Matryoshka truncation, re-normalized | | |
| | `normalize` | `true`, `false` | `true` | `false`: the model's normalized 768-d output truncated without re-normalization | | |
| | `output` | `sentence`, `tokens` | `sentence` | `tokens`: one 768-d vector per token | | |
| | `max_length`, `truncate` | 3 .. `EMBGEMMA_MAX_SEQ_LEN`; `right`, `error` | max; `right` | text-only inputs longer than `max_length` keep their first tokens (+ `<eos>`); media inputs are never cut (400) | | |
| | `image_tokens` | 70, 140, 280 (560, 1120 when enabled) | 280 | soft tokens per image (resolution) | | |
| | `video_fps`, `video_max_frames`, `video_tokens` | > 0; 1 .. 32; 70 .. 280 | 1, 32, 140 | frame sampling and per-frame budget | | |
| | `encoding_format` | `float`, `base64` | `float` | `base64`: little-endian float32 | | |
| - Errors: 400 with the reason, 413 too many inputs / body above `EMBGEMMA_MAX_BODY_MB`, 422 unknown fields, 429 | |
| when `EMBGEMMA_QUEUE_DEPTH` launches wait, 503 if start-up failed or while shutting down, 500 on a device | |
| failure. The port accepts connections once the server is ready (`tt serve` waits for that). | |
| - Images with transparency (RGBA, LA, palette) are composited onto white, like the official processor. | |
| - A Python API with the same options (`tt_embgemma.api.EmbeddingGemma2.embed`) is described in | |
| [`code/PYTHON.md`](code/PYTHON.md); it needs a tt-metal build with the two patches in [`patches/`](patches/). | |
| ### Configuration | |
| The server compiles and traces its device programs when it starts: the first start compiles about 2,200 device | |
| kernels (18 min measured on a busy 8-core host), which are cached, so later starts take about 1 minute. Change | |
| these with environment variables in the container's launch command. `GET /info` reports them. Batch size, sequence length, image size and audio length are | |
| not configuration: every request runs at its real size on the compiled buckets. | |
| | item | environment variable | values | default | | |
| | --- | --- | --- | --- | | |
| | modalities loaded | `EMBGEMMA_MODALITIES` | subset of `text,image,video,audio` (text always) | all | | |
| | engine of every stage (text, vision, audio) | `EMBGEMMA_TEXT_ENGINE` | `ttnn`, `cpu` (float32 reference, no device) | `ttnn` | | |
| | vision attention of one-image launches | `EMBGEMMA_VISION_ATTN` | `sdpa` (tt-nn), `mk` (custom attention kernel) | `sdpa` | | |
| | sequences per text launch | `EMBGEMMA_MAX_BATCH` | 1 .. 32 | 32 | | |
| | inputs per request | `EMBGEMMA_MAX_INPUTS` | 1 .. 65536 | 2048 | | |
| | images + video frames per request | `EMBGEMMA_MAX_IMAGES` | 1 .. 4096 (~8 MB of host memory each) | 64 | | |
| | tokens per input | `EMBGEMMA_MAX_SEQ_LEN` | 32 .. 8192 | 2048 | | |
| | largest image budget | `EMBGEMMA_IMAGE_TOKENS_MAX` | 70, 140, 280, 560, 1120 | 280 | | |
| | video frames | `EMBGEMMA_VIDEO_MAX_FRAMES` | 1 .. 64 | 32 | | |
| | audio length cap | `EMBGEMMA_AUDIO_MAX_SECONDS` | 0.5 .. 30 | 30 | | |
| | buckets | `EMBGEMMA_TEXT_BUCKETS`, `EMBGEMMA_LONG_BUCKETS`, `EMBGEMMA_AUDIO_BUCKETS` | multiples of 32 (128 for audio frames) | `32,...,2048`; `1024,2048`; `512,1024,2048,3072` | | |
| | weights, matmul fidelity | `EMBGEMMA_WEIGHTS`, `EMBGEMMA_FIDELITY` | `bf16`; `HiFi4`, `HiFi3`, `HiFi2` | `bf16`, `HiFi4` | | |
| | default text prompt of `/v1/embeddings` | `EMBGEMMA_DEFAULT_PROMPT` | a prompt name | none | | |
| | merging window, queue | `EMBGEMMA_BATCH_WINDOW_MS`, `EMBGEMMA_QUEUE_DEPTH`, `EMBGEMMA_QUEUE_TIMEOUT_S` | ms, launches, s | 2, 256, 120 | | |
| ### Example output | |
|  | |
| Cross-modal retrieval, served by this package's container on a p150. Eight images drawn by code for this demo | |
| (above the columns) and eight text queries are each embedded in one `POST /embed` request (the images at the | |
| default 280 soft tokens, the queries with `"prompt_name": "SearchQuery"`); the cells are cosine similarities of the | |
| 768-d vectors. Every query finds its own image (8 of 8): matched pairs score 0.760 on average, the other pairs | |
| 0.582. | |
|  | |
| The same with eight audio clips: four synthetic speech clips made with | |
| [changh95/Qwen3-TTS](https://huggingface.co/changh95/Qwen3-TTS), queried with their transcripts in their own | |
| language, and four synthetic sounds, queried with a description. Seven of eight queries find their clip; "a clock | |
| ticking" scores the white-noise clip above the clicks. | |
| | clip | what it is | query | best match (cosine) | | |
| | --- | --- | --- | --- | | |
| | <audio controls src="https://huggingface.co/changh95/embeddinggemma-2/resolve/main/media/demo_audio_speech_en.wav"></audio> [WAV](media/demo_audio_speech_en.wav) | synthetic speech, English | Hello! I'm Ryan, one of the nine preset voices. Every word you hear was generated on a single accelerator card, faster than real time. | this clip (0.908) | | |
| | <audio controls src="https://huggingface.co/changh95/embeddinggemma-2/resolve/main/media/demo_audio_speech_zh.wav"></audio> [WAV](media/demo_audio_speech_zh.wav) | synthetic speech, Chinese | ไฝ ๅฅฝ๏ผๆๆฏ่่ๅฎใ่ฟๆฎต่ฏญ้ณๆฏๅจไธๅผ ๅ ้ๅกไธๅฎๆถ็ๆ็ใ | this clip (0.773; next: the English speech clip, 0.751) | | |
| | <audio controls src="https://huggingface.co/changh95/embeddinggemma-2/resolve/main/media/demo_audio_speech_ko.wav"></audio> [WAV](media/demo_audio_speech_ko.wav) | synthetic speech, Korean | ์๋ ํ์ธ์, ์ ๋ ์ํฌ์์. ์ด ๋ชฉ์๋ฆฌ๋ ํ ์คํ ๋ ํธ ์นด๋์์ ์ค์๊ฐ์ผ๋ก ๋ง๋ค์ด์ก์ด์. | this clip (0.851) | | |
| | <audio controls src="https://huggingface.co/changh95/embeddinggemma-2/resolve/main/media/demo_audio_clone_en.wav"></audio> [WAV](media/demo_audio_clone_en.wav) | synthetic speech, English (a cloned voice) | This voice was cloned from a seven second reference clip, and now it reads a sentence it has never heard before. | this clip (0.898) | | |
| | <audio controls src="https://huggingface.co/changh95/embeddinggemma-2/resolve/main/media/demo_audio_tone.wav"></audio> [WAV](media/demo_audio_tone.wav) | 880 Hz sine, 2 s | a steady high-pitched beep | this clip (0.726) | | |
| | <audio controls src="https://huggingface.co/changh95/embeddinggemma-2/resolve/main/media/demo_audio_siren.wav"></audio> [WAV](media/demo_audio_siren.wav) | a harmonic tone sweeping 650-1450 Hz, 5 s | a wailing siren | this clip (0.725; next: the beep, 0.706) | | |
| | <audio controls src="https://huggingface.co/changh95/embeddinggemma-2/resolve/main/media/demo_audio_ticking.wav"></audio> [WAV](media/demo_audio_ticking.wav) | clicks, two per second, 5 s | a clock ticking | **the white-noise clip** (0.689; this clip 0.651) | | |
| | <audio controls src="https://huggingface.co/changh95/embeddinggemma-2/resolve/main/media/demo_audio_noise.wav"></audio> [WAV](media/demo_audio_noise.wav) | Gaussian white noise, 2 s | white noise | this clip (0.678) | | |
| With `"dimensions"` 512, 256 or 128 in the same requests (Matryoshka truncation), every image query keeps its | |
| best match at every size; the audio queries keep 7 of 8 at 512 and 6 of 8 at 256 and 128, where "a wailing siren" | |
| moves to the beep. The official sentence-transformers model in float32 on the CPU picks the same best match for | |
| every query, including the ticking clip's miss; no score differs from it by more than 0.002 for the images and | |
| 0.0035 for the audio clips, and the lowest embedding cosine to float32 is 0.99996 for the images and 0.9996 for | |
| the audio clips (the click track; 0.9998 or more for the others). One text query sent alone to `/v1/embeddings` | |
| took 16.8 ms on loopback (p50 of 20 requests; 10.2 ms in the server), one image 108 ms (102 ms in the server, | |
| including the image decoding and resizing on the host) and the 9.8 s English speech clip 92 ms (79 ms), on a | |
| shared 8-core host. The exact requests, scores and timings are in [`media/demos.json`](media/demos.json); | |
| [`media/make_demo.py`](media/make_demo.py) draws the images, synthesises the sounds and repeats the requests | |
| against a running server. | |
| performance: | | |
| Agreement with the official sentence-transformers float32 code on the CPU (same weights and inputs; embedding | |
| cosine to float32), next to the official model run in bfloat16: | |
| | eval | this package | official bfloat16 | | |
| | --- | --- | --- | | |
| | Text, 40 inputs of 2 to 2,047 tokens (task prompts, code, 6 languages, emoji): lowest / mean 1 - cosine | 0.99992 / 4.1e-5 | 0.99991 / 3.8e-5 | | |
| | Retrieval, 8 queries x 24 documents: top-1 agreement, largest similarity change | 8/8, 0.0025 | 8/8, 0.0020 | | |
| | Matryoshka 512 / 256 / 128 dimensions: retrieval top-1 agreement | 8/8 at every size | 8/8 | | |
| | Images, 8 at 70 / 140 / 280 tokens: lowest / mean 1 - cosine | 0.99972 / 9.1e-5 | 0.99980 / 7.1e-5 (4 images) | | |
| | Image vs caption similarity: top-1, largest change | 6/6, 0.0010 | 3/3, 0.0011 (measured on 3 images) | | |
| | Audio, 10 clips of 0.1 to 52.8 s: lowest / mean 1 - cosine | 0.99991 / 3.7e-5 | 0.99981 / 5.5e-5 (5 clips) | | |
| | Audio vs transcript similarity: top-1, largest change | 9/9, 0.0018 | 5/5, 0.0015 (measured on 5 clips) | | |
| | Video (2 clips) / interleaved text + images (2): lowest cosine | 0.99991 / 0.99991 | 0.99997 / 0.99992 | | |
| | Same input alone vs packed with other inputs in one device launch, lowest cosine (300 random packings; every packed result stays within the float32 gate, lowest 0.99985) | 0.99979 | 0.99988 (padded batch) | | |
| | 100 repeated runs per modality | bitwise identical | - | | |
| | speed (warm, traced; engine call incl. host packing and readback) | ms | | |
| | --- | --- | | |
| | text, 1 input of 16 / 32 / 128 / 512 tokens | 5.6 / 5.5 / 8.0 / 12.9 | | |
| | text, 1 input of 1,024 / 2,048 tokens | 28.7 / 68.1 | | |
| | text, 32 inputs x 16 tokens / 32 x 64 / 8 x 256 | 12.4 (2,570 inputs/s) / 41.2 (777/s) / 36.8 (218/s) | | |
| | image encoder, 70 / 140 / 280 tokens | 15.5 / 28.0 / 61.5 | | |
| | 4 images x 70 tokens in one launch | 41.1 | | |
| | audio encoder, 1 / 5 / 10 / 30 s | 16.7 / 16.5 / 25.1 / 60.4 | | |
| | served `/v1/embeddings`, one query, client round trip on loopback (p50) | 15.7 | | |
| Measured with `code/scripts/bench.py` and `code/tt_embgemma/server/smoke_test.py` on one p150 with ETH dispatch | |
| (12 x 10 grid); an image or audio request adds the text pass over its soft tokens and host preprocessing (image | |
| resize ~30 ms for a 1600 x 900 photo, log-mel ~60 ms for 30 s). | |
| limitations: | | |
| - The official pipeline never truncates; this package caps an input at `EMBGEMMA_MAX_SEQ_LEN` tokens (2,048 by | |
| default, up to the model's 8,192 context). Audio is truncated at 30 s per clip like the official feature | |
| extractor; video keeps at most 32 frames (1 frame per second by default). | |
| - Video files need PyAV, which the container does not include: send decoded frames (`{"frames": [...], "fps"}`). | |
| - Image budgets 560 and 1120 tokens are opt-in (`EMBGEMMA_IMAGE_TOKENS_MAX`): they cost 2.6 and 7.4 TFLOP per | |
| image and large attention buffers. | |
| - Precision: bfloat16 weights and activations with float32 accumulation and float32 softmax; embeddings differ | |
| from the float32 model about as much as the official bfloat16 run does (table above). A result also depends | |
| slightly on what else shares its device launch (lowest cosine 0.99979 between an input alone and packed with | |
| others), like the official bfloat16 model's padding (0.99988). | |
| - Up to 32 sequences share one text launch; larger and concurrent requests are split / merged automatically. One | |
| p150 only (ETH dispatch). | |
| - The text path in this version is the tt-nn engine: the 24-layer text encoder runs as ~700 traced tt-nn | |
| operations, so a short query is bound by operation count, not by arithmetic. Measured (warm, traced): 5.6 ms | |
| for one input of 16 tokens, 5.5 ms at 32, 8.0 ms at 128, 12.9 ms at 512, 28.7 ms at 1,024 and 68.1 ms at | |
| 2,048 tokens; 12.4 ms for 32 inputs of 16 tokens. A single-program text encoder (megakernel) is planned for a | |
| later version; it is not part of this one. | |
| - Every other stage also runs in tt-nn operations under traces; a custom attention kernel for one-image vision | |
| launches is opt-in (`EMBGEMMA_VISION_ATTN=mk`, 7 % faster at 280 tokens). | |
| licensing: | | |
| - Weights (not redistributed here; `tt serve` downloads them at this commit), Apache-2.0 per the model card: | |
| [google/embeddinggemma-2](https://huggingface.co/google/embeddinggemma-2) `f9972ac2`. Use is subject to the | |
| [Gemma Prohibited Use Policy](https://ai.google.dev/gemma/prohibited_use_policy) referenced by the card. | |
| Notices: [`code/tt_embgemma/licenses/NOTICE.md`](code/tt_embgemma/licenses/NOTICE.md). | |
| - This package is a derivative work: the inference code is written anew (tokenizer framing, image / audio / video | |
| front ends, the three encoders, pooling and normalization follow the official code's behaviour), and the | |
| weights are loaded unmodified. | |
| - Port, server and scripts (`code/`) and the tt-metal patches in [`patches/`](patches/): Apache-2.0. | |
| - The demo in `media/` (figures, audio clips, `demos.json`, `make_demo.py`): Apache-2.0. Its images and sounds | |
| were generated by code for this package, its speech clips are synthetic speech made with | |
| [changh95/Qwen3-TTS](https://huggingface.co/changh95/Qwen3-TTS) (Qwen3-TTS weights, Apache-2.0; no recording of | |
| a person), and its queries were written for this package. Attributions: | |
| [`media/ATTRIBUTION.md`](media/ATTRIBUTION.md). | |
| related: | | |
| - [changh95/all-MiniLM-L6-v2](https://huggingface.co/changh95/all-MiniLM-L6-v2): sentence embeddings on p150. | |
| - [changh95/DepthPro2](https://huggingface.co/changh95/DepthPro2): metric depth on p150. | |
| license: | |
| id: apache-2.0 | |
| pipeline_tag: feature-extraction | |
| base_model: | |
| - google/embeddinggemma-2 | |