Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -12,85 +12,71 @@ base_model:
|
|
| 12 |
---
|
| 13 |
# all-MiniLM-L6-v2 — ExecuTorch
|
| 14 |
|
| 15 |
-
|
| 16 |
-
never leaves the
|
|
|
|
| 17 |
|
| 18 |
-
- **Source**: sentence-transformers/all-MiniLM-L6-v2 —
|
| 19 |
-
- **License**:
|
| 20 |
- **Input**: `input_ids` and `attention_mask`, both `[1, 256]` int64
|
| 21 |
-
- **Output**: `[1, 384]`
|
| 22 |
-
|
| 23 |
-
## The
|
| 24 |
-
|
| 25 |
-
sentence-transformers
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 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 |
-
XNNPACK fp32 is **slower than PyTorch eager** here (14.4 ms against 8.5), and fp16
|
| 82 |
-
is slower again while halving the file. Core ML is the one that pays: 2.0 ms, roughly
|
| 83 |
-
4.2x eager, at half the size. If this is going on an Apple device, take the Core ML
|
| 84 |
-
build.
|
| 85 |
-
|
| 86 |
-
## Conversion
|
| 87 |
-
|
| 88 |
-
```bash
|
| 89 |
-
python convert/export_embed.py all_minilm_l6
|
| 90 |
-
python convert/check_embed.py all_minilm_l6
|
| 91 |
-
```
|
| 92 |
-
|
| 93 |
-
Sequence length is fixed at 256; the attention mask makes padding harmless for mean pooling,
|
| 94 |
-
and chunking anything longer is the caller's job.
|
| 95 |
-
|
| 96 |
(conversion scripts: [executorch-models](https://github.com/john-rocky/executorch-models))
|
|
|
|
| 12 |
---
|
| 13 |
# all-MiniLM-L6-v2 — ExecuTorch
|
| 14 |
|
| 15 |
+
Six layers, and the cheapest embedding on this shelf. 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-L6-v2 — 6 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_l6_xnnpack_fp32.pte` | 90.4 | 11.1 | 73.4% | 1.000000 | 0% |
|
| 37 |
+
| fp16 | `embed_all_minilm_l6_xnnpack_fp16.pte` | 45.3 | 16.7 | 63.4% | 0.999999 | 4% |
|
| 38 |
+
| Core ML (fp16, iOS) | `embed_all_minilm_l6_coreml_all.pte` | 45.7 | 2.0 | 100.0% | 0.999984 | 19% |
|
| 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 |
+
10.5 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 **59.7% to 73.4%** delegated.
|
| 63 |
+
|
| 64 |
+
## Not shipped: int8
|
| 65 |
+
|
| 66 |
+
`embed_all_minilm_l6_xnnpack_int8.pte` is **58.6 MB** against fp16's 45.3 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 90.4 MB model — **52%**. The size a build comes out at is
|
| 69 |
+
`0.5 + 1.5 x (table share)` times the fp16 build; at 52% that is
|
| 70 |
+
1.28, 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.0102** while the
|
| 74 |
+
closest fp32 decision — the gap between the document a query retrieves and the
|
| 75 |
+
runner-up — is **0.0059**. That is **173%** of
|
| 76 |
+
the room available, against a bar of 50%.
|
| 77 |
+
|
| 78 |
+
Correlation reads 0.998751 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))
|