Models · Promptable segmentation
EfficientViT-SAM
EfficientViT-SAM (MIT Han lab): Segment Anything with a fast convolutional image encoder, in five sizes.
stable Fork of mit-han-lab/efficientvit@de7d773 · backends: portable, kernels
- Paper EfficientViT-SAM: Accelerated Segment Anything Model Without Accuracy Loss CVPR 2024 Workshop (Efficient Large Vision Models) · first released 7 Feb 2024
Paper 2024 Added in 0.2.0 Evaluated with 0.2.0
Use it
pip install fastforks Lean install with only what this model needs: pip install fastforks-core
from fastforks import promptable_segmentation
model = promptable_segmentation.load("efficientvit-sam-l0") # kernels on a supported GPU, else portable PyTorch
result = model(image, input_points=...)
result.pred_masks # also: iou_scores
result.backend # what ran: mode, device, dtype, kernels fastforks bench efficientvit-sam-l0 Times the model on this machine. load(…, mode="portable") or mode="kernels" picks a backend; usage guide.
Speed and memory
Every backend on one GPU (RTX 5060 Ti 16 GB) and the same input, the authors’ code included. Kernels runs fp16. Portable runs fp16 on CUDA.
| Backend | dtype | Time per call (ms) | vs original fp16 | Peak memory allocated / reserved | Load (s) | First call (s) |
|---|---|---|---|---|---|---|
| Original fp32upstream EfficientViTSamPredictor.set_image + predict (centre point, multimask_output=True) | fp32 | 26.9 | 0.98× | 251 MiB/290 MiB | 2.5 | 0.62 |
| Original fp16torch.autocast(float16) around the call; upstream EfficientViTSamPredictor.set_image + predict (centre point, multimask_output=True) | fp16 | 26.3 | – | 211 MiB/232 MiB | 0.3 | 0.82 |
| Portable fp32 | fp32 | not measured | – | – | – | – |
| Portable | fp16 | 11.1 | 2.4× | 158 MiB/190 MiB | 1.4 | 0.74 |
| Kernels | fp16 | 4.55 | 5.8× | 164 MiB/236 MiB | 0.8 | 0.24 |
| Portable + torch.compile | 6.44 | 4.1× | 188 MiB/228 MiB | 25 (build) | – | |
| TensorRT fp32image encoder only | fp32 | 5.56 | 4.7× | 202 MiBenginenot comparable | 20 (build) | – |
Measured on RTX 5060 Ti 16 GB, torch 2.14.1+cu130, 2026-11-10 to 2026-11-16. First call, 3 warm-up, peak reset, median of 3 rounds x median of 5. Ratios divide two
times of this table (same GPU, same input). Original fp16 is the authors’ own precision option, else torch.autocast. torch.compile and TensorRT: build time instead of load time. TensorRT memory (engine, not comparable) is the GPU memory the engine took, read from the driver because TensorRT allocates outside PyTorch, so it can't be compared with the PyTorch peaks of the other rows.
Other devices
| Device | Backend | dtype | ms / call | Peak memory | Output vs reference | Input |
|---|---|---|---|---|---|---|
| Apple M1 Pro 16 GB MPS, torch 2.14.1, 2026-11-12 | Original | fp32 | 70.5 | 1,959 MiB process | – | 1024x1024 |
| Portable | fp32 | 50.6 | 1,779 MiB process | matches | 1024x1024 | |
| Kernels | fp16 | not implemented | – | 1024x1024 | ||
CUDA memory is torch’s peak allocated / reserved; Apple has no such counter, so the Mac rows show the process footprint (weights, Python and torch included). “Output vs reference” compares the device’s output with the stored golden output under the card’s tolerance; – = not checked on that device. Kernels “not implemented” = no kernels for this model on that backend yet: it runs portable there.
Licence and weights
Commercial use allowed
- Code
- Apache-2.0 LICENSELICENSE-segment-anything
- Weights
- Apache-2.0 source
- 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
Our reading of the licences, not legal advice.
Weights
efficientvit_sam_l0.pt 139 MB· hosted on Hugging Facefastforks downloads and checks these files on first use (fastforks download efficientvit-sam-l0).
Accuracy
The test set through the authors’ code and through ours: same checkpoint, same protocol. The distance between the original’s fp32 and fp16 runs is what half precision alone costs; our runs should stay within it.
COCO val2017
every 10th image, point prompts, mIoU best of 3 / single mask %
| Run | dtype | mIoU best of 3 % ↑ | mIoU single % ↑ | Δ mIoU best of 3 % vs fp32 original | images | ms / image |
|---|---|---|---|---|---|---|
| Original fp32 | fp32 | 54.45 | 50.57 | reference | 500 | 21.8 |
| Original fp16 | fp16 | 54.60 | 50.50 | +0.15 | 500 | 18.8 |
| Portable fp32 | fp32 | 54.62 | 50.57 | +0.17 | 500 | – |
| Portable | fp16 | 54.58 | 50.54 | +0.13 | 500 | 15.8 |
| Kernels | fp16 | 54.59 | 50.52 | +0.14 | 500 | 11.2 |
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 authors’ code, same checkpoint and protocol. Measured on original fp32, original fp16, portable, kernels: RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-10; portable fp32: RTX 5060 Ti, torch 2.14.1+cu130, fastforks 44640884, 2026-11-17.
Closeness to the original
Beyond the test-set scores: the raw output of ours against the original’s fp32 output on the same input, pixel by pixel. 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).
| Check | Tolerance | Measured |
|---|---|---|
| CPU fp32, max |diff| | ≤ 0.002 (relative) | not recorded |
| GPU default dtypes, mean |diff| | ≤ 0.025 (relative) | 0.00977 (relative) |
| GPU default dtypes, p99 |diff| | ≤ 0.073 (relative) | 0.02641 (relative) |
Recorded for efficientvit-sam-l0 on RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-10, with these kernels: fvm_convfvm_extrafvm_mbfvm_r3
Details
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.
- Input / output
- Input: one image plus a point, box or text prompt. Output: masks with quality scores.
- Input size
- any H x W >= 1, resized inside to the fixed encoder input 1024x1024 (the default export size); tested up to 1080x1920 (180 MiB allocated)
- Outputs
pred_masks,iou_scores- Checkpoint
arch="l0",input_size=512- CUDA kernels
fvm_convfused convolutions for image classifiersfvm_extrafused transformer row operations (rotary split, SwiGLU with LayerNorm)fvm_mbfused MBConv blocks (MobileNet and EfficientNet families)fvm_r3further fused classifier blocks
- Apple (MPS)
- fp32
Limitations
- Kernels keep CUDA graphs: their private pool and static outputs stay reserved, so peak reserved is ~85 MiB above portable (peak allocated is not); `cuda_graphs=false` or `release_graphs()` frees it.
Full reference, generated from the repository
EfficientViT-SAM (MIT Han lab): Segment Anything with a fast convolutional image encoder, in five sizes.
Commercial use: yes.
| variant | input | backend | time (ms) | peak memory (MiB, allocated / reserved) |
|---|---|---|---|---|
efficientvit-sam-l0 | synthetic (1024x1024) | original (fp32) original portable kernels portable + torch.compile TensorRT fp32 | 26.9 26.3 11.1 4.55 6.44 5.56 (image encoder only) | 251 / 290 211 / 232 158 / 190 164 / 236 188 / 228 404 / 428 |
efficientvit-sam-l1 | synthetic (1024x1024) | original (fp32) original portable kernels portable + torch.compile TensorRT fp32 | 30.1 29.9 14.4 5.47 11.3 7.30 (image encoder only) | 300 / 316 260 / 278 183 / 234 191 / 264 212 / 252 517 / 578 |
efficientvit-sam-l2 | synthetic (1024x1024) | original (fp32) original portable kernels portable + torch.compile TensorRT fp32 | 34.4 34.4 17.8 6.54 10.8 9.65 (image encoder only) | 352 / 382 313 / 344 209 / 240 219 / 292 238 / 278 633 / 690 |
efficientvit-sam-xl0 | synthetic (1024x1024) | original (fp32) original portable kernels portable + torch.compile TensorRT fp32 | 46.9 28.2 19.0 9.75 14.2 22.7 (image encoder only) | 814 / 828 654 / 670 433 / 506 401 / 492 397 / 424 1288 / 1328 |
efficientvit-sam-xl1 | synthetic (1024x1024) | original (fp32) original portable kernels portable + torch.compile TensorRT fp32 | 72.6 40.9 28.9 15.3 22.9 38.4 (image encoder only) | 1143 / 1182 984 / 1022 586 / 676 569 / 686 562 / 616 1894 / 1960 |
Details
- Original code: https://github.com/mit-han-lab/efficientvit at
de7d7733cc03 - Code licence: Apache-2.0 (permissive); files:
LICENSE,LICENSE-segment-anything - Weights licence: Apache-2.0
- 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
- 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
- Kernel libraries:
fvm_conv,fvm_extra,fvm_mb,fvm_r3 - Variants:
efficientvit-sam-l0,efficientvit-sam-l1,efficientvit-sam-l2,efficientvit-sam-xl0,efficientvit-sam-xl1 - Outputs: pred_masks, iou_scores
- 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-l01080x1920 (0.2 GiB peak allocated, 0.2 reserved);efficientvit-sam-l11080x1920 (0.2 GiB peak allocated, 0.2 reserved);efficientvit-sam-l21080x1920 (0.2 GiB peak allocated, 0.3 reserved);efficientvit-sam-xl01080x1920 (0.4 GiB peak allocated, 0.5 reserved);efficientvit-sam-xl11080x1920 (0.6 GiB peak allocated, 0.7 reserved) efficientvit-sam-l01024x1024, first call: portable + torch.compile 25 s (cold Inductor cache), TensorRT fp32 20 s (ONNX + engine).efficientvit-sam-l11024x1024, first call: portable + torch.compile 25 s (cold Inductor cache), TensorRT fp32 22 s (ONNX + engine).efficientvit-sam-l21024x1024, first call: portable + torch.compile 26 s (cold Inductor cache), TensorRT fp32 24 s (ONNX + engine).efficientvit-sam-xl01024x1024, first call: portable + torch.compile 24 s (cold Inductor cache), TensorRT fp32 30 s (ONNX + engine).efficientvit-sam-xl11024x1024, first call: portable + torch.compile 27 s (cold Inductor cache), TensorRT fp32 37 s (ONNX + engine).efficientvit-sam-l0original (fp32) 1024x1024: upstream EfficientViTSamPredictor.set_image + predict (centre point, multimask_output=True)efficientvit-sam-l0original 1024x1024: torch.autocast(float16) around the call; upstream EfficientViTSamPredictor.set_image + predict (centre point, multimask_output=True)efficientvit-sam-l1original (fp32) 1024x1024: upstream EfficientViTSamPredictor.set_image + predict (centre point, multimask_output=True)efficientvit-sam-l1original 1024x1024: torch.autocast(float16) around the call; upstream EfficientViTSamPredictor.set_image + predict (centre point, multimask_output=True)efficientvit-sam-l2original (fp32) 1024x1024: upstream EfficientViTSamPredictor.set_image + predict (centre point, multimask_output=True)efficientvit-sam-l2original 1024x1024: torch.autocast(float16) around the call; upstream EfficientViTSamPredictor.set_image + predict (centre point, multimask_output=True)efficientvit-sam-xl0original (fp32) 1024x1024: upstream EfficientViTSamPredictor.set_image + predict (centre point, multimask_output=True)efficientvit-sam-xl0original 1024x1024: torch.autocast(float16) around the call; upstream EfficientViTSamPredictor.set_image + predict (centre point, multimask_output=True)efficientvit-sam-xl1original (fp32) 1024x1024: upstream EfficientViTSamPredictor.set_image + predict (centre point, multimask_output=True)efficientvit-sam-xl1original 1024x1024: torch.autocast(float16) around the call; upstream EfficientViTSamPredictor.set_image + predict (centre point, multimask_output=True)efficientvit-sam-l0load / first call: original 0.35 s / 0.817 s, portable 1.36 s / 0.743 s, kernels 0.81 s / 0.239 sefficientvit-sam-l1load / first call: original 0.31 s / 0.032 s, portable 0.86 s / 0.667 s, kernels 0.9 s / 0.235 sefficientvit-sam-l2load / first call: original 0.39 s / 0.037 s, portable 0.93 s / 0.667 s, kernels 1.0 s / 0.24 sefficientvit-sam-xl0load / first call: original 0.62 s / 0.592 s, portable 2.67 s / 0.519 s, kernels 2.14 s / 0.259 sefficientvit-sam-xl1load / first call: original 1.06 s / 0.041 s, portable 3.24 s / 0.531 s, kernels 3.21 s / 0.238 s- Protocol, first call, 3 warm-up, peak reset, median of 3 rounds x median of 5
Measured
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 | portable fp32 | 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.62 / 50.57 | 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.44 / 51.22 | 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.33 / 52.20 | 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 | 59.01 / 54.48 | 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.45 / 54.84 | 59.43 / 54.85 |
Measured on portable: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-10; portable32: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 44640884, 2026-11-17; kernels: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-10.
Parity
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).
| variant | kernels error vs original, mean / p99 | GPU, torch | kernels used |
|---|---|---|---|
efficientvit-sam-l0 | 0.00977 / 0.02641 | RTX 5060 Ti, torch 2.14.1+cu130 | fvm_conv@f1d064e539e1:sm_120, fvm_extra@3208ce525a91:sm_120, fvm_mb@720dd3f29bf7:sm_120, fvm_r3@f54eb890e23c:sm_120 |
efficientvit-sam-l1 | 0.0096 / 0.03486 | RTX 5060 Ti, torch 2.14.1+cu130 | fvm_conv@f1d064e539e1:sm_120, fvm_extra@3208ce525a91:sm_120, fvm_mb@720dd3f29bf7:sm_120, fvm_r3@f54eb890e23c:sm_120 |
efficientvit-sam-l2 | 0.01609 / 0.04618 | RTX 5060 Ti, torch 2.14.1+cu130 | fvm_conv@f1d064e539e1:sm_120, fvm_extra@3208ce525a91:sm_120, fvm_mb@720dd3f29bf7:sm_120, fvm_r3@f54eb890e23c:sm_120 |
efficientvit-sam-xl0 | 0.00539 / 0.01405 | RTX 5060 Ti, torch 2.14.1+cu130 | fvm_conv@f1d064e539e1:sm_120, fvm_extra@3208ce525a91:sm_120, fvm_mb@720dd3f29bf7:sm_120, fvm_r3@f54eb890e23c:sm_120 |
efficientvit-sam-xl1 | 0.00311 / 0.00859 | RTX 5060 Ti, torch 2.14.1+cu130 | fvm_conv@f1d064e539e1:sm_120, fvm_extra@3208ce525a91:sm_120, fvm_mb@720dd3f29bf7:sm_120, fvm_r3@f54eb890e23c:sm_120 |
Limitations
- Kernels keep CUDA graphs: their private pool and static outputs stay reserved, so peak reserved is ~85 MiB above portable (peak allocated is not);
cuda_graphs=falseorrelease_graphs()frees it.
Example output
One fixed input through this checkpoint, the same for every model of the task (kernels · float16 · NVIDIA GeForce RTX 5060 Ti). Prompt: one foreground point.
Input: A cup of coffee, Rachel Michetti (CC0).