--- library_name: "fastforks" pipeline_tag: "mask-generation" license: "apache-2.0" tags: - "promptable_segmentation" - "segment-anything" - "promptable-segmentation" - "cuda" - "pytorch" - "fastforks" - "fastforks-card" base_model: - "mit-han-lab/efficientvit-sam" --- # EfficientViT-SAM (fastforks) 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. 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: . Kernels for the `kernels` backend: . Original code: at `de7d7733cc03`. Author weight repos: . Task: promptable_segmentation. Tier: stable. Outputs: `pred_masks`, `iou_scores`. Backends: `portable`, `kernels`. Input: one image plus a point, box or text prompt. Output: masks with quality scores. ## Variants 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). | variant | weights (author link) | SHA-256 | weights licence | commercial use | |---|---|---|---|---| | `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 | | `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 | | `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 | | `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 | | `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 | ## Licence 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`. 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. 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 ## Input size any H x W >= 1, resized inside to the fixed encoder input 1024x1024 (the default export size) 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) ## Speed and memory ### Promptable segmentation, synthetic, 1024x1024 | model | time (ms): original fp32 | original | portable | kernels | kernels speed-up: vs original | vs portable | peak memory (MiB, allocated / reserved): original | portable | kernels | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | `efficientvit-sam-l0` | 26.9 | 26.3 | 12.7 | 4.45 | 5.9x | 2.9x | 211 / 232 | 171 / 210 | 176 / 256 | | `efficientvit-sam-l1` | 30.1 | 29.9 | 14.4 | 5.79 | 5.2x | 2.5x | 260 / 278 | 195 / 234 | 203 / 284 | | `efficientvit-sam-l2` | 34.4 | 34.4 | 17.8 | 6.83 | 5.0x | 2.6x | 313 / 344 | 221 / 260 | 232 / 312 | | `efficientvit-sam-xl0` | 46.9 | 28.2 | 19.0 | 9.75 | 2.9x | 1.9x | 654 / 670 | 433 / 506 | 401 / 492 | | `efficientvit-sam-xl1` | 72.6 | 40.9 | 28.9 | 15.3 | 2.7x | 1.9x | 984 / 1022 | 598 / 676 | 582 / 728 | ### Startup and first call | model | load (s): original | portable | kernels | first call (s): original | portable | kernels | | --- | --- | --- | --- | --- | --- | --- | | `efficientvit-sam-l0` | 0.35 | 0.83 | 1.63 | 0.82 | 0.72 | 0.25 | | `efficientvit-sam-l1` | 0.31 | 0.76 | 1.64 | 0.03 | 0.69 | 0.25 | | `efficientvit-sam-l2` | 0.39 | 0.93 | 1.78 | 0.04 | 0.66 | 0.25 | | `efficientvit-sam-xl0` | 0.62 | 2.67 | 2.14 | 0.59 | 0.52 | 0.26 | | `efficientvit-sam-xl1` | 1.06 | 2.32 | 2.51 | 0.04 | 0.53 | 0.24 | ### torch.compile and TensorRT | 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) | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | `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 | | `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 | | `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 | | `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 | | `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 | Fixed-size cells: time (ms) / peak allocated / peak reserved memory (MiB). 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. ## Accuracy ### On public datasets 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. | variant | dataset | original fp32 | original fp16 | portable | kernels | note | |---|---|---|---|---|---|---| | `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 | | | `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 | | | `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 | | | `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 | | | `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 | | Measured on NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-10. ### Parity with the original code 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`). ## Usage ```python from fastforks import promptable_segmentation model = promptable_segmentation.load("efficientvit-sam-l0") # mode="auto": the preferred backend from recorded measurements result = model("photo.jpg", input_points=[[x, y]], input_labels=[1]) result.masks # [M, H, W] bool # SAM 3 (text prompts): model("photo.jpg", text="coin") -> boxes, scores, masks result.backend # what ran, e.g. Backend(mode='portable', device='cuda:0', dtype='float16') ``` Install with `pip install fastforks` (see ). Other variants: `efficientvit-sam-l0`, `efficientvit-sam-l1`, `efficientvit-sam-l2`, `efficientvit-sam-xl0`, `efficientvit-sam-xl1`. ## Kernels backend `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 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.