DawgOG commited on
Commit
3f98e93
·
verified ·
1 Parent(s): aab1891

Sync model card from GitHub e467f0a

Browse files
Files changed (1) hide show
  1. README.md +73 -0
README.md ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ base_model: google/embeddinggemma-2
4
+ pipeline_tag: feature-extraction
5
+ tags:
6
+ - rust
7
+ - cuda
8
+ - embeddings
9
+ - sentence-similarity
10
+ - multimodal
11
+ - gemma
12
+ - embeddinggemma
13
+ ---
14
+
15
+ # EmbeddingGemma 2 in Rust (`egemma2`)
16
+
17
+ [![Buy Me a Coffee](https://img.shields.io/badge/Buy%20Me%20a%20Coffee-dawgog-FFDD00?logo=buymeacoffee&logoColor=black)](https://buymeacoffee.com/dawgog)
18
+ [![GitHub](https://img.shields.io/badge/GitHub-embeddinggemma2--rust-181717?logo=github)](https://github.com/Dalailalama/embeddinggemma2-rust)
19
+
20
+ An unofficial, from-scratch Rust implementation of
21
+ [`google/embeddinggemma-2`](https://huggingface.co/google/embeddinggemma-2): text, images, audio and
22
+ video embedded into one 768-d space (Matryoshka cuts to 512 / 256 / 128), on the CPU or on an NVIDIA
23
+ GPU (fp32, TF32 or bf16 with tensor-core flash attention). No Python or PyTorch at runtime; the CUDA
24
+ libraries are loaded dynamically, so one binary runs with or without a GPU.
25
+
26
+ This repository holds the documentation and the prebuilt binaries. The **weights are Google's**: this
27
+ runtime reads the original checkpoint unchanged, so download it from
28
+ [`google/embeddinggemma-2`](https://huggingface.co/google/embeddinggemma-2) (Apache-2.0, not gated).
29
+ Source code, tests and the full write-up: **<https://github.com/Dalailalama/embeddinggemma2-rust>**.
30
+ Not affiliated with or endorsed by Google.
31
+
32
+ ## Quick start
33
+
34
+ ```bash
35
+ # 1. the runtime: a binary from this repo's `releases/` folder or GitHub Releases, or build it
36
+ cargo install --git https://github.com/Dalailalama/embeddinggemma2-rust
37
+ # 2. the weights
38
+ hf download google/embeddinggemma-2 --local-dir models/embeddinggemma-2
39
+ # 3. embed (the model directory defaults to models/embeddinggemma-2)
40
+ egemma2 embed --prompt-name SearchQuery --text "which planet is known as the red planet"
41
+ egemma2 --device cuda --bf16 embed --image photo.jpg --audio clip.wav --video talk.mp4
42
+ egemma2 similarity --query "red planet" --doc "Mars is the fourth planet" --doc "Venus is the hottest planet"
43
+ ```
44
+
45
+ ## Same answers as the original
46
+
47
+ Checked number for number against the PyTorch reference (transformers + sentence-transformers) on 90
48
+ checks covering text, images, audio, video and prompts: float32 embeddings differ by at most 1e-6.
49
+ bf16 mode stays within cosine 0.99996 of float32, about 8x closer than PyTorch's own bf16 mode.
50
+
51
+ ## Speed (RTX A3000 laptop GPU, warm medians)
52
+
53
+ | Workload | PyTorch bf16 | **Rust bf16** | |
54
+ |---|---|---|---|
55
+ | short query (17 tokens) | 49.4 ms | **2.5 ms** | 19x |
56
+ | long document (2,208 tokens) | 136 ms | **50.0 ms** | 2.7x |
57
+ | batch of 64 short documents | 117 ms | **53.6 ms** | 2.2x |
58
+ | image 641x479 | 151 ms | **59.2 ms** | 2.55x |
59
+ | audio 9.3 s | 96.7 ms | **19.1 ms** | 5.1x |
60
+
61
+ On the CPU (i7-12850HX) Rust is 1.2 - 1.9x faster than PyTorch, starts in 0.9 s instead of 11 s and
62
+ uses about 4x less memory. fp32/TF32 numbers and methodology are in the
63
+ [GitHub README](https://github.com/Dalailalama/embeddinggemma2-rust#speed-rust-vs-the-python-original).
64
+
65
+ ## Support
66
+
67
+ If this saves you time, you can [buy me a coffee](https://buymeacoffee.com/dawgog). New releases are
68
+ published on [GitHub](https://github.com/Dalailalama/embeddinggemma2-rust/releases) and mirrored here.
69
+
70
+ ## License
71
+
72
+ The code is Apache-2.0. The model weights are Google's, distributed under Apache-2.0. "Gemma" and
73
+ "EmbeddingGemma" are trademarks of Google LLC.