Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
tags:
|
| 4 |
+
- executorch
|
| 5 |
+
- xnnpack
|
| 6 |
+
- pte
|
| 7 |
+
- on-device
|
| 8 |
+
- sentence-similarity
|
| 9 |
+
- feature-extraction
|
| 10 |
+
base_model:
|
| 11 |
+
- sentence-transformers/all-MiniLM-L6-v2
|
| 12 |
+
---
|
| 13 |
+
# all-MiniLM-L6-v2 — ExecuTorch
|
| 14 |
+
|
| 15 |
+
Sentence embeddings: text in, one vector out. For search, clustering and retrieval that
|
| 16 |
+
never leaves the device.
|
| 17 |
+
|
| 18 |
+
- **Source**: sentence-transformers/all-MiniLM-L6-v2 — 22M parameters, 6 BERT layers, 384-dimensional output
|
| 19 |
+
- **License**: Apache-2.0
|
| 20 |
+
- **Input**: `input_ids` and `attention_mask`, both `[1, 256]` int64
|
| 21 |
+
- **Output**: `[1, 384]`
|
| 22 |
+
|
| 23 |
+
## The pooling is in the graph, on purpose
|
| 24 |
+
|
| 25 |
+
sentence-transformers keeps the recipe per model in `1_Pooling/config.json` and
|
| 26 |
+
`modules.json`, and the three small models on this shelf do not agree:
|
| 27 |
+
|
| 28 |
+
| | pooling | normalised |
|
| 29 |
+
|---|---|---|
|
| 30 |
+
| all-MiniLM-L6-v2 | mean | yes |
|
| 31 |
+
| bge-small-en-v1.5 | **CLS** | yes |
|
| 32 |
+
| paraphrase-multilingual-L12 | mean | **no** |
|
| 33 |
+
|
| 34 |
+
This one uses mean over the attention mask, then L2 normalise. Getting it wrong does not throw: mean-pooling BGE, or normalising
|
| 35 |
+
the multilingual one, gives vectors that look fine and rank wrong. So it is baked in rather
|
| 36 |
+
than left to the caller.
|
| 37 |
+
|
| 38 |
+
## Verification (Mac arm64, 2026-08-23)
|
| 39 |
+
|
| 40 |
+
| build | size | latency | worst cosine vs eager |
|
| 41 |
+
|---|---|---|---|
|
| 42 |
+
| XNNPACK fp32 | 90.4 MB | 14.4 ms | 1.000000 |
|
| 43 |
+
| XNNPACK fp16 | 45.3 MB | 26.3 ms | 0.999999 |
|
| 44 |
+
| Core ML fp32 | 45.4 MB | **2.0 ms** | 0.999984 |
|
| 45 |
+
|
| 46 |
+
Eager fp32 on the same input is 8.5 ms. Cosine is against the model run in eager through
|
| 47 |
+
its own documented pooling, over eight sentences including one in Japanese — not against
|
| 48 |
+
random token ids, which would tell you nothing.
|
| 49 |
+
|
| 50 |
+
**And that the vectors are useful**, which agreement alone cannot show:
|
| 51 |
+
|
| 52 |
+
```
|
| 53 |
+
0.588 a paraphrase vs -0.063 an unrelated sentence
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
Across languages — "機械学習のモデルを端末の上で動かす" against "On-device inference keeps
|
| 57 |
+
the data on the phone", with an unrelated sentence about the weather — this model scores
|
| 58 |
+
-0.047 against 0.125 — it does not, and should not.
|
| 59 |
+
|
| 60 |
+
## Not shipped
|
| 61 |
+
|
| 62 |
+
**int8** does not export. PT2E quantization fails with `IndexError: tensors used as indices
|
| 63 |
+
must be long, int, byte or bool tensors`, reaching the embedding lookup's index tensor. All
|
| 64 |
+
three of these models fail the same way.
|
| 65 |
+
|
| 66 |
+
## Worth knowing about the speed
|
| 67 |
+
|
| 68 |
+
XNNPACK fp32 is **slower than PyTorch eager** here (14.4 ms against 8.5), and fp16
|
| 69 |
+
is slower again while halving the file. Core ML is the one that pays: 2.0 ms, roughly
|
| 70 |
+
4.2x eager, at half the size. If this is going on an Apple device, take the Core ML
|
| 71 |
+
build.
|
| 72 |
+
|
| 73 |
+
## Conversion
|
| 74 |
+
|
| 75 |
+
```bash
|
| 76 |
+
python convert/export_embed.py all_minilm_l6
|
| 77 |
+
python convert/check_embed.py all_minilm_l6
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
Sequence length is fixed at 256; the attention mask makes padding harmless for mean pooling,
|
| 81 |
+
and chunking anything longer is the caller's job.
|
| 82 |
+
|
| 83 |
+
(conversion scripts: [executorch-models](https://github.com/john-rocky/executorch-models))
|