Meta SAM 3 Playground

Guide · Linux & WSL2 · SAM 3 / 3.1

How to Install Meta SAM 3 Locally Set up a clean Python 3.12 environment, install PyTorch with CUDA and Meta’s sam3 package, unlock the checkpoint, and finish with a first run that proves everything works.

install + first run
Animation of installing SAM 3 and the first runA terminal shows each install command in turn: create the conda environment, install PyTorch, clone the repository, install SAM 3, log in to Hugging Face and run the first test. The last line reports two cats found, and a photo of two cats on a sofa gets two green masks. $ conda create -n sam3 python=3.12$ pip install torch==2.10.0 … cu128$ git clone …/sam3.git$ pip install -e .$ hf auth login$ python first_run.pyfound 2 cat(s) ✓ SAM 3 is working first_mask.png ✓
Illustration: six commands from empty machine to first mask.

Overview

The Install at a Glance

Six steps. Most of the time is spent downloading, not typing.

install progress
Animated install progressSix install steps fill in from left to right with ticks: GPU and driver, Python 3.12 environment, PyTorch with CUDA 12.8, the sam3 package, Hugging Face access, and the first successful run. 1GPU + drivernvidia-smi2Python 3.12env3PyTorchcu1284sam3pip -e .5accesshf login6first run✓ most of the time is downloading: PyTorch and the ~3.45 GB checkpoint
Illustration of the six install steps.
  1. 1Check your machineLinux or WSL2, an NVIDIA GPU and a working driver (nvidia-smi).
  2. 2Create a Python 3.12 environmentconda create -n sam3 python=3.12 (or venv / uv).
  3. 3Install PyTorch with CUDApip install torch==2.10.0 torchvision --index-url https://download.pytorch.org/whl/cu128
  4. 4Install SAM 3git clone https://github.com/facebookresearch/sam3.git, then pip install -e .
  5. 5Get checkpoint accessRequest access to facebook/sam3 on Hugging Face, then hf auth login.
  6. 6Run the first testpython first_run.py segments the cats in a sample photo and saves first_mask.png.

Before you start: system requirements (Python 3.12+, PyTorch 2.7+, CUDA 12.6+ GPU). No GPU? Use the playground or an API.

Step 1

Prepare Your Machine

SAM 3 is developed on Linux with NVIDIA GPUs. Confirm the GPU and driver first; everything else depends on it.

Linux terminal

nvidia-smi                 # must list your GPU and a driver version
git --version
df -h .                    # 20 GB+ free recommended
Windows + WSL2
Animated diagram of SAM 3 on Windows with WSL2Windows hosts the NVIDIA driver. Inside it, WSL2 runs Ubuntu, where Python, PyTorch and SAM 3 live. A pulse travels from SAM 3 through WSL2 to the Windows driver and the GPU, showing the GPU is shared without installing a Linux driver. Windows 10/11 WSL2 · Ubuntu 22.04 sam3 · first_run.pyPyTorch 2.10 + CUDA 12.8Python 3.12 (conda) NVIDIA driver GPU
Illustration of SAM 3 running inside WSL2.
On Windows
  • Use WSL2: install Ubuntu 22.04 from PowerShell.
  • Driver on Windows only: install the latest NVIDIA driver in Windows; WSL2 shares it.
  • Check inside Ubuntu: nvidia-smi must list your GPU.
  • Work in the Linux file system (e.g. ~/projects), not /mnt/c, for speed.

Windows setup

# Windows PowerShell (as administrator)
wsl --install -d Ubuntu-22.04
# install the latest NVIDIA Windows driver, restart, then inside Ubuntu:
nvidia-smi                 # the GPU should appear here; don't install a Linux driver in WSL

Step 2

Create a Python 3.12 Environment

Isolate SAM 3 from other projects. Meta’s README uses conda; venv and uv work the same way.

