Segment Anything (SAM) (fastforks)
Segment Anything (Kirillov et al. 2023): promptable segmentation with a ViT image encoder (windowed + global attention, relative positions) and a light prompt encoder / mask decoder; masks from points, boxes and mask logits. 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: https://github.com/kleinicke/fastforks. Kernels for the kernels backend: https://huggingface.co/fastforks/kernels. Original code: https://github.com/facebookresearch/segment-anything at dca509f.
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.
| variant | weights (author link) | SHA-256 | weights licence | commercial use |
|---|---|---|---|---|
sam-vit-b@1 |
sam_vit_b_01ec64.pth | ec2df6273261 |
Apache-2.0 | yes |
sam-vit-h@1 |
sam_vit_h_4b8939.pth | a7bf3b02f3eb |
Apache-2.0 | yes |
sam-vit-l@1 |
sam_vit_l_0b3195.pth | 3adcc4315b64 |
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.
Training data: 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://github.com/facebookresearch/segment-anything/blob/main/README.md (License section: model checkpoints and code under Apache 2.0)
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): sam-vit-b 1080x1920 (0.4 GiB peak allocated, 0.5 reserved); sam-vit-h 1080x1920 (1.5 GiB peak allocated, 1.9 reserved); sam-vit-l 1080x1920 (0.8 GiB peak allocated, 1.0 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 |
|---|---|---|---|---|---|---|---|---|---|
sam-vit-b |
168 | 98.2 | 48.3 | 37.0 | 2.7x | 1.3x | 1769 / 1802 | 378 / 420 | 377 / 420 |
sam-vit-h |
734 | 306 | 214 | 143 | 2.1x | 1.5x | 5295 / 5404 | 1484 / 2524 | 1480 / 1524 |
sam-vit-l |
406 | 197 | 116 | 81.5 | 2.4x | 1.4x | 3411 / 3464 | 833 / 1262 | 831 / 862 |
Startup and first call
| model | load (s): original | portable | kernels | first call (s): original | portable | kernels |
|---|---|---|---|---|---|---|
sam-vit-b |
0.75 | 0.46 | 0.17โ | 0.18 | 0.05โ | 0.04โ |
sam-vit-h |
4.61 | 2.45 | 0.89โ | 0.38 | 0.21โ | 0.14โ |
sam-vit-l |
1.80 | 1.21 | 0.43โ | 0.27 | 0.12โ | 0.08โ |
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) |
|---|---|---|---|---|---|---|---|---|---|---|---|
sam-vit-b |
1024x1024 | 48.3 ms | 40.9 ms | 27.3 ms (image encoder only) | 37.0 ms | 14.5 s | 36.4 s | 378 / 420 | 362 / 400 | 377 / 420 | 545 / 582 |
sam-vit-h |
1024x1024 | 214 ms | 188 ms | 124 ms (image encoder only) | 143 ms | 42.6 s | 69.7 s | 1484 / 2524 | 1436 / 1484 | 1480 / 1524 | 2744 / 2784 |
sam-vit-l |
1024x1024 | 116 ms | 97.2 ms | 67.5 ms (image encoder only) | 81.5 ms | 32.9 s | 53.4 s | 833 / 1262 | 793 / 862 | 831 / 862 | 1453 / 1520 |
Fixed-size speed and peak memory, all models
| model | mode | 480x640 | 720x1280 | 1080x1920 | 12 MP 3000x4000 |
|---|---|---|---|---|---|
sam-vit-b |
portable | 48.6 ms / 367 / 482 | 48.6 ms / 374 / 482 | 49.0 ms / 387 / 484 | - |
sam-vit-b |
kernels | 37.3 ms / 364 / 424 | 37.4 ms / 370 / 404 | 38.1 ms / 384 / 432 | - |
sam-vit-h |
portable | 216.1 ms / 1490 / 1882 | 215.4 ms / 1496 / 1902 | 215.7 ms / 1510 / 1916 | - |
sam-vit-h |
kernels | 143.6 ms / 1459 / 1712 | 144.4 ms / 1466 / 1704 | 145.1 ms / 1479 / 1714 | - |
sam-vit-l |
portable | 117.2 ms / 814 / 1052 | 116.5 ms / 820 / 1060 | 117.5 ms / 834 / 1048 | - |
sam-vit-l |
kernels | 82.0 ms / 812 / 930 | 81.6 ms / 818 / 946 | 83.2 ms / 833 / 922 | - |
Fixed-size cells: time (ms) / peak allocated / peak reserved memory (MiB).
Hardware, protocol and caveats: benchmarks (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 |
|---|---|---|---|---|---|---|
sam-vit-b |
COCO val2017, every 10th image, point prompts, mIoU best of 3 / single mask % | 52.91 / 50.31 | 53.08 / 50.39 | 52.91 / 50.31 | 52.89 / 50.32 | |
sam-vit-l |
COCO val2017, every 10th image, point prompts, mIoU best of 3 / single mask % | 57.89 / 53.32 | 57.76 / 53.31 | 57.84 / 53.32 | 57.85 / 53.33 | |
sam-vit-h |
COCO val2017, every 10th image, point prompts, mIoU best of 3 / single mask % | 57.93 / 53.13 | 57.92 / 53.13 | 57.97 / 53.12 | 57.99 / 53.12 |
Measured on NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 939adfe8, 2026-11-06.
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| <= 3 % and p99 <= 15 % of the reference's median |value| (absolute error of the output pred_masks).
Usage
from fastforks import promptable_segmentation
model = promptable_segmentation.load("sam-vit-b") # 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 https://github.com/kleinicke/fastforks). Other variants: sam-vit-b, sam-vit-h, sam-vit-l.
Kernels backend
promptable_segmentation.load("sam-vit-b", mode="kernels") runs our CUDA kernels (dpt_fused). 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.