How to run SAM 2 (Segment Anything 2) on a cloud GPU
Rent a GPU on Deploy, then open a terminal in JupyterLab or over SSH. Install SAM 2 from the official facebookresearch/sam2 repository, download checkpoints with the repository script, and run image or video segmentation from the notebooks that repository ships. Copy the notebook outputs off the instance before you destroy it. Destroying the instance deletes its disk.
The repository LICENSE file is the Apache License, Version 2.0 (read 2026-11-12). The README says the SAM 2 model checkpoints, the SAM 2 demo code, and the SAM 2 training code are licensed under Apache 2.0, and that the Inter Font and Noto Color Emoji used in the demo code are under the SIL Open Font License, version 1.1. Read both files before you redistribute the code or the checkpoints.
The commands below are copied from the upstream files named in each step. They were not run on a CloudGPU instance for this page. Anything this page adds around them is marked.
What the README says about memory
The SAM 2 README model table for the SAM 2.1 checkpoints, released in that file as September 29, 2024, has a column headed Size (M). The four rows are 38.9, 46, 80.8, and 224.4 (read 2026-11-12). The same table has a Speed (FPS) column: 91.2, 84.8, 64.1, and 39.5. The README says speed was measured on an A100 with torch 2.5.1, cuda 12.4. It does not say which A100 memory size. Catalog A100 40G is 40 and A100 80G is 80. Those are catalog values, not the measurement’s card. INSTALL.md publishes no GPU GB figure. This page does not treat Size (M) or FPS as VRAM.
GET /v1/public/compute-capabilities does not list GPUs. It returns feature flags. The memory column is vram_gb from gpu-prices.json, updated_at 2026-11-12T18:08:32.252Z. GET /v1/public/gpu-catalog the same day (generated_at 2026-11-12T18:08:33.832Z) listed the same names and the same vram_gb values, plus Ascend 910B, which is not in gpu-prices.json and is not listed here. The catalog response also includes an availability field. This page does not copy it. There is no upstream GPU GB cutoff to match these values against. Which listing you can start is on Deploy. This page does not say which listings are available.
| Catalog name | vram_gb |
|---|---|
| RTX 2080 | 8 |
| RTX 3080 | 10 |
| RTX 2080 Ti | 11 |
| RTX 3080 Ti | 12 |
| V100 16G | 16 |
| A30 | 24 |
| RTX 3090 | 24 |
| RTX 4090 | 24 |
| RTX 4090D | 24 |
| RTX 4080 SUPER 32G | 32 |
| RTX 5090 | 32 |
| RTX 5090D | 32 |
| V100 32G | 32 |
| A100 40G | 40 |
| A800 40G | 40 |
| A40 | 48 |
| RTX 4090 48G | 48 |
| RTX 4090D 48G | 48 |
| RTX A6000 | 48 |
| NVIDIA RTX PRO 5000 72G | 72 |
| RTX PRO 5000 72G | 72 |
| A100 80G | 80 |
| A800 80G | 80 |
| H800 | 80 |
| RTX 6000D | 83 |
| H20 96G | 96 |
| RTX PRO 6000 96G | 96 |
| RTX PRO 6000 Max-Q | 96 |
| H20-3e 141G | 141 |
Image and video upscaling is a different repository: How to upscale images and video with Real-ESRGAN on a cloud GPU. Opening the notebooks in JupyterLab: How to run a Jupyter notebook on a cloud GPU.
Install on Linux
On Deploy, choose Raw GPU. The README says the code requires python>=3.10, as well as torch>=2.5.1 and torchvision>=0.20.1, and it points at the PyTorch install page instead of printing a wheel URL. INSTALL.md says the CUDA toolkit should typically be CUDA 12.1 if you follow the default installation command. This page did not pick a wheel. How to install a specific PyTorch CUDA version is the index check against the CUDA Version in the nvidia-smi header.
The README’s clone and install, copied:
git clone https://github.com/facebookresearch/sam2.git && cd sam2
pip install -e .
The notebooks extra, copied from the same README:
pip install -e ".[notebooks]"
INSTALL.md prints one line that installs that extra directly: pip install -e ".[notebooks]". It also prints SAM2_BUILD_CUDA=0 pip install -e ".[notebooks]" to skip the CUDA extension. The README says a message like Failed to build the SAM 2 CUDA extension can be ignored and SAM 2 can still be used, with some post-processing limited. INSTALL.md says the same failure skips removing small holes and sprinkles in the output masks.
The README says the install compiles a custom CUDA kernel with nvcc, and that the toolkit version should match the PyTorch CUDA version. cloudgpu-net is not in the README. The download speed guide says to leave it off during pip.
Download the checkpoints
The README’s checkpoint script, copied. Run it from the repository root after the clone above.
cd checkpoints && \
./download_ckpts.sh && \
cd ..
The same section lists the SAM 2.1 files the script covers. The filenames, copied: sam2.1_hiera_tiny.pt, sam2.1_hiera_small.pt, sam2.1_hiera_base_plus.pt, sam2.1_hiera_large.pt. The README links one URL per file:
- https://dl.fbaipublicfiles.com/segment_anything_2/092824/sam2.1_hiera_tiny.pt
- https://dl.fbaipublicfiles.com/segment_anything_2/092824/sam2.1_hiera_small.pt
- https://dl.fbaipublicfiles.com/segment_anything_2/092824/sam2.1_hiera_base_plus.pt
- https://dl.fbaipublicfiles.com/segment_anything_2/092824/sam2.1_hiera_large.pt
The README does not print a file size for those checkpoints. This page does not add one.
Image and video notebooks
The README’s image snippet uses checkpoint ./checkpoints/sam2.1_hiera_large.pt and config configs/sam2.1/sam2.1_hiera_l.yaml. The angle-bracket arguments are the README’s placeholders, not a command this page completed. The real calls are in notebooks/image_predictor_example.ipynb. Automatic masks are in notebooks/automatic_mask_generator_example.ipynb.
import torch
from sam2.build_sam import build_sam2
from sam2.sam2_image_predictor import SAM2ImagePredictor
checkpoint = "./checkpoints/sam2.1_hiera_large.pt"
model_cfg = "configs/sam2.1/sam2.1_hiera_l.yaml"
predictor = SAM2ImagePredictor(build_sam2(model_cfg, checkpoint))
with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16):
predictor.set_image(<your_image>)
masks, _, _ = predictor.predict(<input_prompts>)
The video snippet, copied from the same README, including the trailing colon on the add_new_points_or_box line. The video notebook is notebooks/video_predictor_example.ipynb.
import torch
from sam2.build_sam import build_sam2_video_predictor
checkpoint = "./checkpoints/sam2.1_hiera_large.pt"
model_cfg = "configs/sam2.1/sam2.1_hiera_l.yaml"
predictor = build_sam2_video_predictor(model_cfg, checkpoint)
with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16):
state = predictor.init_state(<your_video>)
# add new prompts and instantly get the output on the same frame
frame_idx, object_ids, masks = predictor.add_new_points_or_box(state, <your_prompts>):
# propagate the prompts to get masklets throughout the video
for frame_idx, object_ids, masks in predictor.propagate_in_video(state):
...
The README’s “Load from Hugging Face” section prints SAM2ImagePredictor.from_pretrained and SAM2VideoPredictor.from_pretrained with a Hub id, after pip install huggingface_hub. Copy that id from the README. This page does not paste it.
Web demo
The README points at demo/README.md. That file is a React frontend and a Python backend. It is not a Gradio app. Its Docker quick start, copied:
docker compose up --build
That file says the frontend is at http://localhost:7262 and the backend is at http://localhost:7263/graphql. The local backend command in the same file binds 0.0.0.0:7263 and sets MODEL_SIZE=base_plus. The options it prints for MODEL_SIZE are tiny, small, base_plus, and large. This page did not run Docker or that gunicorn command, and it did not check whether the container sees the rented GPU. To open those ports from your computer, use how to use SSH port forwarding on a cloud GPU for 7262 and 7263.
The SAM 2 README does not document ComfyUI. The ComfyUI examples top-level directory list on 2026-11-12 had no SAM 2 directory. This page does not add a ComfyUI workflow.
When it fails
CUDA extension did not build. The README says you can ignore Failed to build the SAM 2 CUDA extension and still run image and video prediction. INSTALL.md says CUDA_HOME environment variable is not set means the toolkit was not found, and it prints export CUDA_HOME=/usr/local/cuda with a note to change the path. This page did not check that path on a CloudGPU image.
“CUDA error: no kernel image is available for execution on the device”. INSTALL.md prints that error and says a possible cause is that the CUDA kernel was not compiled for the GPU’s capability. The arch list it prints is export TORCH_CUDA_ARCH_LIST=9.0 8.0 8.6 8.9 7.0 7.2 7.5 6.0. That list does not include 12.0. The RTX 5090 guide says that card is compute capability 12.0 (sm_120) and needs a PyTorch build for CUDA 12.8 or newer. This page did not re-test a wheel on an RTX 5090. Catalog RTX 5090 and RTX 5090D are 32. That is the catalog value, not a SAM 2 requirement.
CUDA out of memory. The README and INSTALL.md that this page read do not print a VRAM cutoff or an out-of-memory flag. If the process raises that error, use how to fix CUDA out of memory on a cloud GPU.
Save the outputs, then destroy
The image and video snippets return masks in the variables the README names. The notebooks are where those calls are filled in. The README does not name an output directory for the Python API. Copy the notebook files and any masks you write to disk before you destroy the instance. Save your work before you destroy a cloud GPU is the checklist. The terms say data on local instance storage is permanently deleted when the instance is destroyed. Billing is per minute, with a 1-minute minimum, and it stops when you destroy the instance. The billing rule is on the pricing page. Prices are not copied here.
Frequently asked questions
How much VRAM does the SAM 2 README publish?
The SAM 2 README’s model table uses a column headed Size (M). For the SAM 2.1 checkpoints that column lists 38.9, 46, 80.8, and 224.4 (read 2026-11-12). The README says speed was measured on an A100 with torch 2.5.1, cuda 12.4. Neither the README nor INSTALL.md publishes a GPU GB figure. This page does not treat Size (M) or the FPS column as VRAM, and it does not mark any catalog vram_gb as enough or not enough. Which listing you can start is on https://cloudgpu.app/deploy.
Which license covers the SAM 2 checkpoints?
The SAM 2 README says the model checkpoints, the demo code, and the training code are licensed under Apache 2.0. The LICENSE file in that repository is the Apache License, Version 2.0. The same README says the Inter Font and Noto Color Emoji used in the demo code are under the SIL Open Font License, version 1.1. Read those files before you redistribute the code or the checkpoints.
Does the SAM 2 repository ship a web UI?
The SAM 2 README points at demo/README.md for a frontend and backend. That file is not a Gradio app. Its Docker quick start prints docker compose up --build and says the frontend is at http://localhost:7262 and the backend is at http://localhost:7263/graphql. The local backend command in that file binds 0.0.0.0:7263. This page did not run the demo. The SAM 2 README does not document ComfyUI, and the ComfyUI examples repository’s top-level directory list on 2026-11-12 had no SAM 2 directory.
Do the masks stay on the instance after I destroy it?
No. Copy notebook outputs and anything the demo writes before you destroy the instance. The terms say data on local instance storage is permanently deleted when the instance is destroyed.
Sources (read 2026-11-12, Asia/Shanghai)
- SAM 2 README (Python, torch, and torchvision versions, clone,
pip install -e ., notebooks extra,download_ckpts.sh, SAM 2.1 filenames and URLs, image and video snippets, Hugging Face section, Size (M) and FPS, A100 measurement note, Apache 2.0 and the demo font license): https://github.com/facebookresearch/sam2/blob/main/README.md - INSTALL.md (CUDA 12.1 note,
SAM2_BUILD_CUDA=0,CUDA_HOME, no-kernel-image arch list): https://github.com/facebookresearch/sam2/blob/main/INSTALL.md - LICENSE (Apache License, Version 2.0): https://github.com/facebookresearch/sam2/blob/main/LICENSE
- Notebooks: https://github.com/facebookresearch/sam2/blob/main/notebooks/image_predictor_example.ipynb , https://github.com/facebookresearch/sam2/blob/main/notebooks/video_predictor_example.ipynb , https://github.com/facebookresearch/sam2/blob/main/notebooks/automatic_mask_generator_example.ipynb
- Demo README (Docker command, ports 7262 and 7263,
MODEL_SIZEvalues, gunicorn bind): https://github.com/facebookresearch/sam2/blob/main/demo/README.md - ComfyUI examples top-level directories (no SAM 2 directory): https://github.com/comfyanonymous/ComfyUI_examples
- Public GPU memory: https://cloudgpu.app/gpu-prices.json (
updated_at2026-11-12T18:08:32.252Z) and https://cloudgpu.app/v1/public/gpu-catalog (generated_at2026-11-12T18:08:33.832Z).GET /v1/public/compute-capabilitiesreturned feature flags and no GPU list.
Cards you can start are on the Deploy page. Prices are on https://cloudgpu.app/pricing and are not repeated here.
Last updated: 2026-11-12 (Asia/Shanghai).