environment options
Animated diagram of environment optionsThree routes, conda, venv and uv, flow into the same result: an isolated Python 3.12 environment ready for PyTorch and SAM 3. Conda is the route used in Meta’s README. condaofficial READMEvenvbuilt into Pythonuvfast installer Python 3.12 envisolated · ready
Three ways to the same Python 3.12 environment.
  • Python 3.12 or newer is required; older versions fail on import.
  • One env per project keeps PyTorch and CUDA versions from clashing.
  • Activate it every time you open a new terminal before running SAM 3.

conda (official)

As in Meta’s README.

conda create -n sam3 python=3.12 -y
conda deactivate
conda activate sam3

venv

Needs Python 3.12 installed on the system.

python3.12 -m venv .venv
source .venv/bin/activate
pip install -U pip

uv

Fast; fetches Python 3.12 for you.

uv venv --python 3.12 .venv
source .venv/bin/activate
# then use 'uv pip install' instead of 'pip install'

Step 3

Install PyTorch with CUDA

Install the CUDA build of PyTorch before SAM 3. The current README pins PyTorch 2.10.0 for CUDA 12.8; any PyTorch 2.7+ with CUDA 12.6+ meets the minimum.

inside the activated environment

pip install torch==2.10.0 torchvision --index-url https://download.pytorch.org/whl/cu128

python -c "import torch; print(torch.__version__, torch.version.cuda, torch.cuda.is_available())"
# expect: 2.10.0+cu128 12.8 True

If the last value prints False, you installed a CPU-only build or the driver is too old. Reinstall with the index URL above, or update the driver. No separate CUDA toolkit is needed.

Step 4

Install the SAM 3 Package

Clone Meta’s repository and install it in editable mode, so a later git pull updates it in place.

terminal

git clone https://github.com/facebookresearch/sam3.git
cd sam3
pip install -e .

# optional extras
pip install -e ".[notebooks]"       # example notebooks
pip install -e ".[train,dev]"       # training and development

optional: faster inference

# optional speed-ups from the README
pip install einops ninja && pip install flash-attn-3 --no-deps --index-url https://download.pytorch.org/whl/cu128
pip install git+https://github.com/ronghanghu/cc_torch.git

Optional extras are only needed for notebooks, training or the speed-ups; the first run below needs none of them.

Step 5

Get Checkpoint Access and Log In

The weights are gated. Request access once, then let your machine authenticate.

  1. 1RequestOpen huggingface.co/facebook/sam3 (and sam3.1), fill in the form, accept the SAM License.
  2. 2WaitApproval is usually quick; check the repo page shows access granted.
  3. 3TokenCreate a read token in your Hugging Face settings.
  4. 4Log inRun the commands below in the same environment.

terminal

# after your request for facebook/sam3 is approved
hf auth login              # paste a read token from huggingface.co/settings/tokens
hf auth whoami             # should show the approved account

Details and rejected requests: Hugging Face access · File sizes and checksums: download guide

Step 6 · First successful run

Run SAM 3 for the First Time

Save this as first_run.py and run python first_run.py. It downloads a sample photo, loads SAM 3, finds the cats and saves a mask.

first_run.py

import time, urllib.request
import numpy as np
import torch
from PIL import Image
from sam3.model_builder import build_sam3_image_model
from sam3.model.sam3_image_processor import Sam3Processor

# 1. A known test photo: two cats on a sofa (COCO val2017)
urllib.request.urlretrieve("http://images.cocodataset.org/val2017/000000039769.jpg", "cats.jpg")

# 2. Environment report
print("torch", torch.__version__, "| CUDA", torch.version.cuda,
      "| GPU", torch.cuda.get_device_name(0) if torch.cuda.is_available() else "none")

# 3. Load SAM 3 (downloads the ~3.45 GB checkpoint on first run)
t0 = time.time()
processor = Sam3Processor(build_sam3_image_model())
print(f"model loaded in {time.time() - t0:.1f}s")

# 4. Segment with a text prompt
image = Image.open("cats.jpg").convert("RGB")
t0 = time.time()
out = processor.set_text_prompt(state=processor.set_image(image), prompt="cat")
scores = [round(float(s), 2) for s in out["scores"]]
print(f"found {len(scores)} cat(s) in {time.time() - t0:.2f}s, scores: {scores}")

