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
- Paper Faster Segment Anything: Towards Lightweight SAM for Mobile Applications arXiv · first released 25 Jun 2023
Checkpoint mobile-sam
Paper 2023 Added in 0.2.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("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.
| Backend | dtype | Time per call (ms) | vs original fp16 | Peak memory allocated / reserved | Load (s) | First call (s) |
|---|---|---|---|---|---|---|
| Original fp32upstream SamPredictor.set_image + predict (centre point, multimask_output=True) | fp32 | 30.3 | 0.78× | 319 MiB/368 MiB | 2.1 | 0.70 |
| Original fp16torch.autocast(float16) around the call; upstream SamPredictor.set_image + predict (centre point, multimask_output=True) | fp16 | 23.5 | – | 207 MiB/286 MiB | 0.2 | 1.01 |
| Portable fp32 | fp32 | not measured | – | – | – | – |
| Portable | fp16 | 10.5 | 2.2× | 171 MiB/190 MiB | 0.7 | 0.42 |
| Kernels | fp16 | 7.22 | 3.3× | 203 MiB/296 MiB | 0.8 | 0.31 |
| Portable + torch.compile | 6.22 | 3.8× | 203 MiB/232 MiB | 25 (build) | – | |
| TensorRT fp16image encoder only | fp16 | 4.99 | 4.7× | 122 MiBenginenot comparable | 61 (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
| 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 | 121 | 1,768 MiB process | – | 1024x1024 |
| Portable | fp16 | 69.9 | 1,504 MiB process | matches | 1024x1024 | |
| Portable | fp32 | 80.8 | 1,480 MiB process | matches | 1024x1024 | |
| Kernels | fp16 | not 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 GitHubfastforks 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 %
| Run | dtype | mIoU best of 3 % ↑ | mIoU single % ↑ | Δ mIoU best of 3 % vs fp32 original | images | ms / image |
|---|---|---|---|---|---|---|
| Original fp32 | fp32 | 51.53 | 49.90 | reference | 500 | 34.9 |
| Original fp16 | fp16 | 51.48 | 49.91 | −0.05 | 500 | 25.0 |
| Portable fp32 | fp32 | 51.51 | 49.90 | −0.02 | 500 | – |
| Portable | fp16 | 51.53 | 49.91 | ±0.00 | 500 | 15.6 |
| Kernels | fp16 | 51.53 | 49.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).
| Check | Tolerance | Measured |
|---|---|---|
| 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 classifiersfvm_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.
| variant | input | backend | time (ms) | peak memory (MiB, allocated / reserved) |
|---|---|---|---|---|
mobile-sam | synthetic (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-sam1080x1920 (0.2 GiB peak allocated, 0.2 reserved) mobile-sam1024x1024, first call: portable + torch.compile 25 s (cold Inductor cache), TensorRT fp16 61 s (ONNX + engine).mobile-samoriginal (fp32) 1024x1024: upstream SamPredictor.set_image + predict (centre point, multimask_output=True)mobile-samoriginal 1024x1024: torch.autocast(float16) around the call; upstream SamPredictor.set_image + predict (centre point, multimask_output=True)mobile-samload / 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.
| variant | dataset | original fp32 | original fp16 | portable | portable fp32 | kernels | note |
|---|---|---|---|---|---|---|---|
mobile-sam | COCO val2017, every 10th image, point prompts, mIoU best of 3 / single mask % | 51.53 / 49.90 | 51.48 / 49.91 | 51.53 / 49.91 | 51.51 / 49.90 | 51.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).
| variant | kernels error vs original, mean / p99 | GPU, torch | kernels used |
|---|---|---|---|
mobile-sam | 0.00536 / 0.02698 | RTX 5060 Ti, torch 2.14.1+cu130 | fvm_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=falseorrelease_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: A cup of coffee, Rachel Michetti (CC0).