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
- Paper SAM 2: Segment Anything in Images and Videos ICLR 2025 (oral) · first released 1 Aug 2024
Paper 2024 Added in 0.1.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("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.
| Backend | dtype | Time per call (ms) | vs original fp16 | Peak memory allocated / reserved | Load (s) | First call (s) |
|---|---|---|---|---|---|---|
| Original fp32 | fp32 | 66.3 | 0.57× | 622 MiB/676 MiB | 3.8 | 0.40 |
| Original fp16torch.autocast(float16) around the call | fp16 | 38.0 | – | 577 MiB/636 MiB | 0.4 | 0.15 |
| Portable fp32 | fp32 | not measured | – | – | – | – |
| Portable | fp16 | 16.6 | 2.3× | 304 MiB/382 MiB | 0.3 | 0.02 |
| Kernels | fp16 | 13.9 | 2.7× | 316 MiB/362 MiB | 0.1 | 0.01 |
| Portable + torch.compile | 14.2 | 2.7× | 270 MiB/322 MiB | 13 (build) | – | |
| TensorRT fp16image encoder only | fp16 | 8.56 | 4.4× | 266 MiBenginenot comparable | 34 (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
| Device | Backend | dtype | ms / call | Peak memory | Output vs reference | Input |
|---|---|---|---|---|---|---|
| Apple M1 Pro 16 GB MPS, torch 2.14.1, 2026-11-14 | Original | fp32 | 193 | 3,044 MiB process | – | 1024x1024 |
| Portable | fp16 | 129 | 1,514 MiB process | matches | 1024x1024 | |
| Portable | fp32 | 241 | 2,581 MiB process | matches | 1024x1024 | |
| Kernels | fp16 | not implemented | – | 1024x1024 | ||
| NVIDIA L4 CUDA, torch 2.14.1+cu130, 2026-11-07 | Portable | fp16 | 19.1 | 268 MiB/302 MiB | – | 1024x1024 |
| Kernels | fp16 | 17.6 | 280 MiB/302 MiB | – | 1024x1024 | |
| NVIDIA L40S CUDA, torch 2.14.1+cu130, 2026-11-07 | Portable | fp16 | 8.58 | 268 MiB/302 MiB | – | 1024x1024 |
| Kernels | fp16 | 8.14 | 280 MiB/302 MiB | – | 1024x1024 | |
| NVIDIA A10 CUDA, torch 2.14.1+cu130, 2026-11-07 | Portable | fp16 | 17.7 | 268 MiB/302 MiB | – | 1024x1024 |
| Kernels | fp16 | 15.6 | 280 MiB/302 MiB | – | 1024x1024 | |
| NVIDIA A100-SXM4-40GB CUDA, torch 2.14.1+cu130, 2026-11-08 | Portable | fp16 | 12.0 | 268 MiB/302 MiB | – | 1024x1024 |
| Kernels | fp16 | 12.2 | 280 MiB/302 MiB | – | 1024x1024 | |
| NVIDIA RTX PRO 6000 CUDA, torch 2.14.1+cu130, 2026-11-08 | Portable | fp16 | 5.15 | 292 MiB/322 MiB | – | 1024x1024 |
| Kernels | fp16 | 5.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 %
| Run | dtype | mIoU best of 3 % ↑ | mIoU single % ↑ | Δ mIoU best of 3 % vs fp32 original | images | ms / image |
|---|---|---|---|---|---|---|
| Original fp32 | fp32 | 57.63 | 57.69 | reference | 500 | 63.2 |
| Original fp16 | bf16 | 57.56 | 57.64 | −0.07 | 500 | 29.9 |
| Portable fp32 | not measured | |||||
| Portable | fp16 | 57.62 | 57.72 | −0.01 | 500 | 22.9 |
| Kernels | fp16 | 57.61 | 57.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 %
| Run | dtype | jf ↑ | j ↑ | f ↑ | Δ jf vs fp32 original | objects | ms / object |
|---|---|---|---|---|---|---|---|
| Original fp32 | fp32 | 83.80 | 79.70 | 87.90 | reference | 19 | – |
| Original fp16 | bf16 | 83.86 | 79.50 | 88.22 | +0.06 | 19 | – |
| Portable fp32 | not measured | ||||||
| Portable | fp16 | 83.76 | 79.68 | 87.84 | −0.04 | 19 | – |
| Kernels | fp16 | 83.77 | 79.68 | 87.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 %
| Run | dtype | jf ↑ | j ↑ | f ↑ | Δ jf vs fp32 original | objects | ms / object |
|---|---|---|---|---|---|---|---|
| Original fp32 | fp32 | 87.54 | 84.83 | 90.26 | reference | 61 | – |
| Original fp16 | bf16 | 87.65 | 84.86 | 90.45 | +0.11 | 61 | – |
| Portable fp32 | not measured | ||||||
| Portable | fp16 | 87.53 | 84.84 | 90.23 | −0.01 | 61 | – |
| Kernels | fp16 | 87.54 | 84.84 | 90.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).
| Check | Tolerance | Measured |
|---|---|---|
| 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.
| variant | input | backend | time (ms) | peak memory (MiB, allocated / reserved) |
|---|---|---|---|---|
sam2.1-hiera-tiny | synthetic (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-small | synthetic (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-plus | synthetic (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-large | synthetic (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-tiny1080x1920 (0.3 GiB peak allocated, 0.4 reserved);sam2.1-hiera-small1080x1920 (0.3 GiB peak allocated, 0.4 reserved);sam2.1-hiera-base-plus1080x1920 (0.4 GiB peak allocated, 0.6 reserved);sam2.1-hiera-large1080x1920 (0.7 GiB peak allocated, 0.9 reserved) sam2.1-hiera-tiny1024x1024, first call: portable + torch.compile 13 s (cold Inductor cache), TensorRT fp16 34 s (ONNX + engine).sam2.1-hiera-small1024x1024, first call: portable + torch.compile 24 s (cold Inductor cache), TensorRT fp16 40 s (ONNX + engine).sam2.1-hiera-base-plus1024x1024, first call: portable + torch.compile 28 s (cold Inductor cache), TensorRT fp16 44 s (ONNX + engine).sam2.1-hiera-large1024x1024, first call: portable + torch.compile 39 s (cold Inductor cache), TensorRT fp16 55 s (ONNX + engine).sam2.1-hiera-tinyoriginal 1024x1024: torch.autocast(float16) around the callsam2.1-hiera-smalloriginal 1024x1024: torch.autocast(float16) around the callsam2.1-hiera-base-plusoriginal 1024x1024: torch.autocast(float16) around the callsam2.1-hiera-largeoriginal 1024x1024: torch.autocast(float16) around the callsam2.1-hiera-tinyload / first call: original 0.41 s / 0.147 s, portable 0.25 s / 0.017† s, kernels 0.11† s / 0.014† ssam2.1-hiera-smallload / first call: original 0.48 s / 0.136 s, portable 0.36 s / 0.019† s, kernels 0.13† s / 0.016† ssam2.1-hiera-base-plusload / 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-largeload / 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.
| variant | dataset | original fp32 | original fp16 | portable | kernels | note |
|---|---|---|---|---|---|---|
sam2.1-hiera-tiny | COCO val2017, every 10th image, point prompts, mIoU best of 3 / single mask % | 57.63 / 57.69 | 57.56 / 57.64 | 57.62 / 57.72 | 57.61 / 57.77 | |
sam2.1-hiera-tiny | DAVIS 2017 val, every 3rd sequence, video tracking, J&F / J / F % | 83.80 / 79.70 / 87.90 | 83.86 / 79.50 / 88.22 | 83.76 / 79.68 / 87.84 | 83.77 / 79.68 / 87.85 | |
sam2.1-hiera-tiny | DAVIS 2017 val, video tracking, J&F / J / F % | 87.54 / 84.83 / 90.26 | 87.65 / 84.86 / 90.45 | 87.53 / 84.84 / 90.23 | 87.54 / 84.84 / 90.24 | |
sam2.1-hiera-small | COCO val2017, every 10th image, point prompts, mIoU best of 3 / single mask % | 59.39 / 58.46 | 59.34 / 58.42 | 59.38 / 58.49 | 59.38 / 58.47 | |
sam2.1-hiera-small | DAVIS 2017 val, every 3rd sequence, video tracking, J&F / J / F % | 84.08 / 80.26 / 87.90 | 84.11 / 80.28 / 87.93 | 84.13 / 80.31 / 87.94 | 84.13 / 80.31 / 87.95 | |
sam2.1-hiera-base-plus | COCO val2017, every 10th image, point prompts, mIoU best of 3 / single mask % | 58.79 / 58.67 | 58.73 / 58.57 | 58.81 / 58.71 | 58.82 / 58.73 | |
sam2.1-hiera-base-plus | DAVIS 2017 val, every 3rd sequence, video tracking, J&F / J / F % | 83.88 / 80.62 / 87.14 | 83.88 / 80.61 / 87.16 | 83.87 / 80.61 / 87.13 | 83.86 / 80.60 / 87.12 | |
sam2.1-hiera-large | COCO val2017, every 10th image, point prompts, mIoU best of 3 / single mask % | 64.88 / 64.71 | 64.77 / 64.73 | 64.86 / 64.68 | 64.87 / 64.70 | |
sam2.1-hiera-large | DAVIS 2017 val, every 3rd sequence, video tracking, J&F / J / F % | 85.91 / 82.21 / 89.62 | 85.98 / 82.25 / 89.71 | 85.92 / 82.22 / 89.63 | 85.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).
| variant | kernels error vs original, mean / p99 | GPU, torch | kernels used |
|---|---|---|---|
sam2.1-hiera-tiny | 0.00122 / 0.00428 | RTX 5060 Ti, torch 2.14.1+cu130 | dpt_fused@48e0065bb7cf:sm_120 |
sam2.1-hiera-small | 0.00539 / 0.01677 | RTX 5060 Ti, torch 2.14.1+cu130 | dpt_fused@48e0065bb7cf:sm_120 |
sam2.1-hiera-base-plus | 0.00245 / 0.00842 | RTX 5060 Ti, torch 2.14.1+cu130 | dpt_fused@48e0065bb7cf:sm_120 |
sam2.1-hiera-large | 0.01872 / 0.08865 | RTX 5060 Ti, torch 2.14.1+cu130 | dpt_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: A cup of coffee, Rachel Michetti (CC0).