# 5. Save proof
if scores:
    mask = out["masks"][0].squeeze().cpu().numpy().astype(np.uint8) * 255
    Image.fromarray(mask).save("first_mask.png")
    print("saved first_mask.png  ✓ SAM 3 is working")
else:
    print("no cats found: see Troubleshooting below")

example output (your times and scores will differ)

$ python first_run.py
torch 2.10.0+cu128 | CUDA 12.8 | GPU NVIDIA GeForce RTX 4090
model loaded in 41.3s
found 2 cat(s) in 0.38s, scores: [0.93, 0.91]
saved first_mask.png  ✓ SAM 3 is working
first run
Animation of the first successful runThe sample photo of two cats on a sofa. The prompt “cat” appears, then each cat receives a mask with a score label, and a banner confirms SAM 3 is working. The printed timing and scores are examples. prompt › “cat” cat 0.9xcat 0.9x ✓ SAM 3 worksfirst_mask.png saved sample: COCO val2017 #39769 · illustrative scores
Illustration of a successful first run.
What success looks like
  • GPU named on the first line: PyTorch sees CUDA.
  • Model loaded: access and checkpoint download worked (slow the first time, cached after).
  • “found 2 cat(s)”: the model runs end to end.
  • first_mask.png: open it; one cat should be white on black.
  • Prefer notebooks? jupyter notebook examples/sam3_image_predictor_example.ipynb after installing the notebooks extra.

After installing

Update, Uninstall and Next Steps

maintenance

cd sam3
git pull
pip install -e .           # pick up new code, e.g. SAM 3.1 support

# remove everything
conda deactivate && conda env remove -n sam3
rm -rf sam3 ~/.cache/huggingface/hub/models--facebook--sam3

Next steps

Moving to SAM 3.1

Troubleshooting

Install Problems and Fixes

SymptomLikely causeFix
nvidia-smi not foundNo NVIDIA driver (or Linux driver inside WSL)Install the NVIDIA driver; on WSL install it in Windows only
cuda.is_available() FalseCPU-only PyTorchReinstall from the cu128 index URL
ModuleNotFoundError: sam3Wrong environment activeconda activate sam3; rerun pip install -e .
SyntaxError on importPython older than 3.12Recreate the env with Python 3.12
401 / 403 / gated repoAccess not approved or not logged inhf auth whoami; check approval. Model access
flash-attn-3 fails to installUnsupported GPU or toolchainSkip it; it’s optional
CUDA out of memoryGPU too small or busyClose other GPU jobs; smaller images. OOM fixes
“found 0 cat(s)”Image download failed or changedOpen cats.jpg; try your own photo. Empty masks
Checkpoint / key errorsOld code with new weightsgit pull and reinstall. Checkpoint loading

Questions

Installation FAQ

How do I install SAM 3 locally?

Create a Python 3.12 environment, install PyTorch 2.7+ with CUDA, clone facebookresearch/sam3 and run pip install -e ., request access to facebook/sam3 on Hugging Face and run hf auth login, then run a short test script.

How long does the installation take?

Mostly download time: PyTorch is a few GB and the SAM 3 checkpoint is about 3.45 GB. On a fast connection the whole setup typically fits in under an hour, including the access request.

Do I need to install the CUDA toolkit separately?

Usually not. The PyTorch wheel includes the CUDA runtime; you only need a recent NVIDIA driver. Install the toolkit only if you build optional extensions from source.

Can I install SAM 3 with pip install sam3?

Use Meta’s repository: clone facebookresearch/sam3 and install it in editable mode with pip install -e . so you can pull updates such as SAM 3.1 with git pull.

Can I install SAM 3 on Windows?

Yes, through WSL2 with Ubuntu and the NVIDIA driver for WSL. Follow the Linux steps inside WSL. Native Windows isn’t the supported path.

How do I know SAM 3 installed correctly?

Run the first_run.py script on this page. If it prints the number of cats found and saves first_mask.png, your environment, GPU, checkpoint access and model are all working.

How do I update to SAM 3.1?

Run git pull in the sam3 folder, reinstall with pip install -e ., and request access to facebook/sam3.1. See the upgrade guide for details.

Keep reading