Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
tags:
|
| 4 |
+
- executorch
|
| 5 |
+
- xnnpack
|
| 6 |
+
- pte
|
| 7 |
+
- on-device
|
| 8 |
+
- feature-extraction
|
| 9 |
+
- sentence-similarity
|
| 10 |
+
base_model:
|
| 11 |
+
- intfloat/multilingual-e5-small
|
| 12 |
+
---
|
| 13 |
+
# multilingual-e5-small — ExecuTorch
|
| 14 |
+
|
| 15 |
+
The smallest of the multilingual E5 family. Text in, one
|
| 16 |
+
384-dimensional vector out, for search and retrieval that never leaves the
|
| 17 |
+
device.
|
| 18 |
+
|
| 19 |
+
- **Source**: intfloat/multilingual-e5-small — 12 layers, 384 dimensions, 250,037 vocabulary
|
| 20 |
+
- **License**: mit
|
| 21 |
+
- **Input**: `input_ids` and `attention_mask`, both `[1, 256]` int64
|
| 22 |
+
- **Output**: `[1, 384]`, 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 |
+
## The prefix is not in the graph
|
| 33 |
+
|
| 34 |
+
This model is trained with `query: ` in front of the text and expects it at
|
| 35 |
+
inference. That happens before tokenisation, so the `.pte` never sees it as anything
|
| 36 |
+
but tokens — and leaving it out does not throw. It returns a plausible vector that
|
| 37 |
+
retrieves worse.
|
| 38 |
+
|
| 39 |
+
## Verification
|
| 40 |
+
|
| 41 |
+
| build | file | size (MB) | Mac ms* | worst cosine vs eager | retrieval budget |
|
| 42 |
+
|---|---|---|---|---|---|
|
| 43 |
+
| fp32 | `embed_multilingual_e5_small_xnnpack_fp32.pte` | 470.2 | 29.3 | 1.000000 | 0% |
|
| 44 |
+
| fp16 | `embed_multilingual_e5_small_xnnpack_fp16.pte` | 235.3 | 52.2 | 1.000000 | 1% |
|
| 45 |
+
| Core ML (fp16, iOS) | `embed_multilingual_e5_small_coreml_all.pte` | 235.5 | 4.3 | 0.999979 | 15% |
|
| 46 |
+
|
| 47 |
+
\*Mac arm64, median of 10, one 256-token sequence — a reference point for relative
|
| 48 |
+
cost, not a device number. Torch eager fp32 on the same machine is
|
| 49 |
+
18.0 ms.
|
| 50 |
+
|
| 51 |
+
Cosine is measured against the model run in eager through its own pooling, over eight
|
| 52 |
+
sentences. The last column is the one that decides: rank those eight against each
|
| 53 |
+
other, and ask whether this build's score error is smaller than the gap between the
|
| 54 |
+
document a query retrieves and the runner-up. Every shipped build keeps all eight
|
| 55 |
+
top-1 results.
|
| 56 |
+
|
| 57 |
+
## Not shipped: int8
|
| 58 |
+
|
| 59 |
+
`embed_multilingual_e5_small_xnnpack_int8.pte` is **406.7 MB** against fp16's 235.3 MB. Dynamic int8 quantises the
|
| 60 |
+
linear weights and leaves the token embedding table in fp32, and here that table is
|
| 61 |
+
384 MB of the 470.2 MB model — **82%**. The size a build comes out at is
|
| 62 |
+
`0.5 + 1.5 x (table share)` times the fp16 build; at 82% that is
|
| 63 |
+
1.73, so there was never a smaller file to be had.
|
| 64 |
+
|
| 65 |
+
It is withheld on the number that decides. Ranking the eight test sentences against
|
| 66 |
+
each other, this build moves a pair score by at most **0.0037** while the
|
| 67 |
+
closest fp32 decision — the gap between the document a query retrieves and the
|
| 68 |
+
runner-up — is **0.0105**. That is **35%** of
|
| 69 |
+
the room available, against a bar of 50%.
|
| 70 |
+
|
| 71 |
+
Correlation reads 0.999568 for this build, which no correlation gate
|
| 72 |
+
would stop.
|
| 73 |
+
|
| 74 |
+
torch.export -> to_edge_transform_and_lower(partitioner) -> .pte
|
| 75 |
+
(conversion scripts: [executorch-models](https://github.com/john-rocky/executorch-models))
|