Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -12,95 +12,85 @@ base_model:
|
|
| 12 |
---
|
| 13 |
# multilingual-e5-base — ExecuTorch
|
| 14 |
|
| 15 |
-
Multilingual
|
| 16 |
-
768-dimensional vector out,
|
| 17 |
-
|
| 18 |
|
| 19 |
-
- **Source**: intfloat/multilingual-e5-base —
|
| 20 |
-
|
| 21 |
-
- **License**: MIT
|
| 22 |
- **Input**: `input_ids` and `attention_mask`, both `[1, 256]` int64
|
| 23 |
-
- **Output**: `[1, 768]`, mean-pooled
|
| 24 |
|
| 25 |
-
##
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|---|---|---|
|
| 32 |
-
| all-MiniLM-L6-v2 | mean | yes |
|
| 33 |
-
| all-MiniLM-L12-v2 | mean | yes |
|
| 34 |
-
| bge-small-en-v1.5 | **CLS** | yes |
|
| 35 |
-
| **multilingual-e5-base** | **mean** | **yes** |
|
| 36 |
-
| multilingual-e5-large | mean | yes |
|
| 37 |
-
| paraphrase-multilingual-L12 | mean | **no** |
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
it does
|
| 42 |
-
|
| 43 |
-
**The prefix is not.** E5 is trained with `"query: "` in front of a search query and
|
| 44 |
-
`"passage: "` in front of a document, and it expects them at inference:
|
| 45 |
-
|
| 46 |
-
```
|
| 47 |
-
query: query: how do I keep data on the phone?
|
| 48 |
-
passage: passage: On-device inference keeps the data on the phone.
|
| 49 |
-
```
|
| 50 |
-
|
| 51 |
-
That is text, so it happens before tokenisation and the `.pte` never sees it as anything
|
| 52 |
-
but tokens. Leaving it out does not throw and does not look wrong — it returns a
|
| 53 |
-
plausible vector that retrieves worse. The conversion repo's checker applies it, so the
|
| 54 |
-
numbers below are for the recipe as the model intends it.
|
| 55 |
|
| 56 |
## Verification
|
| 57 |
|
| 58 |
-
| build | file | size |
|
| 59 |
-
|---|---|---|---|---|
|
| 60 |
-
|
|
| 61 |
-
|
|
| 62 |
-
| Core ML
|
| 63 |
-
|
| 64 |
-
Mac arm64, median of 10, one 256-token sequence — a reference point for relative
|
| 65 |
-
not a device number.
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
``
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
```
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
|
| 105 |
torch.export -> to_edge_transform_and_lower(partitioner) -> .pte
|
| 106 |
(conversion scripts: [executorch-models](https://github.com/john-rocky/executorch-models))
|
|
|
|
| 12 |
---
|
| 13 |
# multilingual-e5-base — ExecuTorch
|
| 14 |
|
| 15 |
+
Multilingual E5, base-sized — one index over 100 languages. Text in, one
|
| 16 |
+
768-dimensional vector out, for search and retrieval that never leaves the
|
| 17 |
+
device.
|
| 18 |
|
| 19 |
+
- **Source**: intfloat/multilingual-e5-base — 12 layers, 768 dimensions, 250,002 vocabulary
|
| 20 |
+
- **License**: mit
|
|
|
|
| 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 |
+
## 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* | backend takes | worst cosine vs eager | retrieval budget |
|
| 42 |
+
|---|---|---|---|---|---|---|
|
| 43 |
+
| fp32 | `embed_multilingual_e5_base_xnnpack_fp32.pte` | 1110.0 | 40.0 | 77.3% | 1.000000 | 0% |
|
| 44 |
+
| fp16 | `embed_multilingual_e5_base_xnnpack_fp16.pte` | 555.2 | 65.1 | 66.7% | 0.999999 | 6% |
|
| 45 |
+
| Core ML (fp16, iOS) | `embed_multilingual_e5_base_coreml_all.pte` | 555.7 | 6.9 | 100.0% | 0.999994 | 19% |
|
| 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 |
+
47.9 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 |
+
## The attention is eager, and that is the faster export
|
| 58 |
+
|
| 59 |
+
`F.scaled_dot_product_attention` does not survive export as one operation. The edge
|
| 60 |
+
dialect lowers it through `_safe_softmax`, whose guard against a row with no unmasked
|
| 61 |
+
key at all leaves **eleven operations XNNPACK cannot take, in every attention block** —
|
| 62 |
+
`scalar_tensor`, `where`, `mul.Scalar`, `logical_not`, `eq`, `full_like`, `any.dim`.
|
| 63 |
+
Each one cuts the subgraph in two. The count is exact and does not vary by family:
|
| 64 |
+
measured across this shelf, from a 4-layer cross-encoder to a 28-layer causal reranker,
|
| 65 |
+
it is 11 per block every time.
|
| 66 |
+
|
| 67 |
+
The guard is emitted whether or not it can ever fire, and here it cannot. It triggers
|
| 68 |
+
only on `-inf`, which reaches the graph only because the sdpa path hands `F.sdpa` a
|
| 69 |
+
**boolean** mask for PyTorch to fill; `attn_implementation="eager"` masks with
|
| 70 |
+
`torch.finfo(dtype).min`, a large finite number, and never produces one. So the two
|
| 71 |
+
arms differ only on rows that have no unmasked key — sdpa zeroes them, eager gives them
|
| 72 |
+
a uniform row — and those are padding rows, which the pooling discards and every real
|
| 73 |
+
query row masks out. Measured with all but eight positions masked, as adversarial as
|
| 74 |
+
this shape gets, the two graphs agree to 1.4e-07.
|
| 75 |
+
|
| 76 |
+
XNNPACK fp32 goes from **61.9% to 77.3%** delegated.
|
| 77 |
+
|
| 78 |
+
## Not shipped: int8
|
| 79 |
+
|
| 80 |
+
`embed_multilingual_e5_base_xnnpack_int8.pte` is **855.5 MB** against fp16's 555.2 MB. Dynamic int8 quantises the
|
| 81 |
+
linear weights and leaves the token embedding table in fp32, and here that table is
|
| 82 |
+
768 MB of the 1110.0 MB model — **69%**. The size a build comes out at is
|
| 83 |
+
`0.5 + 1.5 x (table share)` times the fp16 build; at 69% that is
|
| 84 |
+
1.54, so there was never a smaller file to be had.
|
| 85 |
+
|
| 86 |
+
It is withheld on the number that decides. Ranking the eight test sentences against
|
| 87 |
+
each other, this build moves a pair score by at most **0.0057** while the
|
| 88 |
+
closest fp32 decision — the gap between the document a query retrieves and the
|
| 89 |
+
runner-up — is **0.0022**. That is **255%** of
|
| 90 |
+
the room available, against a bar of 50%.
|
| 91 |
+
|
| 92 |
+
Correlation reads 0.997142 for this build, which no correlation gate
|
| 93 |
+
would stop.
|
| 94 |
|
| 95 |
torch.export -> to_edge_transform_and_lower(partitioner) -> .pte
|
| 96 |
(conversion scripts: [executorch-models](https://github.com/john-rocky/executorch-models))
|