card: update from fastforks 1cbf1671
Browse files
README.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: "fastforks"
|
| 3 |
+
pipeline_tag: "mask-generation"
|
| 4 |
+
license: "apache-2.0"
|
| 5 |
+
tags:
|
| 6 |
+
- "promptable_segmentation"
|
| 7 |
+
- "segment-anything"
|
| 8 |
+
- "promptable-segmentation"
|
| 9 |
+
- "cuda"
|
| 10 |
+
- "pytorch"
|
| 11 |
+
- "fastforks"
|
| 12 |
+
- "fastforks-card"
|
| 13 |
+
base_model:
|
| 14 |
+
- "mit-han-lab/efficientvit-sam"
|
| 15 |
+
---
|
| 16 |
+
# EfficientViT-SAM (fastforks)
|
| 17 |
+
|
| 18 |
+
EfficientViT-SAM (Zhang, Cai et al. 2024, MIT Han lab): Segment Anything with the ViT-H image encoder replaced by an EfficientViT (conv stages + ReLU linear attention) distilled from it; SAM's prompt encoder and mask decoder, so points, boxes and mask logits work the same. The portable `module()` is the image encoder only.
|
| 19 |
+
|
| 20 |
+
This repo is the model card only: it holds no weights. fastforks downloads the authors' weights from the links below and checks them against the SHA-256 in the model card. Code: <https://github.com/kleinicke/fastforks>. Kernels for the `kernels` backend: <https://huggingface.co/fastforks/kernels>. Original code: <https://github.com/mit-han-lab/efficientvit> at `de7d7733cc03`.
|
| 21 |
+
|
| 22 |
+
Author weight repos: <https://huggingface.co/mit-han-lab/efficientvit-sam>.
|
| 23 |
+
|
| 24 |
+
Task: promptable_segmentation. Tier: stable. Outputs: `pred_masks`, `iou_scores`. Backends: `portable`, `kernels`.
|
| 25 |
+
|
| 26 |
+
Input: one image plus a point, box or text prompt. Output: masks with quality scores.
|
| 27 |
+
|
| 28 |
+
## Variants
|
| 29 |
+
|
| 30 |
+
Weights are the authors' files (not hosted here). SHA-256 shortened to 12 hex digits; the full hashes are in [`card.toml`](https://github.com/kleinicke/fastforks/blob/main/src/fastforks/promptable_segmentation/models/efficientvit_sam/card.toml).
|
| 31 |
+
|
| 32 |
+
| variant | weights (author link) | SHA-256 | weights licence | commercial use |
|
| 33 |
+
|---|---|---|---|---|
|
| 34 |
+
| `efficientvit-sam-l0@1` | [efficientvit_sam_l0.pt](https://huggingface.co/mit-han-lab/efficientvit-sam/resolve/a2f0c5929196a13ef1ffc9338d3f9e482e1e0e68/efficientvit_sam_l0.pt) | `c4f994b01a16` | Apache-2.0 | yes |
|
| 35 |
+
| `efficientvit-sam-l1@1` | [efficientvit_sam_l1.pt](https://huggingface.co/mit-han-lab/efficientvit-sam/resolve/a2f0c5929196a13ef1ffc9338d3f9e482e1e0e68/efficientvit_sam_l1.pt) | `fa151df2b9b9` | Apache-2.0 | yes |
|
| 36 |
+
| `efficientvit-sam-l2@1` | [efficientvit_sam_l2.pt](https://huggingface.co/mit-han-lab/efficientvit-sam/resolve/a2f0c5929196a13ef1ffc9338d3f9e482e1e0e68/efficientvit_sam_l2.pt) | `d4bfd842224c` | Apache-2.0 | yes |
|
| 37 |
+
| `efficientvit-sam-xl0@1` | [efficientvit_sam_xl0.pt](https://huggingface.co/mit-han-lab/efficientvit-sam/resolve/a2f0c5929196a13ef1ffc9338d3f9e482e1e0e68/efficientvit_sam_xl0.pt) | `9bc2f87bd23d` | Apache-2.0 | yes |
|
| 38 |
+
| `efficientvit-sam-xl1@1` | [efficientvit_sam_xl1.pt](https://huggingface.co/mit-han-lab/efficientvit-sam/resolve/a2f0c5929196a13ef1ffc9338d3f9e482e1e0e68/efficientvit_sam_xl1.pt) | `10f422776794` | Apache-2.0 | yes |
|
| 39 |
+
|
| 40 |
+
## Licence
|
| 41 |
+
|
| 42 |
+
Original-code strings, recorded as they are (research-use package; check them before any other use). Code: Apache-2.0. Licence files: `LICENSE`, `LICENSE-segment-anything`.
|
| 43 |
+
|
| 44 |
+
Training data: distilled from SAM ViT-H, then trained on SA-1B (11M licensed images, 1.1B automatically generated masks) per the paper; the dataset itself is under the SA-1B research licence.
|
| 45 |
+
|
| 46 |
+
Licence evidence: https://huggingface.co/mit-han-lab/efficientvit-sam/blob/a2f0c5929196a13ef1ffc9338d3f9e482e1e0e68/README.md (license: apache-2.0, with LICENSE.txt); code: https://github.com/mit-han-lab/efficientvit/blob/de7d7733cc0329f391b33f1f459271562ec27bd5/LICENSE
|
| 47 |
+
|
| 48 |
+
## Input size
|
| 49 |
+
|
| 50 |
+
any H x W >= 1, resized inside to the fixed encoder input 1024x1024 (the default export size)
|
| 51 |
+
Tested up to (portable, fp16, RTX 5060 Ti 16 GB): `efficientvit-sam-l0` 1080x1920 (0.2 GiB peak allocated, 0.2 reserved); `efficientvit-sam-l1` 1080x1920 (0.2 GiB peak allocated, 0.2 reserved); `efficientvit-sam-l2` 1080x1920 (0.2 GiB peak allocated, 0.3 reserved); `efficientvit-sam-xl0` 1080x1920 (0.4 GiB peak allocated, 0.5 reserved); `efficientvit-sam-xl1` 1080x1920 (0.6 GiB peak allocated, 0.7 reserved)
|
| 52 |
+
|
| 53 |
+
## Speed and memory
|
| 54 |
+
|
| 55 |
+
### Promptable segmentation, synthetic, 1024x1024
|
| 56 |
+
|
| 57 |
+
| model | time (ms): original fp32 | original | portable | kernels | kernels speed-up: vs original | vs portable | peak memory (MiB, allocated / reserved): original | portable | kernels |
|
| 58 |
+
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
|
| 59 |
+
| `efficientvit-sam-l0` | 26.9 | 26.3 | 12.7 | 4.45 | 5.9x | 2.9x | 211 / 232 | 171 / 210 | 176 / 256 |
|
| 60 |
+
| `efficientvit-sam-l1` | 30.1 | 29.9 | 14.4 | 5.79 | 5.2x | 2.5x | 260 / 278 | 195 / 234 | 203 / 284 |
|
| 61 |
+
| `efficientvit-sam-l2` | 34.4 | 34.4 | 17.8 | 6.83 | 5.0x | 2.6x | 313 / 344 | 221 / 260 | 232 / 312 |
|
| 62 |
+
| `efficientvit-sam-xl0` | 46.9 | 28.2 | 19.0 | 9.75 | 2.9x | 1.9x | 654 / 670 | 433 / 506 | 401 / 492 |
|
| 63 |
+
| `efficientvit-sam-xl1` | 72.6 | 40.9 | 28.9 | 15.3 | 2.7x | 1.9x | 984 / 1022 | 598 / 676 | 582 / 728 |
|
| 64 |
+
|
| 65 |
+
### Startup and first call
|
| 66 |
+
|
| 67 |
+
| model | load (s): original | portable | kernels | first call (s): original | portable | kernels |
|
| 68 |
+
| --- | --- | --- | --- | --- | --- | --- |
|
| 69 |
+
| `efficientvit-sam-l0` | 0.35 | 0.83 | 1.63 | 0.82 | 0.72 | 0.25 |
|
| 70 |
+
| `efficientvit-sam-l1` | 0.31 | 0.76 | 1.64 | 0.03 | 0.69 | 0.25 |
|
| 71 |
+
| `efficientvit-sam-l2` | 0.39 | 0.93 | 1.78 | 0.04 | 0.66 | 0.25 |
|
| 72 |
+
| `efficientvit-sam-xl0` | 0.62 | 2.67 | 2.14 | 0.59 | 0.52 | 0.26 |
|
| 73 |
+
| `efficientvit-sam-xl1` | 1.06 | 2.32 | 2.51 | 0.04 | 0.53 | 0.24 |
|
| 74 |
+
|
| 75 |
+
### torch.compile and TensorRT
|
| 76 |
+
|
| 77 |
+
| model | input | time: portable | compile | TensorRT fp16 | kernels | preparation: compile (cold first call) | ONNX + engine build | peak MiB (alloc / reserved): portable | compile | kernels | TensorRT (engine + torch) |
|
| 78 |
+
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
|
| 79 |
+
| `efficientvit-sam-l0` | 1024x1024 | 12.7 ms | 6.44 ms | 5.56 ms, fp32 engine (image encoder only) | 4.45 ms | 25.2 s | 19.9 s | 171 / 210 | 188 / 228 | 176 / 256 | 404 / 428 |
|
| 80 |
+
| `efficientvit-sam-l1` | 1024x1024 | 14.4 ms | 11.3 ms | 7.30 ms, fp32 engine (image encoder only) | 5.79 ms | 24.8 s | 22.0 s | 195 / 234 | 212 / 252 | 203 / 284 | 517 / 578 |
|
| 81 |
+
| `efficientvit-sam-l2` | 1024x1024 | 17.8 ms | 10.8 ms | 9.65 ms, fp32 engine (image encoder only) | 6.83 ms | 26.1 s | 24.1 s | 221 / 260 | 238 / 278 | 232 / 312 | 633 / 690 |
|
| 82 |
+
| `efficientvit-sam-xl0` | 1024x1024 | 19.0 ms | 14.2 ms | 22.7 ms, fp32 engine (image encoder only) | 9.75 ms | 24.0 s | 29.8 s | 433 / 506 | 397 / 424 | 401 / 492 | 1288 / 1328 |
|
| 83 |
+
| `efficientvit-sam-xl1` | 1024x1024 | 28.9 ms | 22.9 ms | 38.4 ms, fp32 engine (image encoder only) | 15.3 ms | 26.7 s | 36.6 s | 598 / 676 | 562 / 616 | 582 / 728 | 1894 / 1960 |
|
| 84 |
+
|
| 85 |
+
Fixed-size cells: time (ms) / peak allocated / peak reserved memory (MiB).
|
| 86 |
+
|
| 87 |
+
Hardware, protocol and caveats: [benchmarks](https://github.com/kleinicke/fastforks/blob/main/docs/benchmarks.md) (RTX 5060 Ti 16 GB, sm_120). Original = the original code named above at the precision of portable (fp16, or `(fp32)` where fp16 is unsupported or not finite); original fp32 = its default fp32 run. Peak memory is the torch allocator's.
|
| 88 |
+
|
| 89 |
+
## Accuracy
|
| 90 |
+
|
| 91 |
+
### On public datasets
|
| 92 |
+
|
| 93 |
+
One point per ground-truth instance (the interior point farthest from the border); IoU of the best-scored of 3 masks / of the single mask. Original = the original code named under Details, same checkpoint and protocol.
|
| 94 |
+
|
| 95 |
+
| variant | dataset | original fp32 | original fp16 | portable | kernels | note |
|
| 96 |
+
|---|---|---|---|---|---|---|
|
| 97 |
+
| `efficientvit-sam-l0` | COCO val2017, every 10th image, point prompts, mIoU best of 3 / single mask % | 54.45 / 50.57 | 54.60 / 50.50 | 54.58 / 50.54 | 54.59 / 50.52 | |
|
| 98 |
+
| `efficientvit-sam-l1` | COCO val2017, every 10th image, point prompts, mIoU best of 3 / single mask % | 55.48 / 51.26 | 55.38 / 51.06 | 55.37 / 51.01 | 55.42 / 51.08 | |
|
| 99 |
+
| `efficientvit-sam-l2` | COCO val2017, every 10th image, point prompts, mIoU best of 3 / single mask % | 56.50 / 52.23 | 56.58 / 52.29 | 56.44 / 52.25 | 56.34 / 52.22 | |
|
| 100 |
+
| `efficientvit-sam-xl0` | COCO val2017, every 10th image, point prompts, mIoU best of 3 / single mask % | 59.00 / 54.47 | 58.90 / 54.48 | 58.99 / 54.51 | 58.90 / 54.51 | |
|
| 101 |
+
| `efficientvit-sam-xl1` | COCO val2017, every 10th image, point prompts, mIoU best of 3 / single mask % | 59.38 / 54.84 | 59.33 / 54.84 | 59.40 / 54.85 | 59.43 / 54.85 | |
|
| 102 |
+
|
| 103 |
+
Measured on NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-10.
|
| 104 |
+
|
| 105 |
+
### Parity with the original code
|
| 106 |
+
|
| 107 |
+
Every variant is checked against reference outputs of the original code at its pinned commit. CPU, float32: max |diff| <= 0.002 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 2.5 % and p99 <= 7.3 % of the reference's median |value| (absolute error of the output `pred_masks`).
|
| 108 |
+
|
| 109 |
+
## Usage
|
| 110 |
+
|
| 111 |
+
```python
|
| 112 |
+
from fastforks import promptable_segmentation
|
| 113 |
+
|
| 114 |
+
model = promptable_segmentation.load("efficientvit-sam-l0") # mode="auto": the preferred backend from recorded measurements
|
| 115 |
+
result = model("photo.jpg", input_points=[[x, y]], input_labels=[1])
|
| 116 |
+
result.masks # [M, H, W] bool
|
| 117 |
+
# SAM 3 (text prompts): model("photo.jpg", text="coin") -> boxes, scores, masks
|
| 118 |
+
result.backend # what ran, e.g. Backend(mode='portable', device='cuda:0', dtype='float16')
|
| 119 |
+
```
|
| 120 |
+
|
| 121 |
+
Install with `pip install fastforks` (see <https://github.com/kleinicke/fastforks>). Other variants: `efficientvit-sam-l0`, `efficientvit-sam-l1`, `efficientvit-sam-l2`, `efficientvit-sam-xl0`, `efficientvit-sam-xl1`.
|
| 122 |
+
|
| 123 |
+
## Kernels backend
|
| 124 |
+
|
| 125 |
+
`promptable_segmentation.load("efficientvit-sam-l0", mode="kernels")` runs our CUDA kernels (`fvm_conv`, `fvm_extra`, `fvm_mb`, `fvm_r3`). It needs a prebuilt kernel for your GPU architecture (downloaded from <https://huggingface.co/fastforks/kernels> on first use) and a recent NVIDIA driver; if there is none it raises `BackendUnavailableError` with the reason and never falls back silently. `mode="auto"` picks `kernels` when it can run and logs the choice.
|
| 126 |
+
|
| 127 |
+
<!-- staged from fastforks 1cbf1671 (2026-11-15) -->
|