embeddinggemma-2 / SERVING.md
changh95's picture
tt-model push embeddinggemma-2 (container)
5c33f00 verified
|
Raw History Blame Contribute Delete
6.66 kB

Serving EmbeddingGemma 2 on a Tenstorrent p150

changh95/embeddinggemma-2 is a tt-model v5.1 container package: the image runs tt_embgemma.server.app:app under uvicorn on one p150 (ETH dispatch, 12 x 10 Tensix grid). The weights are a pointer (google/embeddinggemma-2 at f9972ac22e696a105c482202646979e33e4b5a1e, public, ungated), downloaded into the host's Hugging Face cache on the first serve.

tt serve changh95/embeddinggemma-2                 # or: tt-model serve changh95/embeddinggemma-2 --port 20000
curl -s localhost:20000/health
curl -s localhost:20000/v1/embeddings -H 'Content-Type: application/json' \
  -d '{"input": "What causes the northern lights?", "prompt_name": "SearchQuery"}'
tt model stop changh95/embeddinggemma-2

Start-up compiles and traces every shape bucket (text 32 .. 2048 tokens, long single sequences 1024 / 2048, vision 864 / 1440 / 2592 patches, audio 512 .. 3072 mel frames). The first start compiles ~2,200 device kernels: 18 min measured on a busy 8-core host (load average 16), less on an idle one; they are cached under the container's cache mount, and a restart is ready in about 1-1.5 minutes (52-80 s measured). The port accepts connections only once the server is ready (uvicorn runs the warm-up before it listens; tt serve waits for that). Stopping the container during the warm-up waits for the warm-up to finish: on a first start that can exceed the 120 s stop grace, after which the container is killed and the chip reset by tt-model.

Routes

route body answer
POST /v1/embeddings OpenAI: input (string or list of strings), model, encoding_format (float / base64), dimensions (768 / 512 / 256 / 128), user; extensions prompt_name, prompt {"object": "list", "data": [{"object": "embedding", "index", "embedding"}], "model", "usage"}; header X-Timing-Ms
POST /embed inputs (strings or objects with text / image / audio / video keys or a content list), prompt_name, prompt, dimensions, normalize, output (sentence / tokens), max_length, truncate (right / error), image_tokens, video_fps, video_max_frames, video_tokens, encoding_format {"embeddings", "n_tokens", "truncated", "dim", "output", "normalize", "timing_ms"}
POST /similarity source, targets (inputs as in /embed), prompt_name (source), target_prompt_name, + the /embed options {"scores"}
GET /info engines and buckets, device (dispatch, grid), configuration, limits, the task prompts, batcher counters
GET /health, /v1/health 200: status ok, or error with the reason if start-up failed
GET /v1/models, GET / model list, routes

Media encodings: images as base64 files (PNG, JPEG, WebP, ...; at most 64 MP); audio as base64 WAV (PCM 8/16/24/32 or float, any rate and channel count: mixed to mono and resampled to 16 kHz), other formats when soundfile can read them, {"array": [...], "sampling_rate": sr}, or raw pcm_f32le with "format" + "sampling_rate"; video as {"frames": [base64 images], "fps": f} (a container file needs PyAV, not in the image). Images and frames with transparency (RGBA, LA, palette with a transparent color) are composited onto white, like the official processor. At most EMBGEMMA_MAX_IMAGES images + video frames per request (each costs ~8 MB of host memory while it waits).

Errors: 400 invalid input (reason in detail), 413 too many inputs / images / body too large, 422 schema (unknown field on the native routes, wrong type), 429 queue full (Retry-After: 1), 503 start-up failed / shutting down / queue timeout, 500 inference failed: ....

How a request runs

  1. The handler's worker thread renders each input exactly like sentence-transformers (task prompt + content; media placeholders expanded to <boi> n x <|image|> <eoi>, <boa> k x <|audio|> <eoa>, one block per video frame), tokenizes it (tokenizer.json), resizes / patches images (bicubic antialias, bit-exact with the official processor), computes log-mel features of audio (numpy, bit-exact) and samples video frames.
  2. The inputs go to the device thread (server/batcher.py) in parts of at most EMBGEMMA_MAX_BATCH (32); parts of concurrent requests are merged.
  3. Device: images / frames are packed into vision launches (block-diagonal attention, one trace per patch bucket); each audio clip runs the conformer (one trace per frame bucket); the soft tokens are spliced into the token embeddings (host table lookup); the text sequences are packed end to end into one text launch per token bucket (block-diagonal attention through cu_window_seqlens; a sequence longer than 513 tokens runs alone with the sliding-window band mask) and the device returns per-sequence sums of the token embeddings.
  4. The host divides by the token counts, truncates to dimensions, L2-normalizes and encodes the response.

Configuration (server start)

variable values default
EMBGEMMA_MODALITIES subset of text,image,video,audio all
EMBGEMMA_TEXT_ENGINE engine of every stage (text, vision, audio): ttnn, cpu (float32 reference, no device) ttnn
EMBGEMMA_VISION_ATTN sdpa (tt-nn), mk (custom attention kernel for one-image launches up to 2,592 patches) sdpa
EMBGEMMA_MAX_BATCH 1 .. 32 32
EMBGEMMA_MAX_INPUTS 1 .. 65536 2048
EMBGEMMA_MAX_IMAGES images + video frames per request, 1 .. 4096 64
EMBGEMMA_MAX_SEQ_LEN 32 .. 8192 2048
EMBGEMMA_TEXT_BUCKETS multiples of 32 32,64,128,256,512,1024,2048
EMBGEMMA_LONG_BUCKETS multiples of 32, >= 544, reaching MAX_SEQ_LEN 1024,2048
EMBGEMMA_IMAGE_TOKENS_MAX 70, 140, 280, 560, 1120 280
EMBGEMMA_VIDEO_MAX_FRAMES 1 .. 64 32
EMBGEMMA_AUDIO_MAX_SECONDS 0.5 .. 30 30
EMBGEMMA_AUDIO_BUCKETS multiples of 128 mel frames <= 3072 512,1024,2048,3072
EMBGEMMA_WEIGHTS bf16 (bfp8 weights fail the accuracy gates and are not offered) bf16
EMBGEMMA_FIDELITY HiFi4, HiFi3, HiFi2 HiFi4
EMBGEMMA_TRACE, EMBGEMMA_WARMUP 0 / 1 1, 1
EMBGEMMA_DEFAULT_PROMPT a prompt name for /v1/embeddings requests without one (checked at start) none
EMBGEMMA_BATCH_WINDOW_MS, EMBGEMMA_QUEUE_DEPTH, EMBGEMMA_QUEUE_TIMEOUT_S, EMBGEMMA_MAX_BODY_MB 2, 256, 120, 64
EMBGEMMA_DISPATCH, EMBGEMMA_TRACE_REGION, EMBGEMMA_L1_SMALL, TT_DEVICE_ID eth, 256 MB, 32 KB, 0
EMBGEMMA_WEIGHTS_DIR a local snapshot directory the HF cache snapshot