SAM 3 and SAM 3.1 (Segment Anything): What They Do, How to Run Them Locally on Windows or Linux, GPU Memory, and Fixing CUDA Out of Memory

Logeshwaran
—

SAM 3 (Segment Anything Model 3) is Meta's open model for finding, cutting out and tracking objects in images and videos. Released November 19, 2025, it added the feature earlier versions lacked: you can type a short text prompt such as "red mug" or "yellow school bus" and get a mask for every matching object, not just the one you clicked. It still accepts clicks, boxes and example images as prompts. SAM 3.1, released March 27, 2026, is a drop-in update that adds Object Multiplex: it tracks up to 16 objects in one forward pass, which roughly doubles video speed (16 to 32 frames per second on an H100 for a medium number of objects) and makes crowded scenes far cheaper. Both have about 848 million parameters (the BF16 weights are about 1.7 GB). They need Python 3.12+, PyTorch 2.7+ and an NVIDIA GPU with CUDA 12.6+ for the official code, and the weights are gated on Hugging Face (facebook/sam3, facebook/sam3.1). The famous "CUDA out of memory" error with SAM almost always comes from full precision, too many masks kept at full image resolution, long videos kept on the GPU, the automatic mask generator's batch size, or another program holding VRAM. Below: what SAM does, the versions compared, how to run it with transformers, the official repo or Ultralytics (including on Windows), GPU memory, every CUDA out-of-memory fix, and running it on AWS.

Jake wanted new photos for his shop's website: 1,800 product shots of phone cases, chargers and headphones, each needing a clean white background. Cutting them out by hand would take weeks. A customer who worked in computer vision told him to try Segment Anything, so Jake installed it on his gaming laptop, typed "phone case" as the prompt, and ran it on the first folder. The fourth image stopped everything: torch.OutOfMemoryError: CUDA out of memory. Tried to allocate 2.00 GiB. He sent Ethan a screenshot. "It worked three times, then it ran out of memory. Do I need a new laptop?" Ethan looked at the image sizes in the folder and smiled. "Probably not. You need to stop keeping 4,000-pixel masks on the GPU."

⚡ Quick Answer

• What it is: Meta's open segmentation model; type a phrase and it masks every match, in images and video. Explained.

• SAM 3 vs 3.1: same model size; 3.1 tracks many objects together, about twice as fast in video. Versions compared.

• Run it: transformers (simplest, works on Windows), the official repo, or Ultralytics. Setup and code.

• CUDA out of memory: BF16, one image at a time, move masks to the CPU, offload video frames. Every fix.

Prompts · GPU memory · Video · Windows · On AWS · License · FAQ.

New to running AI models on your own GPU? The cards below cover GPU troubleshooting, ComfyUI, GPU requirements for open video models, SageMaker and running a vision model on a CPU.

🧭 NEW HERE? READ THESE FIRST

These five pages help you run vision models on your own hardware:

📌 Bookmark this; the out-of-memory checklist and the code are the parts you will come back for.

What SAM 3 does, in plain English

Segmentation means drawing the exact outline of an object in a picture, pixel by pixel, so you can cut it out, measure it, blur it, recolor it or count it. A bounding box says "the mug is somewhere in this rectangle"; a segmentation mask says "these exact pixels are the mug." It is the step behind background removal, photo editing tools, medical image measurement, robot vision, sports analytics and video effects.

Meta's Segment Anything models made segmentation a general tool instead of something you train for each kind of object:

  • SAM (2023) segmented anything you pointed at: click a point or draw a box, and it returned a mask for that object, even for objects it had never seen in training.
  • SAM 2 (2024) extended that to video: click an object in one frame, and it tracked and segmented it through the rest of the clip.
  • SAM 3 (November 2025) added concepts: instead of clicking each object, you describe it with a short noun phrase ("phone case", "striped cat", "white car") or show an example, and it finds, segments and tracks every instance in the image or video. Meta calls this promptable concept segmentation.
  • SAM 3.1 (March 2026) kept the same model and made multi-object video tracking much faster and lighter with Object Multiplex.

Under the hood, SAM 3 is an image-level detector and a memory-based video tracker that share one vision backbone, with a "presence head" that first decides whether the concept is in the image at all before locating it. That design is why it handles "is there any red umbrella in this photo?" better than older open-vocabulary detectors. Meta reports that SAM 3 roughly doubles the accuracy of earlier systems on its new SA-Co (Segment Anything with Concepts) benchmark, reaches 47.0 zero-shot mask AP on LVIS, and processes an image with more than 100 detected objects in about 30 milliseconds on an H200 GPU.

