Fix · SAM 3 / 3.1 · video speed
Meta SAM Video Tracking Is Slow Know what speed to expect, find which stage is slow on your machine, check the hardware, change the settings that matter, and measure every change the same way so the gains are real.
Reference points
How Fast Should It Be?
Meta’s published figures are on data-centre GPUs. Use them to judge whether you’re far off, not as a target for a laptop.
| Setup (Meta) | Reported |
|---|---|
| SAM 3 image, H200 | ~30 ms with 100+ objects |
| SAM 3 video, 1× H200 | Near real-time for ~5 objects; slower as objects increase |
| SAM 3 video, 2 / 4 / 8× H200 | Real-time for 10 / 28 / 64 objects |
| SAM 3.1, H100, medium object count | 16 → 32 FPS |
| SAM 3.1, 128 objects, H100 | ~7× faster than SAM 3 |
The paper’s own controlled comparison reports a smaller 5.2× at 128 objects and a few percent overhead for a single object. Your GPU, clip and settings will differ, so measure.
Diagnosis
Where the Time Goes
Each frame passes through the same stages. Only one of them grows with the number of objects.
- Decode: reading frames from the video; CPU work.
- Encode: the image encoder runs on every frame; grows with resolution.
- Detect: finds matches for text prompts; grows with prompt count.
- Track: grows with objects in SAM 3; much less in SAM 3.1.
- Post-process and save: full-size masks and writing files, often forgotten and often slow.
- Time each stage with the
Stageshelper in the benchmark script.
Hardware
Hardware Checks
Before changing settings, make sure the GPU is actually doing the work at full speed.
- On the GPU at all?
torch.cuda.is_available()must be True; CPU runs take minutes per clip. - Watch it run:
nvidia-smi -l 1(ornvtop) shows utilisation, clocks, power and temperature. - Spiky, low utilisation: CPU-bound. Decode with a faster reader, pre-extract frames, and don’t save inside the loop.
- Low clocks or capped power: laptop on battery or power-saving mode, overheating, or a power limit.
- Shared GPU: other notebooks, browsers or jobs on the same card.
- Memory pressure: near-full VRAM forces slow paths; see out of memory.
- GPU class matters: requirements and tiers in system requirements.
Settings
Settings That Change Speed
Ordered by typical impact. Change one at a time and re-measure.
Measured reported by Meta · Documented in official code or docs · Standard general practice
| Setting | Speeds up | Trade-off | Evidence |
|---|---|---|---|
| Upgrade to SAM 3.1 | Tracking with several objects | Upgrade work; check tool support | Measured 16 → 32 FPS (H100); ~7× at 128 objects |
| Track fewer objects / prompts | Tracking and detection | Less coverage | Measured SAM 3 latency scales with objects |
| Lower frame rate before tracking | Everything, per second of video | Less temporal detail | Standard |
Lower resolution / image_size | Encoding | Small objects suffer | Documented Transformers image_size |
| bfloat16 | Most GPU work | Tiny precision change | Documented used in official examples |
torch.compile | Steady-state speed | Slow first run; warm up | Documented improved in SAM 3.1 |
| Save masks after, not during | Post-process and save | More RAM or disk staging | Standard |
| Keep frames on GPU (if memory allows) | Avoids CPU↔GPU copies | More VRAM | Measured Meta, SAM 2: offloading cost 27 → 24 FPS |
| More GPUs | Real-time object count | Cost, setup | Measured 10 / 28 / 64 objects on 2 / 4 / 8× H200 |
Code
Settings in Code
official sam3 · SAM 3.1
# SAM 3.1 video predictor with speed options (names as in the current sam3 code;
# check model_builder.py and the SAM 3.1 notebook for your commit)
from sam3.model_builder import build_sam3_multiplex_video_predictor
predictor = build_sam3_multiplex_video_predictor(
compile=True, # torch.compile: slow first run, faster afterwards
max_num_objects=16, # objects per multiplex bucket
# use_fa3=True, # FlashAttention 3: Hopper GPUs (H100/H200) with FA3 installed
)Transformers · SAM 3 video
# Transformers SAM 3 video: lighter settings
import torch
from transformers import Sam3VideoConfig, Sam3VideoModel
config = Sam3VideoConfig.from_pretrained("facebook/sam3")
config.image_size = 560 # documented: faster inference / lower memory
model = Sam3VideoModel.from_pretrained("facebook/sam3", config=config).to("cuda", dtype=torch.bfloat16)ffmpeg · resample the clip
# resample before tracking: lower frame rate and resolution, cut to the part you need
ffmpeg -ss 00:01:00 -t 20 -i input.mp4 -vf "fps=10,scale=-2:720" -c:v libx264 -crf 18 clip_10fps_720p.mp4FlashAttention 3 needs a Hopper GPU and the FA3 package; leave it off elsewhere. Upgrade steps: upgrade to SAM 3.1. Full pipeline: video segmentation with Python.
Reproducible measurements
Measure Speed the Same Way Every Time
Without a fixed method, “it feels faster” is noise. Warm up, repeat, take the median, record the environment.
- 1Fix the input:one clip (e.g. 20 s, 720p), one prompt, stored with your results.
- 2Warm up once:loading, CUDA start-up and compilation are not tracking speed.
- 3Time three or more runswith the GPU synchronised before reading the clock.
- 4Report the median and spread;over ~10% spread means something else is competing.
- 5Change one thing,re-run, compare medians.
Script
Benchmark Script
Works with any pipeline: pass a function that processes the clip once.
bench_video.py
# bench_video.py: reproducible timing for any SAM video pipeline
import json, platform, statistics, subprocess, time
from contextlib import contextmanager
from importlib import metadata
def sync():
try:
import torch
if torch.cuda.is_available():
torch.cuda.synchronize() # GPU work is async; wait before reading the clock
except ImportError:
pass
def env_info():
info = {"python": platform.python_version(), "os": platform.platform()}
for pkg in ["torch", "sam3", "transformers", "ultralytics"]:
try:
info[pkg] = metadata.version(pkg)
except metadata.PackageNotFoundError:
pass
try:
import torch
info["cuda"] = torch.version.cuda
if torch.cuda.is_available():
info["gpu"] = torch.cuda.get_device_name(0)
except ImportError:
pass
try:
q = "driver_version,clocks.sm,clocks.max.sm,power.draw,temperature.gpu,utilization.gpu"
info["nvidia_smi"] = subprocess.run(["nvidia-smi", f"--query-gpu={q}", "--format=csv,noheader"],
capture_output=True, text=True, timeout=10).stdout.strip()
except Exception:
pass
return info
class Stages:
"""with stages("track"): ... accumulates seconds per stage"""
def __init__(self):
self.seconds = {}
@contextmanager
def __call__(self, name):
sync(); t = time.perf_counter()
yield
sync(); self.seconds[name] = self.seconds.get(name, 0.0) + time.perf_counter() - t
def bench(run, frames, warmup=1, repeats=3, out=None, **settings):
for _ in range(warmup): # loading, CUDA init, torch.compile happen here
run(); sync()
times = []
for _ in range(repeats):
sync(); t = time.perf_counter()
run()
sync(); times.append(time.perf_counter() - t)
med = statistics.median(times)
result = {**settings, "frames": frames, "runs_s": [round(x, 3) for x in times],
"median_s": round(med, 3), "fps": round(frames / med, 2),
"spread_pct": round(100 * (max(times) - min(times)) / med, 1), "env": env_info()}
print(json.dumps(result, indent=2))
if out:
with open(out, "a") as f:
f.write(json.dumps(result) + "\n")
return resultusage
# example: official sam3 predictor, same clip and prompt for every setting
from bench_video import bench, Stages
CLIP, PROMPT, FRAMES = "clips/street_20s_720p.mp4", "person", 600
def make_run(predictor):
def run():
sid = predictor.handle_request(dict(type="start_session", resource_path=CLIP))["session_id"]
predictor.handle_request(dict(type="add_prompt", session_id=sid, frame_index=0, text=PROMPT))
for _ in predictor.handle_stream_request(dict(type="propagate_in_video", session_id=sid)):
pass # don't save inside the timed loop
predictor.handle_request(dict(type="close_session", session_id=sid))
return run
# bench(make_run(predictor_sam3), FRAMES, model="sam3", dtype="bf16", out="results.jsonl")
# bench(make_run(predictor_sam31), FRAMES, model="sam3.1", dtype="bf16", out="results.jsonl")Each run appends one JSON line to results.jsonl with settings, timings and environment, ready to compare or share.
Report
What to Record or Share
Numbers without this context can’t be compared or reproduced.
| Field | Example |
|---|---|
| Model and checkpoint | SAM 3.1, sam3.1_multiplex.pt |
| Code version | sam3 commit git log -1; or Transformers / Ultralytics version |
| GPU, driver, CUDA, PyTorch | RTX 4090, driver, CUDA 12.8, torch 2.10 |
| Clip | 20 s, 720p, 30 → 10 fps, 200 frames |
| Prompt and objects | “person”, 12 tracked objects |
| Settings | bf16, compile on, image size, offload on/off |
| Result | Median FPS, spread, peak memory |
Memory measurement: measure VRAM · Objects lost while speeding up? Tracking loses objects · All problems: troubleshooting
Questions
Slow Tracking FAQ
How fast should SAM 3 video tracking be?
Meta reports near real-time for about five objects on an H200 GPU, with time rising as you add objects. SAM 3.1 roughly doubles throughput at medium object counts on an H100. Consumer GPUs will be slower.
Why does SAM 3 get slower with more objects?
SAM 3’s tracker runs once per object on every frame. SAM 3.1’s Object Multiplex groups up to 16 objects into one pass, which is why it helps most in crowded scenes.
Is the first run always slow?
Yes, usually. Model loading, CUDA start-up and torch.compile all happen on the first call. Measure after a warm-up run.
Does lowering resolution help?
Yes. A smaller internal image size and smaller frames reduce the work per frame, at some cost to small-object detail.
Can I skip frames?
You can lower the frame rate before tracking (for example 30 → 10 fps). Tracking works on consecutive frames, so resample the video rather than skipping frames inside a session.
How do I compare two settings fairly?
Same clip, prompt, GPU and versions; one warm-up; at least three timed runs; report the median and the spread. The script on this page does that.