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.
Overview
The Install at a Glance
Six steps. Most of the time is spent downloading, not typing.
- 1Check your machineLinux or WSL2, an NVIDIA GPU and a working driver (nvidia-smi).
- 2Create a Python 3.12 environmentconda create -n sam3 python=3.12 (or venv / uv).
- 3Install PyTorch with CUDApip install torch==2.10.0 torchvision --index-url https://download.pytorch.org/whl/cu128
- 4Install SAM 3git clone https://github.com/facebookresearch/sam3.git, then pip install -e .
- 5Get checkpoint accessRequest access to facebook/sam3 on Hugging Face, then hf auth login.
- 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- 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-smimust 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 WSLStep 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.
- 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 sam3venv
Needs Python 3.12 installed on the system.
python3.12 -m venv .venv
source .venv/bin/activate
pip install -U pipuv
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 TrueIf 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 developmentoptional: 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.gitOptional 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.
- 1RequestOpen huggingface.co/facebook/sam3 (and sam3.1), fill in the form, accept the SAM License.
- 2WaitApproval is usually quick; check the repo page shows access granted.
- 3TokenCreate a read token in your Hugging Face settings.
- 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 accountDetails 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- 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.ipynbafter 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--sam3Next steps
- Python tutorial: overlays and cut-outs
- Video with Python: track objects
- SAM 3 prompts: better results
- ComfyUI setup: node workflows
Moving to SAM 3.1
- Request access to
facebook/sam3.1 git pullandpip install -e .- Follow the upgrade guide
- Compare first: SAM 3 vs 3.1
Troubleshooting
Install Problems and Fixes
| Symptom | Likely cause | Fix |
|---|---|---|
nvidia-smi not found | No NVIDIA driver (or Linux driver inside WSL) | Install the NVIDIA driver; on WSL install it in Windows only |
cuda.is_available() False | CPU-only PyTorch | Reinstall from the cu128 index URL |
ModuleNotFoundError: sam3 | Wrong environment active | conda activate sam3; rerun pip install -e . |
| SyntaxError on import | Python older than 3.12 | Recreate the env with Python 3.12 |
| 401 / 403 / gated repo | Access not approved or not logged in | hf auth whoami; check approval. Model access |
| flash-attn-3 fails to install | Unsupported GPU or toolchain | Skip it; it’s optional |
| CUDA out of memory | GPU too small or busy | Close other GPU jobs; smaller images. OOM fixes |
| “found 0 cat(s)” | Image download failed or changed | Open cats.jpg; try your own photo. Empty masks |
| Checkpoint / key errors | Old code with new weights | git 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.