electroglyph commited on
Commit
10d7d7b
·
verified ·
1 Parent(s): f65b79b

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -33,3 +33,12 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ onnx/model.onnx_data filter=lfs diff=lfs merge=lfs -text
37
+ onnx/model_fp16.onnx_data filter=lfs diff=lfs merge=lfs -text
38
+ onnx/model_q4.onnx_data filter=lfs diff=lfs merge=lfs -text
39
+ onnx/model_q4f16.onnx_data filter=lfs diff=lfs merge=lfs -text
40
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
41
+ onnx/model_quantized.onnx_data filter=lfs diff=lfs merge=lfs -text
42
+ onnx/model_no_gather_q4.onnx_data filter=lfs diff=lfs merge=lfs -text
43
+ mteb_results_by_task.png filter=lfs diff=lfs merge=lfs -text
44
+ mteb_total_scores.png filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: gemma
3
+ base_model:
4
+ - google/embeddinggemma-300m
5
+ pipeline_tag: sentence-similarity
6
+ library_name: transformers.js
7
+ tags:
8
+ - text-embeddings-inference
9
+ ---
10
+
11
+ # embeddinggemma-300m-ONNX-uint8
12
+
13
+ This is based on https://huggingface.co/onnx-community/embeddinggemma-300m-ONNX/blob/main/onnx/model_quantized.onnx, but it outputs a uint8 tensor instead of an f32 one.
14
+
15
+ This model is compatible with Qdrant, but I'm not sure what other vector DBs it's compatible with.
16
+
17
+ For calibration data I used my own multilingual dataset of around 1.5m tokens: https://github.com/electroglyph/dataset_build
18
+
19
+ I ran all 1.5m tokens through the model and logged the highest/lowest values seen. I found a range of: -0.19112960994243622 to 0.22116543352603912
20
+
21
+ So I hacked on the sentence_embedding output of the ONNX model and added QuantizeLinear node based on the range of -0.22116543352603912 to 0.22116543352603912 to keep it symmetric. It would be cool if Qdrant let me specify my own zero point for a little more accuracy, but symmetric will have to do.
22
+
23
+ # Benchmarks
24
+
25
+ For benchmarking with MTEB I dequantize the uint8 output to the f32 that MTEB expects.
26
+
27
+ These retrieval benchmarks are a little wild. All the benchmarks used the `task: search result` query format. I have no idea why this model benchmarks better than the base model on most retrieval tasks, but I'll take it.
28
+
29
+ ![mteb retrieval results](.\mteb_results_by_task.png)
30
+
31
+ ![mteb totals](.\mteb_total_scores.png)
32
+
33
+ # Benchmark example code
34
+
35
+ ```python
36
+ import mteb
37
+ from mteb.encoder_interface import PromptType
38
+ import numpy as np
39
+ import onnxruntime as rt
40
+ from transformers import AutoTokenizer
41
+
42
+ class CustomModel:
43
+ def __init__(self) -> None:
44
+ self.tokenizer = AutoTokenizer.from_pretrained("C:/LLM/embeddinggemma-300m-ONNX-uint8")
45
+ self.session = rt.InferenceSession("C:/LLM/embeddinggemma-300m-ONNX-uint8/onnx/model.onnx", providers=["CPUExecutionProvider"])
46
+ self.scale = 0.22116543352603912 / 127.0
47
+
48
+ def dequantize(self, quantized: list | np.ndarray, scale: float) -> np.ndarray:
49
+ quantized = np.array(quantized)
50
+ dequant = (quantized.astype(np.float32) - 128) * scale
51
+ if dequant.ndim == 3 and dequant.shape[0] == 1:
52
+ return np.squeeze(dequant, axis=0)
53
+ return dequant
54
+
55
+ def encode(
56
+ self,
57
+ sentences: list[str],
58
+ task_name: str,
59
+ prompt_type: PromptType | None = None,
60
+ **kwargs,
61
+ ) -> np.ndarray:
62
+ if prompt_type == PromptType.query:
63
+ sentences = [f"task: search result | query: {s}" for s in sentences]
64
+ inputs = self.tokenizer(sentences, padding=True, truncation=True, return_tensors="np")
65
+ q = self.session.run(["sentence_embedding"], dict(inputs))
66
+ return self.dequantize(q, self.scale)
67
+
68
+
69
+ model = CustomModel()
70
+ benchmark = mteb.get_benchmark("NanoBEIR")
71
+ evaluation = mteb.MTEB(tasks=benchmark)
72
+ results = evaluation.run(model, corpus_chunk_size=128)
73
+ for r in results:
74
+ print(r)
75
+
76
+ ```
77
+
78
+ # FastEmbed usage
79
+
80
+ You should be able to use this as a custom model with no pooling and no normalization. The sentence_embedding output is ready to use.
added_tokens.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ {
2
+ "<image_soft_token>": 262144
3
+ }
config.json ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_sliding_window_pattern": 6,
3
+ "architectures": [
4
+ "Gemma3TextModel"
5
+ ],
6
+ "attention_bias": false,
7
+ "attention_dropout": 0.0,
8
+ "attn_logit_softcapping": null,
9
+ "bos_token_id": 2,
10
+ "dtype": "float32",
11
+ "eos_token_id": 1,
12
+ "final_logit_softcapping": null,
13
+ "head_dim": 256,
14
+ "hidden_activation": "gelu_pytorch_tanh",
15
+ "hidden_size": 768,
16
+ "initializer_range": 0.02,
17
+ "intermediate_size": 1152,
18
+ "layer_types": [
19
+ "sliding_attention",
20
+ "sliding_attention",
21
+ "sliding_attention",
22
+ "sliding_attention",
23
+ "sliding_attention",
24
+ "full_attention",
25
+ "sliding_attention",
26
+ "sliding_attention",
27
+ "sliding_attention",
28
+ "sliding_attention",
29
+ "sliding_attention",
30
+ "full_attention",
31
+ "sliding_attention",
32
+ "sliding_attention",
33
+ "sliding_attention",
34
+ "sliding_attention",
35
+ "sliding_attention",
36
+ "full_attention",
37
+ "sliding_attention",
38
+ "sliding_attention",
39
+ "sliding_attention",
40
+ "sliding_attention",
41
+ "sliding_attention",
42
+ "full_attention"
43
+ ],
44
+ "max_position_embeddings": 2048,
45
+ "model_type": "gemma3_text",
46
+ "num_attention_heads": 3,
47
+ "num_hidden_layers": 24,
48
+ "num_key_value_heads": 1,
49
+ "pad_token_id": 0,
50
+ "query_pre_attn_scalar": 256,
51
+ "rms_norm_eps": 1e-06,
52
+ "rope_local_base_freq": 10000.0,
53
+ "rope_scaling": null,
54
+ "rope_theta": 1000000.0,
55
+ "sliding_window": 512,
56
+ "transformers_version": "4.57.0.dev0",
57
+ "use_bidirectional_attention": true,
58
+ "use_cache": true,
59
+ "vocab_size": 262144,
60
+ "transformers.js_config": {
61
+ "use_external_data_format": {
62
+ "model.onnx": 1,
63
+ "model_fp16.onnx": 1,
64
+ "model_quantized.onnx": 1,
65
+ "model_q4.onnx": 1,
66
+ "model_q4f16.onnx": 1,
67
+ "model_no_gather_q4.onnx": 1
68
+ },
69
+ "kv_cache_dtype": false
70
+ }
71
+ }
generation_config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "cache_implementation": "hybrid",
3
+ "do_sample": true,
4
+ "top_k": 64,
5
+ "top_p": 0.95,
6
+ "transformers_version": "4.57.0.dev0"
7
+ }
mteb_results_by_task.png ADDED

