Models · Promptable segmentation

Segment Anything (SAM)

Segment Anything: masks from clicks, boxes or mask prompts, in sizes B, L and H.

stable Fork of facebookresearch/segment-anything@dca509f · backends: portable, kernels

Checkpoint

Paper 2023 Added in 0.1.0 Evaluated with 0.2.0

Kernels, RTX 5060 Ti 16 GB 37.0 ms 1024x1024, fp16
vs the faster original 2.7× original fp16: 98.2 ms
Peak memory 377 MiB original: 1,769 MiB
Accuracy vs original fp32 −0.02 kernels mIoU best of 3 %, COCO val2017 (52.91 original)

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("sam-vit-b")  # 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 sam-vit-b

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.

BackenddtypeTime per call (ms)vs original fp16Peak memory
allocated / reserved
Load (s)First call (s)
Original fp32fp32 1680.58×2,798 MiB/2,832 MiB4.20.50
Original fp16torch.autocast(float16) around the callfp16 98.2–1,769 MiB/1,802 MiB0.80.18
Portable fp32fp32not measured ––––
Portablefp16 48.32.0×378 MiB/420 MiB0.50.05
Kernelsfp16 37.02.7×377 MiB/420 MiB0.20.04
Portable + torch.compile 40.92.4×362 MiB/400 MiB15 (build)–
TensorRT fp16image encoder onlyfp16 27.33.6×322 MiBenginenot comparable36 (build)–

Measured on RTX 5060 Ti 16 GB, torch 2.14.1+cu130, 2026-11-03 to 2026-11-06. Median of 5 after 3 warm-up, uint8 CUDA input (synthetic for bench_inputs sizes), card defaults; gc before each load; peak = max over the first call and the timed calls. 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

DeviceBackenddtypems / callPeak memoryOutput vs referenceInput
Apple M1 Pro 16 GB MPS, torch 2.14.1, 2026-11-14Originalfp32841 4,783 MiB process–1024x1024
Portablefp16600 3,762 MiB processmatches1024x1024
Portablefp32631 4,362 MiB processmatches1024x1024
Kernelsfp16not implemented–1024x1024
NVIDIA L4 CUDA, torch 2.14.1+cu130, 2026-11-07Portablefp1648.6 341 MiB/360 MiB–1024x1024
Kernelsfp1640.7 341 MiB/380 MiB–1024x1024
NVIDIA L40S CUDA, torch 2.14.1+cu130, 2026-11-07Portablefp1617.6 341 MiB/360 MiB–1024x1024
Kernelsfp1615.7 341 MiB/380 MiB–1024x1024
NVIDIA A10 CUDA, torch 2.14.1+cu130, 2026-11-07Portablefp1639.7 341 MiB/360 MiB–1024x1024
Kernelsfp1635.1 341 MiB/380 MiB–1024x1024
NVIDIA A100-SXM4-40GB CUDA, torch 2.14.1+cu130, 2026-11-08Portablefp1620.0 341 MiB/360 MiB–1024x1024
Kernelsfp1619.2 341 MiB/380 MiB–1024x1024
NVIDIA RTX PRO 6000 CUDA, torch 2.14.1+cu130, 2026-11-08Portablefp1611.2 365 MiB/400 MiB–1024x1024
Kernelsfp1610.3 365 MiB/420 MiB–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 LICENSE
Weights
Apache-2.0 source
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

Our reading of the licences, not legal advice.

Weights

sam_vit_b_01ec64.pth 375 MB· hosted on Meta (fbaipublicfiles)

fastforks downloads and checks these files on first use (fastforks download sam-vit-b).

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 %

RundtypemIoU best of 3 % ↑mIoU single % ↑Δ mIoU best of 3 % vs fp32 originalimagesms / image
Original fp32fp3252.9150.31 reference 500 176
Original fp16fp1653.0850.39 +0.17 500 105
Portable fp32not measured
Portablefp1652.9150.31 ±0.00 500 53.4
Kernelsfp1652.8950.32 −0.02 500 42.0

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: RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-06; portable, kernels: RTX 5060 Ti, torch 2.14.1+cu130, fastforks 939adfe8, 2026-11-06.

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| <= 3 % and p99 <= 15 % of the reference's median |value| (absolute error of the output pred_masks).

CheckToleranceMeasured
CPU fp32, max |diff|≤ 0.002 (relative)not recorded
GPU default dtypes, mean |diff|≤ 0.03 (relative)0.00044 (relative)
GPU default dtypes, p99 |diff|≤ 0.15 (relative)0.00203 (relative)

Recorded for sam-vit-b on RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-07, with these kernels: dpt_fused

Details

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.

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 (387 MiB allocated)
Outputs
pred_masks, iou_scores
Checkpoint
embed_dim=768, depth=12, num_heads=12
CUDA kernels
  • dpt_fusedfused fp16 matrix multiplies and convolutions for DINOv2 backbones and DPT depth heads