What people use it for

  • Background removal for product photos and portraits, like Jake's catalog.
  • Dataset labeling: auto-generate masks for thousands of images, then correct the few it gets wrong, which is many times faster than drawing by hand.
  • Video editing and effects: isolate a person or object across a clip for color grading, blur or replacement.
  • Counting and measuring: count cars in a parking lot, cells under a microscope, or products on a shelf from a single prompt.
  • Robotics and AR: find and track the objects a robot or headset needs to interact with.
  • Privacy: find every face or license plate in a video to blur them.

What SAM 3 does not do: it does not generate or edit pixels itself (it only finds them), and it is best with short, simple noun phrases. Long instructions such as "the second person from the left holding a coffee" need a multimodal language model in front of it; Meta's SAM 3 Agent setup pairs it with one for that.

Jake: "So I type 'phone case' and it cuts out every phone case in the picture?"

Ethan: "Every one, with a confidence score each. Then you paste them on white. The model is fine. Your memory settings are the problem."

SAM vs SAM 2 vs SAM 3 vs SAM 3.1

SAM (1)SAM 2 / 2.1SAM 3SAM 3.1
ReleasedApril 2023July 2024 (2.1: September 2024)November 19, 2025March 27, 2026
PromptsPoints, boxes, masksPoints, boxes, masksText phrases, image exemplars, points, boxes, masksSame as SAM 3
Finds all instances of a conceptNoNoYesYes
Video trackingNoYes, per objectYes, per objectYes, up to 16 objects per pass
SizesViT-B, ViT-L, ViT-HTiny (38.9M) to Large (224.4M)One size, about 848MOne size, about 848M
LicenseApache 2.0Apache 2.0SAM License (Meta)SAM License (Meta)
Best forLegacy projectsClick-to-segment on small GPUs, edge devicesText-prompted segmentation and trackingVideo with many objects; new projects

Two practical takeaways. First, for new projects use SAM 3.1 checkpoints; they are a drop-in replacement for SAM 3 and faster in video. Second, if you only need click or box prompts and you are short on GPU memory, SAM 2.1 Tiny or Small is a fraction of SAM 3's size, runs on far smaller GPUs, and is Apache 2.0 licensed; you only need SAM 3 when you want text prompts or "find them all."

What exactly does Object Multiplex change?

SAM 2 and SAM 3 track each object with its own pass through the tracker, so cost grows roughly linearly with the number of objects: tracking 50 people means about 50 times the work of tracking one. SAM 3.1's Object Multiplex processes up to 16 tracked objects together in a single forward pass with a shared memory, cutting the repeated computation and memory traffic. Meta reports throughput rising from 16 to 32 frames per second on one H100 for videos with a medium number of objects, and about a 7x speedup at 128 tracked objects, without losing accuracy. For single images and single objects, SAM 3 and 3.1 behave about the same.

SAM 3 vs SAM 3D: not the same thing

Alongside SAM 3, Meta released SAM 3D, a separate pair of models that turn a single 2D photo into 3D: SAM 3D Objects reconstructs the shape and texture of objects in a picture, and SAM 3D Body estimates the 3D pose and shape of people. They are often searched together because they share a launch and a name. The difference in one line: SAM 3 tells you which pixels belong to an object, while SAM 3D builds a 3D model of it. The two work well in sequence, with SAM 3 finding and masking the object and SAM 3D reconstructing it, which is how AR, e-commerce "view in your room" features and game asset pipelines use them.

SAM 3 Agent: when the prompt is a sentence

Because SAM 3 understands short noun phrases, a request such as "the person on the left who is not wearing a helmet" is too complex for it on its own. SAM 3 Agent is Meta's pattern for that: a multimodal language model reads the request and the image, breaks it into simple noun phrases and checks, calls SAM 3 for each, and reasons over the masks it gets back to pick the right ones. If your application takes free-form instructions from users, plan for that layer; if your prompts are fixed product or object names, plain SAM 3 is enough and far cheaper.

Is SAM 3 free? What it costs to run

The model and weights cost nothing to download and use under the SAM License. What you pay for is compute: your own GPU's electricity, an hourly cloud GPU, or per-request charges if you use a hosted service such as Meta Model API. For batch jobs of a few thousand images, a local consumer GPU or one cloud GPU for an hour is usually the cheapest route; for an app with steady traffic, compare a hosted API's per-request price with the cost of keeping a GPU endpoint running all day.

The quickest way to try it: no install

Before you install anything, you can try SAM 3 in your browser in Meta's Segment Anything Playground (aidemos.meta.com/segment-anything): upload a photo or a short video, type a prompt, and see the masks. It is the fastest way to check whether SAM 3 handles your kind of images before you spend an afternoon on drivers.

