Models · Promptable segmentation

Segment Anything 2.1 (SAM 2.1)

Segment Anything 2.1 in image mode: masks from clicks, boxes or mask prompts, in four sizes.

stable Fork of facebookresearch/sam2@2b90b9f · backends: portable, kernels

Checkpoint

Paper 2024 Added in 0.1.0 Evaluated with 0.2.0

Kernels, RTX 5060 Ti 16 GB 13.9 ms 1024x1024, fp16
vs the faster original 2.7× original fp16: 38.0 ms
Peak memory 316 MiB original: 577 MiB
Accuracy vs original fp32 −0.02 kernels mIoU best of 3 %, COCO val2017 (57.63 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("sam2.1-hiera-tiny")  # 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 sam2.1-hiera-tiny

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 66.30.57×622 MiB/676 MiB3.80.40
Original fp16torch.autocast(float16) around the callfp16 38.0–577 MiB/636 MiB0.40.15
Portable fp32fp32not measured ––––
Portablefp16 16.62.3×304 MiB/382 MiB0.30.02
Kernelsfp16 13.92.7×316 MiB/362 MiB0.10.01
Portable + torch.compile 14.22.7×270 MiB/322 MiB13 (build)–
TensorRT fp16image encoder onlyfp16 8.564.4×266 MiBenginenot comparable34 (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-14Originalfp32193 3,044 MiB process–1024x1024
Portablefp16129 1,514 MiB processmatches1024x1024
Portablefp32241 2,581 MiB processmatches1024x1024
Kernelsfp16not implemented–1024x1024
NVIDIA L4 CUDA, torch 2.14.1+cu130, 2026-11-07Portablefp1619.1 268 MiB/302 MiB–1024x1024
Kernelsfp1617.6 280 MiB/302 MiB–1024x1024
NVIDIA L40S CUDA, torch 2.14.1+cu130, 2026-11-07Portablefp168.58 268 MiB/302 MiB–1024x1024
Kernelsfp168.14 280 MiB/302 MiB–1024x1024
NVIDIA A10 CUDA, torch 2.14.1+cu130, 2026-11-07Portablefp1617.7 268 MiB/302 MiB–1024x1024
Kernelsfp1615.6 280 MiB/302 MiB–1024x1024
NVIDIA A100-SXM4-40GB CUDA, torch 2.14.1+cu130, 2026-11-08Portablefp1612.0 268 MiB/302 MiB–1024x1024
Kernelsfp1612.2 280 MiB/302 MiB–1024x1024
NVIDIA RTX PRO 6000 CUDA, torch 2.14.1+cu130, 2026-11-08Portablefp165.15 292 MiB/322 MiB–1024x1024
Kernelsfp165.11 304 MiB/342 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 and the SA-V video dataset (plus internal data) per the paper; SA-V itself is under CC BY 4.0, SA-1B under its research licence

Our reading of the licences, not legal advice.

Weights

sam2.1_hiera_tiny.pt 156 MB· hosted on Meta (fbaipublicfiles)

fastforks downloads and checks these files on first use (fastforks download sam2.1-hiera-tiny).

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 fp32fp3257.6357.69 reference 500 63.2
Original fp16bf1657.5657.64 −0.07 500 29.9
Portable fp32not measured
Portablefp1657.6257.72 −0.01 500 22.9
Kernelsfp1657.6157.77 −0.02 500 20.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: 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.

DAVIS 2017 val

every 3rd sequence, video tracking, J&F / J / F %

Rundtypejf ↑j ↑f ↑Δ jf vs fp32 originalobjectsms / object
Original fp32fp3283.8079.7087.90 reference 19 –
Original fp16bf1683.8679.5088.22 +0.06 19 –
Portable fp32not measured
Portablefp1683.7679.6887.84 −0.04 19 –
Kernelsfp1683.7779.6887.85 −0.03 19 –

Semi-supervised: every object's first-frame mask as `input_masks`, `video` forward at 480p; the lower object id wins where masks overlap; J (IoU) and F (boundary) as davis2017-evaluation, mean over objects. Original = the authors’ code, same checkpoint and protocol. Measured on original fp32, original fp16: RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-12; portable, kernels: RTX 5060 Ti, torch 2.14.1+cu130, fastforks 84ba91d4, 2026-11-12.

DAVIS 2017 val

video tracking, J&F / J / F %

Rundtypejf ↑j ↑f ↑Δ jf vs fp32 originalobjectsms / object
Original fp32fp3287.5484.8390.26 reference 61 –
Original fp16bf1687.6584.8690.45 +0.11 61 –
Portable fp32not measured
Portablefp1687.5384.8490.23 −0.01 61 –
Kernelsfp1687.5484.8490.24 ±0.00 61 –

Semi-supervised: every object's first-frame mask as `input_masks`, `video` forward at 480p; the lower object id wins where masks overlap; J (IoU) and F (boundary) as davis2017-evaluation, mean over objects. Original = the authors’ code, same checkpoint and protocol. Measured on original fp32, original fp16: RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-12; portable, kernels: RTX 5060 Ti, torch 2.14.1+cu130, fastforks 84ba91d4, 2026-11-12.

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.00122 (relative)
GPU default dtypes, p99 |diff|≤ 0.15 (relative)0.00428 (relative)

Recorded for sam2.1-hiera-tiny on RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-13, with these kernels: dpt_fused

Details

Segment Anything 2.1 (Ravi et al. 2024), image mode: promptable segmentation with a hierarchical Hiera image encoder, an FPN neck and the SAM prompt encoder / mask decoder with high-resolution skip features; masks from points, boxes and mask logits. `video` follows objects prompted on the first frame through a video with the original memory attention / memory encoder (`SAM2VideoPredictor`, forward, memory features in bfloat16 as upstream); the memory side has no fused kernels yet. Option `samurai` tracks as SAMURAI (Yang et al. 2024: a Kalman filter on the mask box picks among the multimask outputs, and the memory keeps only confident frames); upstream SAMURAI tracks one object, here every object has its own filter and memory. 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 (305 MiB allocated)
Options
  • samurai=false· changes the output
Outputs
pred_masks, iou_scores
Checkpoint
embed_dim=96, num_heads=1, stages=[1,2,7,2], global_att_blocks=[5,7,9], window_spec=[8,4,14,7], pos_embed_size=[7,7]
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 2.1 in image mode: masks from clicks, boxes or mask prompts, in four sizes.

Commercial use: yes.

variantinputbackendtime (ms)peak memory (MiB, allocated / reserved)
sam2.1-hiera-tinysynthetic (1024x1024)original (fp32)
original
portable
kernels
portable + torch.compile
TensorRT fp16
66.3
38.0
16.6
13.9
14.2
8.56 (image encoder only)
622 / 676
577 / 636
304 / 382
316 / 362
270 / 322
414 / 446
sam2.1-hiera-smallsynthetic (1024x1024)original (fp32)
original
portable
kernels
portable + torch.compile
TensorRT fp16
74.8
41.8
18.8
15.6
14.9
9.93 (image encoder only)
649 / 698
618 / 662
318 / 366
330 / 386
283 / 326
429 / 452
sam2.1-hiera-base-plussynthetic (1024x1024)original (fp32)
original
portable
kernels
portable + torch.compile
TensorRT fp16
107
47.2
31.9
25.4
26.4
16.7 (image encoder only)
830 / 868
823 / 870
400 / 444
414 / 464
365 / 404
588 / 620
sam2.1-hiera-largesynthetic (1024x1024)original (fp32)
original
portable
kernels
portable + torch.compile
TensorRT fp16
242
86.4
68.0
49.1
59.5
38.1 (image encoder only)
1474 / 1518
1656 / 1724
730 / 768
748 / 808
678 / 748
1212 / 1232
Details
  • Original code: https://github.com/facebookresearch/sam2 at 2b90b9f
  • Code licence: Apache-2.0 (permissive); files: LICENSE
  • Weights licence: Apache-2.0
  • Licence evidence: https://github.com/facebookresearch/sam2/blob/main/README.md (License section: model checkpoints and code under Apache 2.0)
  • Training data: SA-1B and the SA-V video dataset (plus internal data) per the paper; SA-V itself is under CC BY 4.0, SA-1B under its research licence
  • Options: samurai = False
  • Kernel libraries: dpt_fused
  • Variants: sam2.1-hiera-tiny, sam2.1-hiera-small, sam2.1-hiera-base-plus, sam2.1-hiera-large
  • 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): sam2.1-hiera-tiny 1080x1920 (0.3 GiB peak allocated, 0.4 reserved); sam2.1-hiera-small 1080x1920 (0.3 GiB peak allocated, 0.4 reserved); sam2.1-hiera-base-plus 1080x1920 (0.4 GiB peak allocated, 0.6 reserved); sam2.1-hiera-large 1080x1920 (0.7 GiB peak allocated, 0.9 reserved)
  • sam2.1-hiera-tiny 1024x1024, first call: portable + torch.compile 13 s (cold Inductor cache), TensorRT fp16 34 s (ONNX + engine).
  • sam2.1-hiera-small 1024x1024, first call: portable + torch.compile 24 s (cold Inductor cache), TensorRT fp16 40 s (ONNX + engine).
  • sam2.1-hiera-base-plus 1024x1024, first call: portable + torch.compile 28 s (cold Inductor cache), TensorRT fp16 44 s (ONNX + engine).
  • sam2.1-hiera-large 1024x1024, first call: portable + torch.compile 39 s (cold Inductor cache), TensorRT fp16 55 s (ONNX + engine).
  • sam2.1-hiera-tiny original 1024x1024: torch.autocast(float16) around the call
  • sam2.1-hiera-small original 1024x1024: torch.autocast(float16) around the call
  • sam2.1-hiera-base-plus original 1024x1024: torch.autocast(float16) around the call
  • sam2.1-hiera-large original 1024x1024: torch.autocast(float16) around the call
  • sam2.1-hiera-tiny load / first call: original 0.41 s / 0.147 s, portable 0.25 s / 0.017† s, kernels 0.11† s / 0.014† s
  • sam2.1-hiera-small load / first call: original 0.48 s / 0.136 s, portable 0.36 s / 0.019† s, kernels 0.13† s / 0.016† s
  • sam2.1-hiera-base-plus load / first call: original 0.74 s / 0.143 s, portable 0.8 s / 0.032 s (840x1297), kernels 1.15 s / 0.026 s (840x1297)
  • sam2.1-hiera-large load / first call: original 1.95 s / 0.184 s, portable 1.46 s / 0.069 s (840x1297), kernels 2.07 s / 0.05 s (840x1297)
  • † 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, sam2.1-hiera-tiny, sam2.1-hiera-small: 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
  • Protocol, sam2.1-hiera-base-plus, sam2.1-hiera-large: 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. Semi-supervised: every object's first-frame mask as input_masks, video forward at 480p; the lower object id wins where masks overlap; J (IoU) and F (boundary) as davis2017-evaluation, mean over objects. Original = the original code named under Details, same checkpoint and protocol.

variantdatasetoriginal fp32original fp16portablekernelsnote
sam2.1-hiera-tinyCOCO val2017, every 10th image, point prompts, mIoU best of 3 / single mask %57.63 / 57.6957.56 / 57.6457.62 / 57.7257.61 / 57.77
sam2.1-hiera-tinyDAVIS 2017 val, every 3rd sequence, video tracking, J&F / J / F %83.80 / 79.70 / 87.9083.86 / 79.50 / 88.2283.76 / 79.68 / 87.8483.77 / 79.68 / 87.85
sam2.1-hiera-tinyDAVIS 2017 val, video tracking, J&F / J / F %87.54 / 84.83 / 90.2687.65 / 84.86 / 90.4587.53 / 84.84 / 90.2387.54 / 84.84 / 90.24
sam2.1-hiera-smallCOCO val2017, every 10th image, point prompts, mIoU best of 3 / single mask %59.39 / 58.4659.34 / 58.4259.38 / 58.4959.38 / 58.47
sam2.1-hiera-smallDAVIS 2017 val, every 3rd sequence, video tracking, J&F / J / F %84.08 / 80.26 / 87.9084.11 / 80.28 / 87.9384.13 / 80.31 / 87.9484.13 / 80.31 / 87.95
sam2.1-hiera-base-plusCOCO val2017, every 10th image, point prompts, mIoU best of 3 / single mask %58.79 / 58.6758.73 / 58.5758.81 / 58.7158.82 / 58.73
sam2.1-hiera-base-plusDAVIS 2017 val, every 3rd sequence, video tracking, J&F / J / F %83.88 / 80.62 / 87.1483.88 / 80.61 / 87.1683.87 / 80.61 / 87.1383.86 / 80.60 / 87.12
sam2.1-hiera-largeCOCO val2017, every 10th image, point prompts, mIoU best of 3 / single mask %64.88 / 64.7164.77 / 64.7364.86 / 64.6864.87 / 64.70
sam2.1-hiera-largeDAVIS 2017 val, every 3rd sequence, video tracking, J&F / J / F %85.91 / 82.21 / 89.6285.98 / 82.25 / 89.7185.92 / 82.22 / 89.6385.92 / 82.22 / 89.63

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

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
sam2.1-hiera-tiny0.00122 / 0.00428RTX 5060 Ti, torch 2.14.1+cu130dpt_fused@48e0065bb7cf:sm_120
sam2.1-hiera-small0.00539 / 0.01677RTX 5060 Ti, torch 2.14.1+cu130dpt_fused@48e0065bb7cf:sm_120
sam2.1-hiera-base-plus0.00245 / 0.00842RTX 5060 Ti, torch 2.14.1+cu130dpt_fused@48e0065bb7cf:sm_120
sam2.1-hiera-large0.01872 / 0.08865RTX 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).