Apple (MPS)
fp32, fp16
Full reference, generated from the repository

Segment Anything: masks from clicks, boxes or mask prompts, in sizes B, L and H.

Commercial use: yes.

variantinputbackendtime (ms)peak memory (MiB, allocated / reserved)
sam-vit-bsynthetic (1024x1024)original (fp32)
original
portable
kernels
portable + torch.compile
TensorRT fp16
168
98.2
48.3
37.0
40.9
27.3 (image encoder only)
2798 / 2832
1769 / 1802
378 / 420
377 / 420
362 / 400
545 / 582
sam-vit-lsynthetic (1024x1024)original (fp32)
original
portable
kernels
portable + torch.compile
TensorRT fp16
406
197
116
81.5
97.2
67.5 (image encoder only)
4428 / 4474
3411 / 3464
833 / 1262
831 / 862
793 / 862
1453 / 1520
sam-vit-hsynthetic (1024x1024)original (fp32)
original
portable
kernels
portable + torch.compile
TensorRT fp16
734
306
214
143
188
124 (image encoder only)
5702 / 5754
5295 / 5404
1484 / 2524
1480 / 1524
1436 / 1484
2744 / 2784
Details
  • Original code: https://github.com/facebookresearch/segment-anything at dca509f
  • Code licence: Apache-2.0 (permissive); files: LICENSE
  • Weights licence: Apache-2.0
  • Licence evidence: https://github.com/facebookresearch/segment-anything/blob/main/README.md (License section: model checkpoints and code under Apache 2.0)
  • 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
  • Kernel libraries: dpt_fused
  • Variants: sam-vit-b, sam-vit-l, sam-vit-h
  • 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): sam-vit-b 1080x1920 (0.4 GiB peak allocated, 0.5 reserved); sam-vit-l 1080x1920 (0.8 GiB peak allocated, 1.0 reserved); sam-vit-h 1080x1920 (1.5 GiB peak allocated, 1.9 reserved)
  • sam-vit-b 1024x1024, first call: portable + torch.compile 15 s (cold Inductor cache), TensorRT fp16 36 s (ONNX + engine).
  • sam-vit-l 1024x1024, first call: portable + torch.compile 33 s (cold Inductor cache), TensorRT fp16 53 s (ONNX + engine).
  • sam-vit-h 1024x1024, first call: portable + torch.compile 43 s (cold Inductor cache), TensorRT fp16 70 s (ONNX + engine).
  • sam-vit-b original 1024x1024: torch.autocast(float16) around the call
  • sam-vit-l original 1024x1024: torch.autocast(float16) around the call
  • sam-vit-h original 1024x1024: torch.autocast(float16) around the call
  • sam-vit-b load / first call: original 0.75 s / 0.176 s, portable 0.46 s / 0.048† s, kernels 0.17† s / 0.037† s
  • sam-vit-l load / first call: original 1.8 s / 0.268 s, portable 1.21 s / 0.116† s, kernels 0.43† s / 0.081† s
  • sam-vit-h load / first call: original 4.61 s / 0.376 s, portable 2.45 s / 0.214† s, kernels 0.89† s / 0.143† s
  • † measured in the speed sweep after the portable load (or an earlier size) in the same process: file cache and kernels are warm, so the time is lower than a fresh start.
  • Protocol, median of 5 after 3 warm-up, uint8 CUDA input (synthetic for bench_inputs sizes), card defaults; gc before each load; peak = max over the first call and the timed calls

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.

variantdatasetoriginal fp32original fp16portablekernelsnote
sam-vit-bCOCO val2017, every 10th image, point prompts, mIoU best of 3 / single mask %52.91 / 50.3153.08 / 50.3952.91 / 50.3152.89 / 50.32
sam-vit-lCOCO val2017, every 10th image, point prompts, mIoU best of 3 / single mask %57.89 / 53.3257.76 / 53.3157.84 / 53.3257.85 / 53.33
sam-vit-hCOCO val2017, every 10th image, point prompts, mIoU best of 3 / single mask %57.93 / 53.1357.92 / 53.1357.97 / 53.1257.99 / 53.12

Measured on NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 939adfe8, 2026-11-06.

Parity

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).

variantkernels error vs original, mean / p99GPU, torchkernels used
sam-vit-b0.00044 / 0.00203RTX 5060 Ti, torch 2.14.1+cu130dpt_fused@48e0065bb7cf:sm_120
sam-vit-l0.01589 / 0.06758RTX 5060 Ti, torch 2.14.1+cu130dpt_fused@48e0065bb7cf:sm_120
sam-vit-h0.00329 / 0.01177RTX 5060 Ti, torch 2.14.1+cu130dpt_fused@48e0065bb7cf:sm_120

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
Output
A cup of coffee, input
Input · 100%

Input: A cup of coffee, Rachel Michetti (CC0).