Since September 18, 2026, SAM 3.1 is also available as a hosted endpoint on Meta Model API, which returns detections, masks and video tracks from a single call, so you can use it in an application without running a GPU yourself. For batch work on your own images, local or cloud GPUs are usually cheaper, which is what the rest of this page covers.

How to run SAM 3 locally: three ways

Before you start: get access to the weights

  1. Create a free Hugging Face account and open the model page facebook/sam3.1 (or facebook/sam3).
  2. Accept the license terms to request access. Approval is usually quick.
  3. Create an access token in your Hugging Face settings (read permission is enough).
  4. Sign in on your computer: hf auth login (from the huggingface_hub package), and paste the token. Downloads then work from code.

"401 Client Error" or "Cannot access gated repo" when loading the model means step 2 or step 4 is missing.

Option 1: Hugging Face transformers (simplest, works on Windows)

Recent releases of the transformers library include Sam3Model and Sam3Processor, so SAM 3 runs like any other Hugging Face model, natively on Windows, Linux and macOS:

pip install --upgrade torch torchvision --index-url https://download.pytorch.org/whl/cu128
pip install --upgrade transformers accelerate pillow
import torch
from PIL import Image
from transformers import Sam3Model, Sam3Processor

device = "cuda" if torch.cuda.is_available() else "cpu"
dtype = torch.bfloat16 if device == "cuda" else torch.float32

model = Sam3Model.from_pretrained("facebook/sam3", torch_dtype=dtype).to(device)
processor = Sam3Processor.from_pretrained("facebook/sam3")

image = Image.open("products/case-0141.jpg").convert("RGB")
inputs = processor(images=image, text="phone case", return_tensors="pt").to(device)

with torch.inference_mode():
    outputs = model(**inputs)

results = processor.post_process_instance_segmentation(
    outputs,
    threshold=0.5,
    mask_threshold=0.5,
    target_sizes=inputs.get("original_sizes").tolist(),
)
for result in results:
    print(f"Found {len(result['masks'])} objects")
    for box, score in zip(result["boxes"], result["scores"]):
        print([round(v) for v in box.tolist()], round(float(score), 3))

Each result contains masks (resized to the original image), boxes in pixel coordinates (x1, y1, x2, y2) and scores. Raise threshold to keep only confident matches. The same processor accepts box prompts through input_boxes (each box as x1, y1, x2, y2 in pixels) and input_boxes_labels, where a label of one means "objects like this" and zero means "not this", with or without a text prompt alongside.

Option 2: the official repository (full features, Linux and WSL)

Meta's facebookresearch/sam3 repository has the reference implementation, the video predictor, fine-tuning code and SAM 3.1 updates. It needs Python 3.12 or later, PyTorch 2.7 or later and an NVIDIA GPU with CUDA 12.6 or later:

conda create -n sam3 python=3.12
conda activate sam3
pip install torch==2.10.0 torchvision --index-url https://download.pytorch.org/whl/cu128
git clone https://github.com/facebookresearch/sam3.git
cd sam3
pip install -e .

For images, you build the model with build_sam3_image_model(), wrap it in Sam3Processor, call set_image() and then set_text_prompt(), and read masks, boxes and scores from the output. For video, build_sam3_video_predictor() gives you a predictor whose handle_request() takes a start_session request (with a folder of JPEG frames or an MP4 file) and then add_prompt requests with a frame index and a text prompt; results come back in the response's outputs. To move an older install to SAM 3.1, pull the latest code and reinstall. The optional flash-attention 3 package speeds up inference on supported GPUs but is not required.

Option 3: Ultralytics (fast to script, good for pipelines)

If you already use YOLO models, Ultralytics wraps SAM 3 in the same style. Install with pip install -U ultralytics, download sam3.pt (or sam3.1_multiplex.pt) from the gated Hugging Face pages yourself, since Ultralytics does not download them automatically, and put the file in your working folder:

from ultralytics.models.sam import SAM3SemanticPredictor

overrides = dict(conf=0.25, task="segment", mode="predict", model="sam3.pt", half=True, save=True)
predictor = SAM3SemanticPredictor(overrides=overrides)
predictor.set_image("products/case-0141.jpg")
results = predictor(text=["phone case", "charger"])

In Ultralytics, sam3.1_multiplex.pt currently supports image prompts only; use sam3.pt for video. If you see TypeError: 'SimpleTokenizer' object is not callable, uninstall the separate clip package and install Ultralytics' own CLIP fork from GitHub.

Which way should you run it?

