--- license: apache-2.0 base_model: google/embeddinggemma-2 tags: - embedding - multimodal - sentence-transformers - quantization - int8 - compressed-tensors - vllm pipeline_tag: feature-extraction library_name: transformers --- # embeddinggemma-2 — INT8 (W8A8) quantization for vLLM An INT8 quantization of [`google/embeddinggemma-2`](https://huggingface.co/google/embeddinggemma-2) in the **compressed-tensors `int-quantized`** format, built to be served directly by [vLLM](https://docs.vllm.ai) as an embedding/pooling model. - **Weights:** INT8, symmetric, **per-output-channel** (strategy `channel`), static - **Activations:** INT8, symmetric, **dynamic per-token** (strategy `token`, `dynamic: true`) - **Targets:** all `Linear` modules — language model, vision tower, and audio tower - **Checkpoint:** `model.safetensors` 897 MB (vs 1,489 MB bf16 for the base model) - **License:** Apache-2.0 (same as the base model) ## Why this exists Other INT8 packages of this architecture ship in custom packed formats that only their own loader can read. This checkpoint uses the standard [compressed-tensors](https://github.com/vllm-project/compressed-tensors) format that vLLM understands natively — no custom runtime, no patched loader. vLLM has upstream support for the base architecture (`EmbeddingGemma2Model`) since v0.33, so this repo is meant to be paired with a stock `vllm/vllm-openai` image. ## Quantization method Post-training **weight quantization with dynamic activation quantization**, done directly in PyTorch (see [`quantize.py`](quantize.py) in this repo): ```python scale = (weight.abs().amax(dim=1, keepdim=True) / 127.5).clamp_(min=1e-10) q = torch.clamp(torch.round(weight / scale), -128, 127).to(torch.int8) ``` Per-output-channel symmetric INT8 for each `nn.Linear`, with `weight_scale` stored as fp32 of shape `[out_features, 1]`, and `quantization_config` written into `config.json`: ```json { "quant_method": "compressed-tensors", "format": "int-quantized", "config_groups": { "group_0": { "targets": ["Linear"], "weights": { "num_bits": 8, "type": "int", "strategy": "channel", "symmetric": true, "dynamic": false }, "input_activations":{ "num_bits": 8, "type": "int", "strategy": "token", "symmetric": true, "dynamic": true } } } } ``` **No calibration corpus is required**: because activation quantization is dynamic (per-token, computed at runtime), the checkpoint only needs the weight scales. That makes the quantization deterministic, cheap (~10 s on CPU), and free of dataset-induced bias — at the cost of not being activation-aware (no AWQ / SmoothQuant-style error correction). ## Accuracy vs. the bf16 base model Measured by embedding the same texts with the bf16 and INT8 checkpoints served in vLLM and comparing cosine similarity (mean-pooled 768-d embeddings): | sample set | mean cosine | min cosine | |---|---|---| | single sentence | 0.9965 | — | | 4-text probe set | 0.9988 | 0.9981 | Retrieval ordering is preserved exactly. Example (query → 4 candidate docs), bf16 vs INT8: ``` bf16: 1.0000 / 0.9001 / 0.6053 / 0.5828 int8: 0.9993 / 0.9035 / 0.6040 / 0.5884 ``` ## Serving with vLLM vLLM selects the `CompressedTensorsW8A8Int8` scheme for this config (int8 weights **and** int8 activations; on Ada/Ampere+ it resolves to a CUTLASS int8 scaled-MM kernel). Minimum compute capability for the scheme is sm_75. ```bash docker run -d --gpus all -p 8100:8000 \ -v $PWD/models:/models \ vllm/vllm-openai:v0.34.0 \ /models/embeddinggemma-2-int8 \ --runner pooling \ --convert embed \ --served-model-name embeddinggemma-2-int8 \ --max-model-len 8192 ``` Verified on an NVIDIA RTX 2000 Ada Generation (sm_89) with `vllm/vllm-openai:v0.34.0`: ``` Selected CutlassInt8ScaledMMLinearKernel for CompressedTensorsW8A8Int8 ``` Then: ```bash curl -s http://localhost:8100/v1/embeddings -H 'Content-Type: application/json' \ -d '{"model":"embeddinggemma-2-int8","input":"A man is playing a guitar on stage."}' ``` Matryoshka truncation is supported via `dimensions` (128 / 256 / 512 / 768) on the pooling params, same as the base model. ## Model details (inherited from the base model) - Output embeddings: 768-dimensional, mean-pooled, L2-normalized; Matryoshka-capable - Modalities: text, image, audio, video - 24 language layers, hidden 512 → projected to 768; 262,144 context - Recommended prompt prefixes (see `config_sentence_transformers.json`): - query: `task: search result | query: ` - document: `title: none | text: ` ## Notes & limitations - The vision and audio towers are INT8-quantized as well as the language model. - Weight scales are plain min/max per output channel — no activation-aware smoothing, so this is a conservative W8A8 rather than a task-tuned PTQ. If you need maximum accuracy, serve the bf16 base model; the weight saving here is ~590 MB, which on a 16 GB card is mostly a bandwidth/footprint win rather than a capacity unlock. - **Serving is validated under vLLM.** Loading this checkpoint through plain `transformers` / `sentence-transformers` (via the compressed-tensors decompression path) has not been tested here. - The quantization script in this repo runs on CPU with no calibration data and produces a byte-identical checkpoint from the bf16 base model. ## Source Quantized from `google/embeddinggemma-2` (Apache-2.0). All model weights and derivations retain the Apache-2.0 license.