Git LFS Details

  • SHA256: 4a177733abf37e9ee8d54d90c8684beb22a2b998784c4165376ed20c148ccc52
  • Pointer size: 131 Bytes
  • Size of remote file: 382 kB
mteb_total_scores.png ADDED

Git LFS Details

  • SHA256: 604180ae18228e7a9050248aec35e197918dfe7189167edda251655df2d4eb43
  • Pointer size: 131 Bytes
  • Size of remote file: 221 kB
onnx/model.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:21585443cf1ee0e87ba306ba9b1b97761d0aa3666f96947f8e65123dfee06688
3
+ size 309435349
special_tokens_map.json ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "boi_token": "<start_of_image>",
3
+ "bos_token": {
4
+ "content": "<bos>",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false
9
+ },
10
+ "eoi_token": "<end_of_image>",
11
+ "eos_token": {
12
+ "content": "<eos>",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false
17
+ },
18
+ "image_token": "<image_soft_token>",
19
+ "pad_token": {
20
+ "content": "<pad>",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false
25
+ },
26
+ "unk_token": {
27
+ "content": "<unk>",
28
+ "lstrip": false,
29
+ "normalized": false,
30
+ "rstrip": false,
31
+ "single_word": false
32
+ }
33
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4dda02faaf32bc91031dc8c88457ac272b00c1016cc679757d1c441b248b9c47
3
+ size 20323312
tokenizer.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1299c11d7cf632ef3b4e11937501358ada021bbdf7c47638d13c0ee982f2e79c
3
+ size 4689074
tokenizer_config.json ADDED
The diff for this file is too large to render. See raw diff