OptionSetup effortNeedsBest for
Segment Anything PlaygroundNoneA browserTrying it on a few of your own images or clips
Meta Model API (SAM 3.1)LowAn API keyApps that need segmentation without running GPUs
transformersLowPython, PyTorch, an NVIDIA GPU ideallyImage batches, Windows users, quick scripts
Official repositoryMediumPython 3.12, PyTorch 2.7+, CUDA 12.6+, Linux or WSLVideo tracking, SAM 3.1 features, fine-tuning
UltralyticsLowpip, downloaded weightsTeams already using YOLO pipelines
Cloud GPU (EC2, SageMaker)MediumAn AWS account and GPU quotaLarge batches, long videos, no local GPU

Common setup errors

  • "Cannot access gated repo" or a 401 error: request access on the model page and sign in with hf auth login.
  • torch.cuda.is_available() returns False: a CPU-only PyTorch is installed, or the NVIDIA driver is missing or too old. Reinstall PyTorch from the CUDA index URL and update the driver.
  • "CUDA error: no kernel image is available for execution on the device": your PyTorch build does not support your GPU's architecture, common with very old or very new cards. Install a PyTorch build that lists your GPU generation.
  • "No module named sam3": the repository was not installed into the active environment; activate the conda environment and run pip install -e . inside the cloned folder.
  • "Sam3Model" cannot be imported from transformers: your transformers version predates SAM 3 support; upgrade it.
  • The optional flash-attention build fails: skip it; it only speeds things up, and SAM 3 works without it.

Writing good prompts

  • Use short noun phrases: "phone case", "white sneaker", "person with red jacket". SAM 3 is trained on concepts, not sentences.
  • Add an attribute to narrow it: "black phone case" instead of "phone case" when you only want some of them.
  • Prompt each concept separately when you want different kinds of objects, or pass a list where your tool supports it (Ultralytics accepts ["person", "bus"]).
  • Use an exemplar box when words are not enough: draw a box around one example and SAM 3 finds the others that look like it. Add a negative box (label 0) to exclude look-alikes.
  • Use point or box prompts (the classic SAM style) when you want exactly one specific object.
  • Tune the threshold: lower it if objects are missed, raise it if you get false matches.
  • Expect trouble with vague or rare concepts: "small window", "cozy corner" or highly technical parts may need examples or fine-tuning.

How much GPU memory does SAM 3 need?

