Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
tags:
|
| 4 |
+
- executorch
|
| 5 |
+
- xnnpack
|
| 6 |
+
- pte
|
| 7 |
+
- on-device
|
| 8 |
+
- feature-extraction
|
| 9 |
+
- sentence-similarity
|
| 10 |
+
base_model:
|
| 11 |
+
- sentence-transformers/all-mpnet-base-v2
|
| 12 |
+
---
|
| 13 |
+
# all-mpnet-base-v2 — ExecuTorch
|
| 14 |
+
|
| 15 |
+
The most downloaded sentence-transformer there is. Text in, one
|
| 16 |
+
768-dimensional vector out, for search and retrieval that never leaves the
|
| 17 |
+
device.
|
| 18 |
+
|
| 19 |
+
- **Source**: sentence-transformers/all-mpnet-base-v2 — 12 layers, 768 dimensions, 30,527 vocabulary
|
| 20 |
+
- **License**: apache-2.0
|
| 21 |
+
- **Input**: `input_ids` and `attention_mask`, both `[1, 256]` int64
|
| 22 |
+
- **Output**: `[1, 768]`, mean-pooled and L2-normalised inside the graph
|
| 23 |
+
|
| 24 |
+
## The recipe is in the graph, and it was read off this repo
|
| 25 |
+
|
| 26 |
+
sentence-transformers stores it per model, and the shelf's seven embedding models do
|
| 27 |
+
not agree. This one pools **mean** and
|
| 28 |
+
**normalises**, read from
|
| 29 |
+
`1_Pooling/config.json` and `modules.json` rather than inferred from the family name.
|
| 30 |
+
Getting it wrong does not throw; it returns vectors that look fine and rank wrong.
|
| 31 |
+
|
| 32 |
+
## Verification
|
| 33 |
+
|
| 34 |
+
| build | file | size (MB) | Mac ms* | worst cosine vs eager | retrieval budget |
|
| 35 |
+
|---|---|---|---|---|---|
|
| 36 |
+
| fp32 | `embed_all_mpnet_xnnpack_fp32.pte` | 435.8 | 35.2 | 1.000000 | 0% |
|
| 37 |
+
| fp16 | `embed_all_mpnet_xnnpack_fp16.pte` | 218.1 | 56.2 | 1.000000 | 11% |
|
| 38 |
+
| Core ML (fp16, iOS) | `embed_all_mpnet_coreml_all.pte` | 220.2 | 6.2 | 0.999993 | 32% |
|
| 39 |
+
|
| 40 |
+
\*Mac arm64, median of 10, one 256-token sequence — a reference point for relative
|
| 41 |
+
cost, not a device number. Torch eager fp32 on the same machine is
|
| 42 |
+
37.0 ms.
|
| 43 |
+
|
| 44 |
+
Cosine is measured against the model run in eager through its own pooling, over eight
|
| 45 |
+
sentences. The last column is the one that decides: rank those eight against each
|
| 46 |
+
other, and ask whether this build's score error is smaller than the gap between the
|
| 47 |
+
document a query retrieves and the runner-up. Every shipped build keeps all eight
|
| 48 |
+
top-1 results.
|
| 49 |
+
|
| 50 |
+
## Not shipped: int8
|
| 51 |
+
|
| 52 |
+
`embed_all_mpnet_xnnpack_int8.pte` is **181.3 MB** — smaller than fp16's 218.1 MB, because the token embedding
|
| 53 |
+
table is only 94 MB of the 435.8 MB model (22%), leaving most of the
|
| 54 |
+
weight in linears for int8 to shrink.
|
| 55 |
+
|
| 56 |
+
It is withheld on the number that decides. Ranking the eight test sentences against
|
| 57 |
+
each other, this build moves a pair score by at most **0.0081** while the
|
| 58 |
+
closest fp32 decision — the gap between the document a query retrieves and the
|
| 59 |
+
runner-up — is **0.0026**. That is **316%** of
|
| 60 |
+
the room available, against a bar of 50%.
|
| 61 |
+
|
| 62 |
+
Correlation reads 0.998871 for this build, which no correlation gate
|
| 63 |
+
would stop.
|
| 64 |
+
|
| 65 |
+
torch.export -> to_edge_transform_and_lower(partitioner) -> .pte
|
| 66 |
+
(conversion scripts: [executorch-models](https://github.com/john-rocky/executorch-models))
|