facebookresearch / segment-anything

The repository provides code for running inference with the SegmentAnything Model (SAM), links for downloading the trained model checkpoints, and example notebooks that show how to use the model.
Apache License 2.0
46.58k stars 5.52k forks source link

SAM with AMD GPU (ROCm) #601

Open Eleko opened 10 months ago

Eleko commented 10 months ago

Hi,

Is it possible to use SAM with ROCm pyTorch (because I'm on a AMD GPU (RX 6600) ?

When i run :

sam_checkpoint = "sam_vit_h_4b8939.pth"
model_type = "vit_h"
device = "rocm"
sam = sam_model_registry[model_type](checkpoint=sam_checkpoint)
sam.to(device=device)
mask_generator = SamAutomaticMaskGenerator(sam)

I have the following error:

RuntimeError: Expected one of cpu, cuda, ipu, xpu, mkldnn, opengl, opencl, ideep, hip, ve, fpga, ort, xla, lazy, vulkan, mps, meta, hpu, mtia, privateuseone device type at start of device string: rocm

Thank you !

Eleko commented 10 months ago

Ok i have understand i have to use "cuda" but the notebook is dying every time i run :

masks = mask_generator.generate(image)

Thanks !

Eleko commented 10 months ago

update : its a segfault :( ... any idea ?

NielsRogge commented 7 months ago

Hi,

Models in the 🤗 Transformers library run natively on AMD GPUs. Hence I'd recommend trying out the Hugging Face version of SAM: https://huggingface.co/docs/transformers/model_doc/sam