mlboydaisuke commited on
Commit
9beb623
·
verified ·
1 Parent(s): 504b0c4

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +26 -17
README.md CHANGED
@@ -33,13 +33,16 @@ Getting it wrong does not throw; it returns vectors that look fine and rank wron
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
@@ -49,17 +52,23 @@ 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
 
 
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 | 20.6 | 78.5% | 1.000000 | 0% |
37
+ | fp16 | `embed_all_minilm_l12_xnnpack_fp16.pte` | 66.7 | 32.0 | 67.6% | 0.999999 | 4% |
38
+ | Core ML (fp16, iOS) | `embed_all_minilm_l12_coreml_all.pte` | 67.2 | 3.7 | 100.0% | 0.999969 | 23% |
39
 
40
+ \*Mac arm64, one 256-token sequence, **fastest of five medians of ten** — a reference
41
+ point for relative cost, not a device number. The host shares its cores with other work,
42
+ and a single median does not survive that: the same eager model here measured 19.6 ms and
43
+ 182.8 ms twenty minutes apart. Contention only ever adds time, so the fastest repetition is
44
+ the one that means something. Torch eager fp32, measured the same way, is
45
+ 19.1 ms.
46
 
47
  Cosine is measured against the model run in eager through its own pooling, over eight
48
  sentences. The last column is the one that decides: rank those eight against each
 
52
 
53
  ## The attention is eager, and that is the faster export
54
 
55
+ `F.scaled_dot_product_attention` does not survive export as one operation. The edge
56
+ dialect lowers it through `_safe_softmax`, whose guard against a row with no unmasked key
57
+ at all leaves **11 operations XNNPACK cannot take, in every attention
58
+ block** — `scalar_tensor`, `where`, `mul.Scalar`, `logical_not`, `eq`, `full_like`, `any.dim`. Each one cuts the subgraph in two.
59
+
60
+ The switch is `attn_implementation="eager"`: transformers then builds the mask
61
+ itself, as `torch.finfo(dtype).min`, instead of handing `F.sdpa` a **boolean** mask
62
+ for PyTorch to fill with `-inf`.
63
+
64
+ The guard is emitted whether or not it can ever fire, and here it cannot: it triggers only
65
+ on `-inf`, and this arm never produces one. So the two differ only about rows that have no
66
+ unmasked key at all — sdpa zeroes them, this one gives them a uniform row — and those are
67
+ padding rows, which the pooling discards and which every real query row masks out anyway.
68
+ Measured with all but eight positions masked, as adversarial as this shape gets, the two
69
+ graphs agree to 1.4e-07.
70
+
71
+ XNNPACK fp32 goes from **62.6% to 78.5%** delegated.
72
 
73
  ## Not shipped: int8
74