embeddinggemma-2-phi-lattice-v2
4-bit phi-lattice v2 build of google/embeddinggemma-2 (740M multimodal / 270M text backbone across 1,376 tensors), supporting both standard plug-and-play SentenceTransformer (bfloat16 safetensors) and compressed 4-bit in-memory execution via phi_loader.py.
1. Repository Layout & Memory Footprint
embeddinggemma-2-phi-lattice-v2/
├── embeddinggemma2_phi_v2_packed_4bit.pt # 590.3 MiB 4-bit packed archive (all 1,376/1,376 tensors)
├── phi_loader.py # Standalone loader (low_vram_4bit & unrolled_bf16, full or text_only)
├── model.safetensors # 1,419.9 MiB unrolled BF16 fallback for SentenceTransformer
├── 1_Pooling/ & 2_Normalize/ # SentenceTransformer mean-pooling & L2-normalization modules
├── config.json & tokenizer files
└── README.md
| Deployment Mode | Disk / Download Size | RAM / GPU VRAM Footprint | Savings vs Full BF16 |
|---|---|---|---|
Full Multimodal model.safetensors (BF16 fallback, 740M) | 1,419.9 MiB (1,488.9 MB) | 1,419.8 MiB | 1.00x |
Full Multimodal low_vram_4bit (embeddinggemma2_phi_v2_packed_4bit.pt) | 590.3 MiB (619.0 MB) | 589.7 MiB | 2.41x disk & VRAM |
Text-Only 270M low_vram_4bit (text_only=True) | 590.3 MiB (619.0 MB) | 326.0 MiB | 4.36x RAM/VRAM |
(Note: the 262k-vocabulary token table embed_tokens and all Matryoshka embedding_projection heads remain unquantized in bfloat16 to preserve exact MRL axis alignment across widths 768, 512, 256, and 128).
2. Public Benchmark: STSBenchmark (1,379 Pairs) & BEIR SciFact (300 Queries / 5,183 Papers)
Evaluated on the full STSBenchmark test split (Spearman rank correlation against human similarity scores) and the full BEIR SciFact scientific retrieval corpus (nDCG@10 across 5,183 scientific abstracts) at Matryoshka widths 768, 512, 256, and 128:
| Method | 4-bit Weight SQNR | Sparsity | STS Spearman 768d / 128d | SciFact nDCG@10 768d | SciFact nDCG@10 512d | SciFact nDCG@10 256d | SciFact nDCG@10 128d |
|---|---|---|---|---|---|---|---|
Baseline (BF16) | Reference | 0.00% | 0.8743 / 0.8682 | 0.8569 | 0.8515 | 0.8331 | 0.7943 |
Standard Uniform (4-bit) | 19.04 dB | 0.00% | 0.8718 / 0.8638 | 0.8366 | 0.8266 | 0.8079 | 0.7645 |
phi-lattice v1 (4-bit) | 18.63 dB | 7.71% | 0.8693 / 0.8629 | 0.8399 | 0.8389 | 0.8256 | 0.7787 |
phi-lattice v2 (This Repo) | 19.61 dB | 12.40% | 0.8668 / 0.8595 | 0.8388 | 0.8368 | 0.8136 | 0.7732 |
Embedding Cosine Agreement vs Baseline (BF16) (Full 740M Checkpoint)
| Method | Full-Model 4-bit SQNR | Sparsity | Cosine 768d | Cosine 512d | Cosine 256d | Cosine 128d | 12-Pair Recall@1 |
|---|---|---|---|---|---|---|---|
Baseline (BF16) | Reference | 0.00% | 1.0000 | 1.0000 | 1.0000 | 1.0000 | 1.000 |
Standard Uniform (4-bit) | 19.18 dB | 0.00% | 0.9819 | 0.9825 | 0.9842 | 0.9887 | 1.000 |
phi-lattice v1 (4-bit) | 19.28 dB | 22.41% | 0.9864 | 0.9868 | 0.9881 | 0.9911 | 1.000 |
phi-lattice v2 (This Repo) | 21.07 dB | 24.80% | 0.9867 | 0.9872 | 0.9884 | 0.9920 | 1.000 |
3. Quick Start & Loading Modes
Option A: Low-VRAM 4-Bit Mode via phi_loader.py (326.0 MiB text-only / 589.7 MiB full multimodal, skips 1.49 GB safetensors)
import importlib.util
import torch
import torch.nn.functional as F
from huggingface_hub import hf_hub_download
from transformers import AutoTokenizer
repo_id = "ununununununununununununununununununun/embeddinggemma-2-phi-lattice-v2"
device = "cuda" if torch.cuda.is_available() else "cpu"
loader_path = hf_hub_download(repo_id=repo_id, filename="phi_loader.py")
spec = importlib.util.spec_from_file_location("phi_loader", loader_path)
phi_loader = importlib.util.module_from_spec(spec)
spec.loader.exec_module(phi_loader)
# mode="low_vram_4bit" keeps all 478 quantized layers packed in 4-bit uint8 in memory:
# - text_only=True -> 326.0 MiB RAM/VRAM
# - text_only=False -> 589.7 MiB RAM/VRAM (full 740M with vision & audio towers)
model = phi_loader.load_embeddinggemma2_from_packed_4bit(
repo_id=repo_id,
mode="low_vram_4bit",
text_only=True,
device=device,
dtype=torch.bfloat16,
)
tokenizer = AutoTokenizer.from_pretrained(repo_id)
texts = [
"task: search result | query: What causes the northern lights?",
"title: none | text: Charged particles from the sun collide with gases in Earth's atmosphere.",
]
batch = tokenizer(texts, padding=True, truncation=True, return_tensors="pt").to(device)
with torch.no_grad():
hidden = model(**batch).last_hidden_state
mask = batch["attention_mask"].unsqueeze(-1).to(hidden.dtype)
embeddings = F.normalize((hidden * mask).sum(1) / mask.sum(1).clamp(min=1.0), p=2, dim=-1)
print("Cosine similarity:", float((embeddings[0] @ embeddings[1]).item()))
Option B: Standard Plug-and-Play SentenceTransformer (model.safetensors)
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("ununununununununununununununununununun/embeddinggemma-2-phi-lattice-v2")
query = model.encode("What causes the northern lights?", prompt_name="SearchQuery")
document = model.encode(
"Charged particles from the sun collide with gases in Earth's atmosphere.",
prompt_name="Document",
)
print(model.similarity(query, document))