Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -12,83 +12,71 @@ base_model:
|
|
| 12 |
---
|
| 13 |
# all-MiniLM-L12-v2 โ ExecuTorch
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
twelve layers instead of six, the same 384-dimensional output and the same recipe.
|
| 19 |
-
|
| 20 |
-
- **Source**: sentence-transformers/all-MiniLM-L12-v2 โ 33.4M parameters, 12 BERT layers,
|
| 21 |
-
384-dimensional output
|
| 22 |
-
- **License**: Apache-2.0
|
| 23 |
-
- **Input**: `input_ids` and `attention_mask`, both `[1, 256]` int64
|
| 24 |
-
- **Output**: `[1, 384]`, mean-pooled over the mask and L2-normalised inside the graph
|
| 25 |
-
|
| 26 |
-
## The pooling is in the graph, on purpose
|
| 27 |
|
| 28 |
-
sentence-transformers
|
| 29 |
-
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|---|---|---|
|
| 33 |
-
| all-MiniLM-L6-v2 | mean | yes |
|
| 34 |
-
| **all-MiniLM-L12-v2** | **mean** | **yes** |
|
| 35 |
-
| bge-small-en-v1.5 | **CLS** | yes |
|
| 36 |
-
| multilingual-e5-base | mean | yes |
|
| 37 |
-
| multilingual-e5-large | mean | yes |
|
| 38 |
-
| paraphrase-multilingual-L12 | mean | **no** |
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
|
| 46 |
## Verification
|
| 47 |
|
| 48 |
-
| build | file | size |
|
| 49 |
-
|---|---|---|---|---|
|
| 50 |
-
|
|
| 51 |
-
|
|
| 52 |
-
| Core ML
|
| 53 |
-
|
| 54 |
-
Mac arm64, median of 10, one 256-token sequence โ a reference point for relative
|
| 55 |
-
a device number.
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 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 |
torch.export -> to_edge_transform_and_lower(partitioner) -> .pte
|
| 94 |
(conversion scripts: [executorch-models](https://github.com/john-rocky/executorch-models))
|
|
|
|
| 12 |
---
|
| 13 |
# all-MiniLM-L12-v2 โ ExecuTorch
|
| 14 |
|
| 15 |
+
all-MiniLM at twice the depth, on the same recipe. Text in, one
|
| 16 |
+
384-dimensional vector out, for search and retrieval that never leaves the
|
| 17 |
+
device.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
- **Source**: sentence-transformers/all-MiniLM-L12-v2 โ 12 layers, 384 dimensions, 30,522 vocabulary
|
| 20 |
+
- **License**: apache-2.0
|
| 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 |
## Verification
|
| 33 |
|
| 34 |
+
| build | file | size (MB) | Mac ms* | backend takes | worst cosine vs eager | retrieval budget |
|
| 35 |
+
|---|---|---|---|---|---|---|
|
| 36 |
+
| fp32 | `embed_all_minilm_l12_xnnpack_fp32.pte` | 133.0 | 22.2 | 78.5% | 1.000000 | 0% |
|
| 37 |
+
| fp16 | `embed_all_minilm_l12_xnnpack_fp16.pte` | 66.7 | 33.5 | 67.6% | 0.999999 | 4% |
|
| 38 |
+
| Core ML (fp16, iOS) | `embed_all_minilm_l12_coreml_all.pte` | 67.2 | 3.6 | 100.0% | 0.999969 | 23% |
|
| 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 |
+
19.6 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 |
+
## The attention is eager, and that is the faster export
|
| 51 |
+
|
| 52 |
+
`F.scaled_dot_product_attention` decomposes in the edge dialect to `_safe_softmax`,
|
| 53 |
+
whose guard against a fully-masked row costs six operations XNNPACK cannot take โ
|
| 54 |
+
`scalar_tensor`, `where`, `logical_not`, `eq`, `full_like`, `any.dim` โ once per
|
| 55 |
+
attention block, and each one cuts the subgraph in two. The guard can only ever fire
|
| 56 |
+
when some query row loses **every** key, which needs left padding or an empty
|
| 57 |
+
sequence. This model is right-padded, so even a row that is all padding still sees the
|
| 58 |
+
real tokens and the guard protects nothing.
|
| 59 |
+
|
| 60 |
+
Exporting with `attn_implementation="eager"` removes it. Measured with 251 of 256
|
| 61 |
+
positions masked โ as adversarial as this shape gets โ the two graphs agree to 1.4e-07,
|
| 62 |
+
and XNNPACK fp32 goes from **62.6% to 78.5%** delegated.
|
| 63 |
+
|
| 64 |
+
## Not shipped: int8
|
| 65 |
+
|
| 66 |
+
`embed_all_minilm_l12_xnnpack_int8.pte` is **69.5 MB** against fp16's 66.7 MB. Dynamic int8 quantises the
|
| 67 |
+
linear weights and leaves the token embedding table in fp32, and here that table is
|
| 68 |
+
47 MB of the 133.0 MB model โ **35%**. The size a build comes out at is
|
| 69 |
+
`0.5 + 1.5 x (table share)` times the fp16 build; at 35% that is
|
| 70 |
+
1.03, so there was never a smaller file to be had.
|
| 71 |
+
|
| 72 |
+
It is withheld on the number that decides. Ranking the eight test sentences against
|
| 73 |
+
each other, this build moves a pair score by at most **0.0107** while the
|
| 74 |
+
closest fp32 decision โ the gap between the document a query retrieves and the
|
| 75 |
+
runner-up โ is **0.0078**. That is **138%** of
|
| 76 |
+
the room available, against a bar of 50%.
|
| 77 |
+
|
| 78 |
+
Correlation reads 0.998465 for this build, which no correlation gate
|
| 79 |
+
would stop.
|
| 80 |
|
| 81 |
torch.export -> to_edge_transform_and_lower(partitioner) -> .pte
|
| 82 |
(conversion scripts: [executorch-models](https://github.com/john-rocky/executorch-models))
|