Models · Promptable segmentation

MobileSAM

MobileSAM: Segment Anything with a small TinyViT image encoder distilled from the largest SAM.

experimental Fork of ChaoningZhang/MobileSAM@f706ad9 · backends: portable, kernels

Checkpoint mobile-sam

Paper 2023 Added in 0.2.0 Evaluated with 0.2.0

Kernels, RTX 5060 Ti 16 GB 7.22 ms 1024x1024, fp16
vs the faster original 3.3× original fp16: 23.5 ms
Peak memory 203 MiB original: 207 MiB
Accuracy vs original fp32 ±0.00 kernels mIoU best of 3 %, COCO val2017 (51.53 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("mobile-sam")  # 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 mobile-sam

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 fp32upstream SamPredictor.set_image + predict (centre point, multimask_output=True)fp32 30.30.78×319 MiB/368 MiB2.10.70
Original fp16torch.autocast(float16) around the call; upstream SamPredictor.set_image + predict (centre point, multimask_output=True)fp16 23.5–207 MiB/286 MiB0.21.01
Portable fp32fp32not measured ––––
Portablefp16 10.52.2×171 MiB/190 MiB0.70.42
Kernelsfp16 7.223.3×203 MiB/296 MiB0.80.31
Portable + torch.compile 6.223.8×203 MiB/232 MiB25 (build)–
TensorRT fp16image encoder onlyfp16 4.994.7×122 MiBenginenot comparable61 (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

DeviceBackenddtypems / callPeak memoryOutput vs referenceInput
Apple M1 Pro 16 GB MPS, torch 2.14.1, 2026-11-14Originalfp32121 1,768 MiB process–1024x1024
Portablefp1669.9 1,504 MiB processmatches1024x1024
Portablefp3280.8 1,480 MiB processmatches1024x1024
Kernelsfp16not 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 AND MIT LICENSELICENSE-TinyViT
Weights
Apache-2.0 source
Training data
image encoder distilled from SAM ViT-H on 1 % of SA-1B (about 100k images) per the README and paper; prompt encoder and mask decoder are SAM's (trained on SA-1B: 11M licensed images, 1.1B automatically generated masks); the dataset itself is under the SA-1B research licence

Our reading of the licences, not legal advice.

Weights

mobile_sam.pt 40.7 MB· hosted on GitHub

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

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 fp32fp3251.5349.90 reference 500 34.9
Original fp16fp1651.4849.91 −0.05 500 25.0
Portable fp32fp3251.5149.90 −0.02 500 –
Portablefp1651.5349.91 ±0.00 500 15.6
Kernelsfp1651.5349.91 ±0.00 500 14.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-10; portable fp32: RTX 5060 Ti, torch 2.14.1+cu130, fastforks 44640884, 2026-11-17; portable, kernels: RTX 5060 Ti, torch 2.14.1+cu130, fastforks 5eafe838+dir, 2026-11-10.

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.0013 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.81 % and p99 <= 4.1 % of the reference's median |value| (absolute error of the output pred_masks).

CheckToleranceMeasured
CPU fp32, max |diff|≤ 0.0013 (relative)not recorded
GPU default dtypes, mean |diff|≤ 0.0081 (relative)0.00536 (relative)
GPU default dtypes, p99 |diff|≤ 0.041 (relative)0.02698 (relative)

Recorded for mobile-sam on RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-10, with these kernels: fvm_convfvm_extrafvm_mbfvm_r3

Details

MobileSAM (Zhang et al. 2023, Kyung Hee University): Segment Anything with the ViT-H image encoder replaced by a TinyViT-5M (an MBConv stage, then window attention with depthwise convs) distilled from it; SAM's own 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 (183 MiB allocated)
Outputs
pred_masks, iou_scores
CUDA kernels
  • fvm_convfused convolutions for image classifiers
  • fvm_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, fp16

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

MobileSAM: Segment Anything with a small TinyViT image encoder distilled from the largest SAM.

Commercial use: yes.

variantinputbackendtime (ms)peak memory (MiB, allocated / reserved)
mobile-samsynthetic (1024x1024)original (fp32)
original
portable
kernels
portable + torch.compile
TensorRT fp16
30.3
23.5
10.5
7.22
6.22
4.99 (image encoder only)
319 / 368
207 / 286
171 / 190
203 / 296
203 / 232
219 / 252
Details
  • Original code: https://github.com/ChaoningZhang/MobileSAM at f706ad9c4eb7
  • Code licence: Apache-2.0 AND MIT (permissive); files: LICENSE, LICENSE-TinyViT
  • Weights licence: Apache-2.0
  • Licence evidence: https://github.com/ChaoningZhang/MobileSAM/blob/f706ad9c4eb7f219c00d9050e46328518ffb65d2/LICENSE (Apache-2.0; weights/mobile_sam.pt is in the same tree and the README names no other terms); the same file from a co-author: https://huggingface.co/dhkim2810/MobileSAM/blob/4e2e5245fe9dc63096d575d36e70eb39b03b3aba/README.md (license: mit); TinyViT: https://github.com/microsoft/Cream/blob/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/LICENSE
  • Training data: image encoder distilled from SAM ViT-H on 1 % of SA-1B (about 100k images) per the README and paper; prompt encoder and mask decoder are SAM's (trained on SA-1B: 11M licensed images, 1.1B automatically generated masks); the dataset itself is under the SA-1B research licence
  • Kernel libraries: fvm_conv, fvm_extra, fvm_mb, fvm_r3
  • Variants: mobile-sam
  • 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): mobile-sam 1080x1920 (0.2 GiB peak allocated, 0.2 reserved)
  • mobile-sam 1024x1024, first call: portable + torch.compile 25 s (cold Inductor cache), TensorRT fp16 61 s (ONNX + engine).
  • mobile-sam original (fp32) 1024x1024: upstream SamPredictor.set_image + predict (centre point, multimask_output=True)
  • mobile-sam original 1024x1024: torch.autocast(float16) around the call; upstream SamPredictor.set_image + predict (centre point, multimask_output=True)
  • mobile-sam load / first call: original 0.21 s / 1.006 s, portable 0.71 s / 0.419 s, kernels 0.82 s / 0.309 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.

variantdatasetoriginal fp32original fp16portableportable fp32kernelsnote
mobile-samCOCO val2017, every 10th image, point prompts, mIoU best of 3 / single mask %51.53 / 49.9051.48 / 49.9151.53 / 49.9151.51 / 49.9051.53 / 49.91

Measured on portable: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 5eafe838+dirty, 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, fastforks 5eafe838+dirty, 2026-11-10.

Parity

CPU, float32: max |diff| <= 0.0013 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.81 % and p99 <= 4.1 % of the reference's median |value| (absolute error of the output pred_masks).

variantkernels error vs original, mean / p99GPU, torchkernels used
mobile-sam0.00536 / 0.02698RTX 5060 Ti, torch 2.14.1+cu130fvm_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=false or release_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
Output
A cup of coffee, input
Input · 100%

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