Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
tags:
|
| 4 |
+
- executorch
|
| 5 |
+
- xnnpack
|
| 6 |
+
- pte
|
| 7 |
+
- on-device
|
| 8 |
+
- mask-generation
|
| 9 |
+
base_model:
|
| 10 |
+
- facebook/EdgeTAM
|
| 11 |
+
---
|
| 12 |
+
# EdgeTAM β ExecuTorch XNNPACK (encoder + decoder)
|
| 13 |
+
|
| 14 |
+
Promptable segmentation in two `.pte` files: run the encoder once per image, the
|
| 15 |
+
decoder once per click.
|
| 16 |
+
|
| 17 |
+
- `edgetam_encoder_xnnpack_fp32.pte` (19.7 MB) β image (1,3,1024,1024) β
|
| 18 |
+
image_embed (1,256,64,64), feat_s0 (1,32,256,256), feat_s1 (1,64,128,128)
|
| 19 |
+
- `edgetam_decoder_xnnpack_fp32.pte` (24.7 MB) β (image_embed, feat_s0, feat_s1,
|
| 20 |
+
points (1,1,N,2) fp32 pixel coords in 1024-space, labels (1,1,N) int64 1=fg/0=bg)
|
| 21 |
+
β mask logits (1,1,3,256,256), iou scores (1,1,3)
|
| 22 |
+
- `edgetam_decoder_xnnpack_fp16.pte` (12.6 MB) β the same decoder at half the size,
|
| 23 |
+
corr 1.000000 against fp32 eager. It takes and returns fp32 tensors, so pairing it
|
| 24 |
+
with the fp32 encoder needs no app changes.
|
| 25 |
+
|
| 26 |
+
The encoder ships in fp32 only, and that is not an omission. Its backbone is RepViT,
|
| 27 |
+
which is convolutional, and XNNPACK serializes convolution weights as fp32 whatever
|
| 28 |
+
dtype the graph carries β fp16 came out at 19.8 MB (100.5%) and dynamic int8 at
|
| 29 |
+
19.7 MB, so neither buys anything. At 19.7 MB the fp32 encoder is already smaller
|
| 30 |
+
than SAM 2.1 hiera-tiny's *fp16* encoder (55.6 MB).
|
| 31 |
+
|
| 32 |
+
EdgeTAM is Meta's on-device SAM 2 (CVPR 2025). Its encoder is **5.5Γ smaller than
|
| 33 |
+
SAM 2.1 hiera-tiny's** (19.7 MB vs 109.2 MB) for the same output contract, so an
|
| 34 |
+
app written against
|
| 35 |
+
[SAM2.1-hiera-tiny-ExecuTorch](https://huggingface.co/mlboydaisuke/SAM2.1-hiera-tiny-ExecuTorch)
|
| 36 |
+
swaps the two files and changes nothing else.
|
| 37 |
+
|
| 38 |
+
- **Source**: [facebook/EdgeTAM](https://huggingface.co/facebook/EdgeTAM), loaded
|
| 39 |
+
from the transformers-format mirror
|
| 40 |
+
[yonigozlan/EdgeTAM-hf](https://huggingface.co/yonigozlan/EdgeTAM-hf)
|
| 41 |
+
(`facebook/EdgeTAM` publishes only the original `edgetam.pt`)
|
| 42 |
+
- **License**: Apache-2.0
|
| 43 |
+
- **Preprocess**: RGB/255, ImageNet norm (mean .485/.456/.406, std .229/.224/.225),
|
| 44 |
+
resize 1024Γ1024
|
| 45 |
+
- **Postprocess**: take argmax(iou) of the 3 mask logits, threshold at > 0, upsample
|
| 46 |
+
4Γ (256β1024) back to image space. The prompt encoder is inside the decoder β pass
|
| 47 |
+
raw click coordinates, no separate point-encoding code needed.
|
| 48 |
+
|
| 49 |
+
## Verification (Mac arm64, executorch 1.4.0, torch 2.13.0)
|
| 50 |
+
|
| 51 |
+
Every output of both graphs matches torch fp32 eager at corr 1.000000, and the two
|
| 52 |
+
wrappers compose back to `EdgeTamModel.forward` exactly (max_abs_diff 0.000e+00).
|
| 53 |
+
|
| 54 |
+
| graph | output | shape | max_abs_diff | corr |
|
| 55 |
+
|-------|--------|-------|--------------|------|
|
| 56 |
+
| encoder | image_embed | [1, 256, 64, 64] | 0.000e+00 | 1.000000 |
|
| 57 |
+
| encoder | feat_s0 | [1, 32, 256, 256] | 0.000e+00 | 1.000000 |
|
| 58 |
+
| encoder | feat_s1 | [1, 64, 128, 128] | 0.000e+00 | 1.000000 |
|
| 59 |
+
| decoder | mask logits | [1, 1, 3, 256, 256] | 0.000e+00 | 1.000000 |
|
| 60 |
+
| decoder | iou | [1, 1, 3] | 0.000e+00 | 1.000000 |
|
| 61 |
+
|
| 62 |
+
Median over 10 runs, Mac arm64 single process β a relative reference, not a device
|
| 63 |
+
number: encoder 32.3 ms (torch eager 103.5 ms), decoder 23.7 ms (eager 13.9 ms).
|
| 64 |
+
|
| 65 |
+
XNNPACK delegate coverage: encoder 99.8% (one `upsample_nearest2d` on the portable
|
| 66 |
+
kernels), decoder 66.5% (the prompt encoder's `expand`/`where` bookkeeping stays on
|
| 67 |
+
portable; every convolution and matmul is delegated).
|
| 68 |
+
|
| 69 |
+
## Conversion
|
| 70 |
+
|
| 71 |
+
torch.export β to_edge_transform_and_lower(XnnpackPartitioner) β .pte
|
| 72 |
+
(conversion script: [executorch-models](https://github.com/john-rocky/executorch-models))
|
| 73 |
+
|
| 74 |
+
Two details matter for this split, both shared with the SAM 2.1 conversion. Encoder
|
| 75 |
+
outputs are forced `.contiguous()` β transformers hands back channels_last tensors,
|
| 76 |
+
and that layout at a `.pte` boundary makes the delegate's runtime shape propagation
|
| 77 |
+
read physical strides as logical dims. Identity `repeat_interleave(1, dim)` calls in
|
| 78 |
+
the decoder are dropped, since their lowered form mis-sizes on a single-point export.
|
| 79 |
+
|
| 80 |
+
The GPU-specific rewrites in the LiteRT build of this model (splitting the
|
| 81 |
+
squeeze-excite mean, replacing ConvTranspose2d) are ML Drift workarounds and are not
|
| 82 |
+
needed here β XNNPACK runs the stock graph.
|