Meta does not publish official VRAM figures, so plan from the parts you can measure:

  • The weights: about 848 million parameters, which is roughly 1.7 GB in BF16 or FP16 and about 3.4 GB in FP32 (Ultralytics' sam3.pt file is about 3.45 GB). Quantized community builds (INT8, FP8) are about 1 GB.
  • Activations for one image at the model's input resolution, which grow with precision and with the number of objects found.
  • The output masks, which are where most surprises come from: masks are returned at the original image size, one per object. One 4,000 x 3,000 mask in 32-bit floats is 48 MB; 100 of them are 4.8 GB.
  • Video state: the tracker keeps features and memory for frames and objects, which grows with clip length, resolution and object count.
  • Everything else on the GPU: your desktop, browser, games, and other AI tools such as Ollama, which keeps models loaded in VRAM for a while after you use them.

In practice: single images with a text prompt in BF16 are comfortable on a consumer GPU when you process one image at a time and move the masks to the CPU as soon as you get them; long videos with many tracked objects are where 24 GB and larger cards earn their price. Watch real usage with nvidia-smi (or Task Manager's GPU tab on Windows, which shows "Dedicated GPU memory") while you test, and size from that rather than from guesses.

No NVIDIA GPU?

  • CPU: the transformers version runs on a CPU, slowly: fine for a handful of images or for testing your code, impractical for thousands.
  • Mac: the official code targets CUDA. Use the Playground, the hosted API, a cloud GPU, or the transformers version on CPU.
  • AMD GPUs: PyTorch's ROCm builds on Linux can run many transformers models; expect more setup work and check current support for your card.
  • A cloud GPU by the hour is often the cheapest answer for a one-off batch job; see running it on AWS.

Fixing "CUDA out of memory" with SAM, SAM 2 and SAM 3

The error looks like this:

torch.OutOfMemoryError: CUDA out of memory. Tried to allocate 2.00 GiB.
GPU 0 has a total capacity of 7.99 GiB of which 1.12 GiB is free.
Of the allocated memory 5.10 GiB is allocated by PyTorch, and 1.31 GiB is reserved by PyTorch but unallocated.

(Older PyTorch versions say RuntimeError: CUDA out of memory.) Read the numbers: the size it tried to allocate tells you how big the failing step is, and "reserved but unallocated" memory points at fragmentation. Then work through these fixes, most effective first.

1. Run in half precision (BF16)

Loading the model in BF16 (or FP16 on older GPUs without BF16 support) halves the memory for weights and most activations, with no visible change in masks for most uses. In transformers, pass torch_dtype=torch.bfloat16; in Ultralytics, half=True; for SAM 2 scripts, wrap inference in torch.autocast("cuda", dtype=torch.bfloat16), as the SAM 2 examples do.

2. Turn off gradient tracking

Inference does not need gradients. Wrap every call in with torch.inference_mode(): (or torch.no_grad()). Without it, PyTorch keeps intermediate results for a backward pass that never comes, which can multiply memory use.

3. Process one image at a time and free memory between images

This was Jake's problem. His script appended every result, masks and all, to a list on the GPU, and each 4,000-pixel image added gigabytes. Move what you need to the CPU immediately, save it, and let the GPU copy go:

import gc
from pathlib import Path
import numpy as np

for path in sorted(Path("products").glob("*.jpg")):
    image = Image.open(path).convert("RGB")
    image.thumbnail((2048, 2048))          # cap the size; masks scale with it
    inputs = processor(images=image, text="phone case", return_tensors="pt").to(device)
    with torch.inference_mode():
        outputs = model(**inputs)
    results = processor.post_process_instance_segmentation(
        outputs, threshold=0.5, mask_threshold=0.5,
        target_sizes=inputs.get("original_sizes").tolist(),
    )
    for result in results:
        masks = result["masks"].to("cpu").numpy().astype(np.uint8)   # off the GPU, 1 byte per pixel
        np.save(f"masks/{path.stem}.npy", masks)
    del inputs, outputs, results
    gc.collect()
    torch.cuda.empty_cache()

The three changes that matter: cap the image size before inference (2,048 pixels on the long side is plenty for web product photos), convert masks to small 8-bit arrays on the CPU, and delete GPU tensors before the next image. torch.cuda.empty_cache() returns cached memory so other processes and the next allocation can use it.

4. Keep fewer masks

Raise the score threshold so weak matches are dropped before they are upsampled, or keep only the top few masks per image. A prompt such as "phone case" on a busy shelf photo can return dozens of objects; if you only need the main product, take the highest-scoring one.

5. The automatic mask generator (SAM and SAM 2)

The classic "segment everything" mode samples a grid of points across the image and runs them through the model in batches. Its memory use is controlled mainly by points_per_batch (64 by default): lower it to 16 or 32 to trade speed for memory. Fewer points (points_per_side) and turning off crop layers also help. With SAM 3, a text prompt usually replaces "segment everything" entirely, at a fraction of the cost.

6. Video: offload frames and state to the CPU

Video is where SAM runs out of memory most often, because features for every frame and every object pile up. For SAM 2, start the session with predictor.init_state(video_path, offload_video_to_cpu=True, offload_state_to_cpu=True): frames and tracking state then live in system RAM, with a modest slowdown. With any version:

  • Split long videos into clips of a few hundred frames and process them one after another.
  • Lower the resolution or the frame rate of the input before tracking.
  • Track fewer objects at once; real-time figures for SAM 3 are quoted for about five objects.
  • Use SAM 3.1 when many objects must be tracked together; Object Multiplex exists to cut exactly this cost.

7. Use a smaller model when you can

If you only need click or box prompts, SAM 2.1 Tiny (38.9 million parameters) or Small uses a small fraction of SAM 3's memory. For the original SAM, the ViT-B checkpoint (about 375 MB) instead of ViT-H (about 2.5 GB) makes the same trade.

8. Reduce fragmentation

When the error says a lot of memory is "reserved by PyTorch but unallocated," memory is fragmented into pieces too small for the next request. Set this environment variable before starting Python:

# Linux and WSL
export PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True

# Windows PowerShell
$env:PYTORCH_CUDA_ALLOC_CONF = "expandable_segments:True"

9. Free the GPU from other programs

Check nvidia-smi for other processes holding memory: another Python kernel left running in Jupyter, a game, a browser with hardware acceleration, or a local language model server. Ollama, for example, keeps a model loaded for a few minutes after the last request; stop it or unload the model before a SAM batch. Our Ollama GPU guide shows how to see and free what it holds. Restarting a Jupyter kernel releases everything that kernel allocated.

10. Make sure you are using the GPU you think you are

Laptops with both integrated and NVIDIA graphics sometimes run Python on the wrong one, and machines with several GPUs default to GPU 0. torch.cuda.get_device_name(0) shows which card PyTorch sees, and the CUDA_VISIBLE_DEVICES environment variable picks one.

Jake: "So I didn't need a new laptop. I needed to stop hoarding masks."

Ethan: "Smaller photos, masks on the CPU, one image at a time. Your 8 GB card did all 1,800 overnight."

From masks to finished cutouts: a background removal script

A mask on its own is just an array of ones and zeros. To get Jake's catalog images, you combine the best mask with the original photo, then either save a transparent PNG or paste the product onto white. Pillow and NumPy do it in a few lines, entirely on the CPU, so the GPU is free for the next image:

import numpy as np
from PIL import Image

def cutout(image, masks, scores, out_png, out_jpg):
    if len(scores) == 0:
        return False                                   # nothing found: review by hand
    best = int(np.argmax(scores))                      # keep the highest-scoring object
    alpha = (np.asarray(masks)[best] > 0).astype(np.uint8) * 255
    rgba = image.convert("RGBA")
    rgba.putalpha(Image.fromarray(alpha))
    rgba.save(out_png)                                 # transparent background
    white = Image.new("RGB", rgba.size, (255, 255, 255))
    white.paste(rgba, mask=rgba.getchannel("A"))
    white.save(out_jpg, quality=92)                    # white background for the shop
    return True

Call it with the image, the CPU copy of the masks, and the scores from each result. Two refinements make the output look professional: smooth the mask edge slightly (a 1 to 2 pixel blur on the alpha channel removes jagged outlines), and add a little padding around the product when you crop, so every catalog image has the same margins. Log each image's best score; anything below about 0.6 is worth a human look.

SAM 3 vs YOLO and other dedicated detectors

SAM 3 is a generalist: it segments almost anything you can name, with no training. The price is speed. In Ultralytics' measurements on an RTX PRO 6000, SAM 3 took about 2.9 seconds per image, SAM 2-b about 0.9 seconds, and the tiny YOLO26n-seg segmentation model about 8 milliseconds. The trade-off is simple:

  • Use SAM 3 when the objects change often, you have no labeled data, or you need masks for many different concepts: product photos, labeling new datasets, one-off analysis.
  • Use a trained YOLO-style model when you detect the same few object types over and over in real time, such as people in a store camera feed or cars at a gate. A common pattern is to use SAM 3 to label a few thousand images quickly, then train a small, fast model on those labels for production.

Medical, microscopy and other specialist images

"Segment anything in medical images" is a popular search, and the honest answer is that the general SAM models work surprisingly well on many specialist images but are not tuned for them. Medical scans, microscope slides and satellite images look very different from the everyday photos SAM learned from. Research groups have released versions adapted to these fields, such as MedSAM for medical imaging and micro-sam for microscopy, built on earlier SAM generations, and SAM 3's own fine-tuning code lets you adapt it with a few hundred labeled examples from your domain. For anything clinical, treat SAM as a research and labeling tool: it is not a certified medical device, and its masks need expert review.

Tracking objects in video

Video is SAM 3's other half. The workflow, whichever tool you use, is the same:

  1. Start a session with the video (an MP4 file or a folder of JPEG frames).
  2. Add a prompt on one frame: a text phrase to find every matching object, or clicks and boxes for specific objects.
  3. Propagate: the tracker carries each object's mask through the following frames, giving each object a stable ID.
  4. Correct where needed: add a click on a frame where it drifted, and propagate again.
  5. Export masks per frame, or render them onto the video.

Cost grows with frames, resolution and objects. A 10-second clip at 30 frames per second is 300 frames, and each tracked object adds work per frame (much less with SAM 3.1's multiplexing). For long footage, process in clips and stitch the results; for real-time use, keep the number of tracked objects small and the input resolution moderate.

Running SAM 3 on Windows

You have two good routes on a Windows PC with an NVIDIA GPU:

  • Native Windows with transformers (Option 1 above): install Python 3.12 from python.org, the CUDA build of PyTorch from pytorch.org's selector, then transformers. No compiler, no extra packages. This is what Jake used.
  • WSL2 with the official repository (Option 2): install Ubuntu from the Microsoft Store, install the NVIDIA driver on Windows (WSL2 uses the Windows driver; you do not install a Linux driver inside it), then follow the Linux steps. Some optional speed-up packages, such as flash-attention, are Linux-only, which is why WSL is the smoother path for the full repo.

Common Windows stumbling blocks: a CPU-only PyTorch installed by a plain pip install torch (check with torch.cuda.is_available(); reinstall from the CUDA index URL if it says False), an old NVIDIA driver that does not support the CUDA version of your PyTorch build (update the driver), and long path errors during installs (enable long paths in Windows or install in a short folder such as C:\sam3). If you prefer a visual workflow, ComfyUI has community nodes for SAM models; our ComfyUI install guide covers the base setup.

Running SAM 3 on AWS

For a large batch, or if you have no suitable GPU, a cloud GPU for a few hours costs less than a new graphics card:

  • EC2 with a Deep Learning AMI: launch a GPU instance such as a g6.xlarge (one NVIDIA L4 with 24 GB) or g5.xlarge (one A10G with 24 GB) from an AWS Deep Learning AMI, which comes with NVIDIA drivers and PyTorch, then install transformers or the SAM 3 repo. On-demand prices for those sizes are around $0.80 to $1.00 an hour in US East; stop the instance when the batch finishes.
  • Amazon SageMaker AI: run SAM 3 in a SageMaker notebook for experiments, a processing or batch transform job for large image sets, or a real-time endpoint for an application. Our SageMaker guide explains which fits.
  • GPU quotas: new AWS accounts often have a quota of zero for GPU instance vCPUs. Request an increase for "Running On-Demand G and VT instances" in Service Quotas before you need it.

Keep images in S3, process them on the instance, and write the masks back to S3. For Jake's 1,800 photos, an L4 instance would have finished in well under an hour, for about a dollar.

License: can you use SAM 3 commercially?

SAM and SAM 2 are Apache 2.0. SAM 3 and SAM 3.1 use Meta's own SAM License, which grants a royalty-free, worldwide license to use, modify and redistribute the model, including in commercial products, with conditions: you must pass the license along when you redistribute, acknowledge SAM in published research, and stay within its acceptable-use limits, which exclude uses such as military and warfare applications, weapons and espionage, and require compliance with trade controls and privacy law. Read the full text on the Hugging Face model page before shipping a product, and have someone qualified review it if your use is anywhere near those limits.

Three practical points for businesses. First, the license applies to the model and its weights; your own images and the masks you generate are yours. Second, if you fine-tune SAM 3 and share the result, the fine-tuned weights carry the same license. Third, if your company's policy only allows standard open-source licenses such as Apache 2.0 or MIT, SAM 2.1 is the Segment Anything option that fits, at the cost of text prompts. Using the hosted Meta Model API instead brings that service's own terms, which are separate from the model license.

Tips for a good batch job

  • Test on 20 images first and look at every mask before you run 2,000.
  • Save masks as PNG or compressed arrays on the CPU, not as GPU tensors in memory.
  • Cap image size to what you actually need for the output.
  • Log the score of every mask so you can review the low-confidence ones by hand.
  • Keep the model loaded across images; loading it per image wastes time, not memory.
  • Write results as you go, so a crash at image 1,500 does not lose the first 1,499.
  • Fine-tune on a few hundred labeled examples if your objects are unusual; the SAM 3 repository includes fine-tuning code.

A simple folder layout keeps a batch job manageable: input/ for originals, masks/ for the saved arrays, output/ for finished images, and a results.csv with each file name, the number of objects found and the best score. When you rerun, skip any file that already has an output, so an interrupted job resumes where it stopped instead of starting again. And keep a copy of the exact prompt and thresholds you used; when someone asks in three months why one product looks different, you will want to rerun it the same way.

Frequently asked questions

What is SAM 3?

Segment Anything Model 3, Meta's open model released November 19, 2025, that detects, segments and tracks objects in images and videos from text phrases, example images, points, boxes or masks, finding every instance of a concept.

What is the difference between SAM 3 and SAM 3.1?

SAM 3.1, released March 27, 2026, is a drop-in replacement that adds Object Multiplex, tracking up to 16 objects per forward pass. It roughly doubles video throughput for medium object counts and is about 7x faster at 128 objects; image results are about the same.

How do I fix CUDA out of memory with SAM?

Run in BF16, wrap inference in torch.inference_mode, process one image at a time, cap image size, move masks to the CPU as 8-bit arrays, offload video frames and state to the CPU, lower points_per_batch for the automatic mask generator, and close other programs using the GPU.

How much VRAM does SAM 3 need?

There is no official figure. The weights take about 1.7 GB in BF16 and 3.4 GB in FP32; the rest depends on image size, the number of masks and video length. Single images in BF16 fit consumer GPUs when you free memory between images; long multi-object videos need much more.

How many parameters does SAM 3 have?

About 848 million, shared between the detector and the tracker.

Can SAM 3 run on a CPU?

The transformers version can, slowly. It is fine for testing and small jobs, not for large batches or video. The official repository expects an NVIDIA GPU with CUDA 12.6 or later.

Can I run SAM 3 on Windows?

Yes. Use transformers natively on Windows with a CUDA build of PyTorch, or use WSL2 with the official repository for the full feature set.

How do I download SAM 3 weights?

Request access on the Hugging Face pages facebook/sam3 or facebook/sam3.1, create an access token, and sign in with hf auth login. Code then downloads the weights automatically.

Is SAM 3 free for commercial use?

It is free to use under Meta's SAM License, which allows commercial use and redistribution with conditions and acceptable-use restrictions. SAM and SAM 2 are Apache 2.0. Read the license before shipping.

What prompts does SAM 3 accept?

Short text noun phrases, image exemplars (boxes around example objects, positive or negative), and the classic point, box and mask prompts.

Should I use SAM 2 or SAM 3?

SAM 3 for text prompts and finding every instance; SAM 2.1 Tiny or Small for click or box prompts on small GPUs or edge devices, with an Apache 2.0 license.

Why does SAM run out of memory on long videos?

The tracker keeps frames and per-object state, which grows with clip length, resolution and object count. Offload frames and state to the CPU, split the video into clips, lower resolution and track fewer objects, or use SAM 3.1.

Can I use SAM 3 without installing anything?

Yes: try it in Meta's Segment Anything Playground in a browser, or call SAM 3.1 through Meta Model API.

Does SAM 3 work in Ultralytics?

Yes. Download sam3.pt or sam3.1_multiplex.pt from Hugging Face yourself and use SAM3SemanticPredictor for text prompts. In Ultralytics, the 3.1 multiplex file supports images only for now; use sam3.pt for video.

What GPU should I rent on AWS for SAM 3?

A single-GPU instance with 24 GB, such as g6.xlarge (NVIDIA L4) or g5.xlarge (A10G), from a Deep Learning AMI handles image batches and moderate video comfortably.

What is SAM 3D, and how is it different from SAM 3?

SAM 3D is a separate pair of Meta models, SAM 3D Objects and SAM 3D Body, that reconstruct 3D objects and human bodies from a single photo. SAM 3 segments objects in 2D images and video; the two are often used together.

Does SAM 3 work on medical or microscopy images?

It often works reasonably, but it is not tuned for them. Domain-adapted variants such as MedSAM and micro-sam exist, and SAM 3 can be fine-tuned on your own labeled images. Clinical use needs expert review.

Why do I get "Cannot access gated repo" when loading SAM 3?

You have not been granted access on the model page yet, or your code is not signed in. Accept the terms on Hugging Face, then run hf auth login with an access token.

For readers preparing for an AWS certification

We have been covering AWS certifications alongside our fixes, so here is a short extra for readers studying for one. If you only came for the fix, you already have it; feel free to skip this part.

Exams that test this topic: Machine Learning Engineer – Associate (MLA-C02) • AI Practitioner (AIF-C01) • Solutions Architect – Associate (SAA-C03).

Here are the exam-style questions this topic tends to raise, with the reasoning you need to answer them:

1. A team must outline the exact pixels of each product in thousands of photos to remove backgrounds. Which computer vision task is this?

Image segmentation (instance segmentation), not classification or bounding-box detection.

2. A company wants to run an open segmentation model on AWS for a one-time batch of 50,000 images stored in S3, without keeping an endpoint running. Which SageMaker AI option fits?

A SageMaker batch transform or processing job.

3. A new AWS account cannot launch any G-family GPU instances. What must be requested?

A Service Quotas increase for Running On-Demand G and VT instances.

4. Which AWS service offers managed image analysis, including custom labels, without hosting your own model?

Amazon Rekognition (Custom Labels for your own object types).

5. A model runs out of GPU memory during inference. Which change usually halves memory use with little effect on output quality?

Running the model in half precision (FP16 or BF16).

6. A team uses a large general model to label images quickly and then trains a small, fast model for real-time production. What is this pattern called?

Using the large model for automated labeling (pseudo-labeling) and distilling into a smaller model.

7. Which EC2 Amazon Machine Image comes with NVIDIA drivers and deep learning frameworks preinstalled?

An AWS Deep Learning AMI.

Exam codes and dates change often. Our AWS certification changes page keeps track of what is current.

πŸ“š ALSO READ

Where to go next, from image models to GPUs in Docker:

📌 Bookmark this; the out-of-memory checklist and the code are the parts you will come back for.

The overnight run finished at 3:40 a.m. Jake's laptop had segmented all 1,800 product photos, with a score for each; he hand-checked the 60 with the lowest scores in the morning, fixed nine, and pasted the rest onto white with a ten-line script. The new catalog went live that weekend. "Same laptop," he told Ethan, "just less greedy." Ethan added the memory checklist to the shop's notes for the next time Jake tried a new model.

📌 If you keep one line from this page

SAM 3 (and the faster SAM 3.1) segments every object matching a short text prompt in images and video; run it with transformers in BF16, one image at a time, with masks moved to the CPU, and most "CUDA out of memory" errors disappear without new hardware.

848M parameters · gated weights on Hugging Face · SAM 2.1 Tiny for small GPUs.

Revision note. Written October 21, 2026. We will update this page when Meta releases new Segment Anything versions or tools change.

Related