Skip to content

Feature request: backend-agnostic inference (CPU/MPS/TPU support) #164

Description

@trothe

Summary

It would be great if SAM 3 exposed a backend-agnostic inference path so the model can run on devices other than CUDA GPUs (Apple Silicon / MPS, CPU-only servers, TPU via XLA, etc.). Right now the repo assumes CUDA everywhere, so even image-only inference fails on machines without NVIDIA GPUs.

Use case

I (and likely many others) want to use SAM 3 for bulk auto-labeling images when preparing YOLO datasets. Those labeling jobs often run on whatever hardware is already available—e.g., a MacBook Pro M3 with the Metal build of PyTorch. Because SAM 3 hard-requires CUDA 12.6, there is no way to try the model without renting a remote GPU, which makes lightweight labeling workflows much harder.

Current blockers

These are some spots that make CUDA mandatory today:

  • The README lists "CUDA-compatible GPU with CUDA 12.6 or higher" as a prerequisite and only shows CUDA install commands (README.md:58-79).
  • Core preprocessing helpers unconditionally move tensors to CUDA (e.g. load_image_as_single_frame_video calls .cuda() on the image, mean, and std tensors in sam3/model/io_utils.py:93-112). On a PyTorch build compiled without CUDA, importing these utilities throws Torch not compiled with CUDA enabled.
  • The video inference stack wraps methods with @torch.autocast(device_type="cuda") and raises if self.device.type != "cuda" (sam3/model/sam3_video_inference.py:797-810), so even if most of the model could run on CPU/MPS, execution aborts immediately.
  • Multi-GPU support is hard-coded to NCCL + CUDA tensors (sam3/model/sam3_video_predictor.py:420-433), again preventing CPU or other backends.
  • Performance-critical helpers require CUDA-only extensions such as torch_generic_nms and Triton kernels built with TORCH_CUDA_ARCH_LIST (sam3/perflib/nms.py:11-69). There is no fallback that keeps execution on CPU/MPS when these aren’t available.

Request / proposal

Would Meta consider supporting a backend-agnostic inference mode? Concretely, that could mean:

  1. Abstracting device selection (use tensor.to(device) instead of raw .cuda() and allowing torch.device("mps"), "cpu", etc.).
  2. Guarding CUDA-specific features (NCCL, Triton kernels, torch.cuda.* logging) behind availability checks and providing CPU-friendly defaults.
  3. Documenting a CPU/MPS installation path—e.g., PyTorch nightly with Metal and a note about expected performance.
  4. (Stretch) exposing hooks so advanced users could plug in XLA/TPU devices once the general abstraction exists.

I’m happy to test on Apple Silicon if guidance is provided, but an official stance on whether CPU/MPS/TPU support is on the roadmap would already help the community plan.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions