Cuda installation on M3

So I am trying to install this plug in which is built for Linux/Windows

~ I have managed to get it installed in venv with python 3.10, with torch 2.5.1 , I have the node loaded into to nuke I can create a bounding box and set files, but [create mask] in debugging script I get;

File “/Applications/Nuke15.1v5/Nuke15.1v5.app/Contents/MacOS/plugins/ENV_DIR/venv/lib/python3.10/site-packages/torch/cuda/init.py”, line 310, in _lazy_init
raise AssertionError(“Torch not compiled with CUDA enabled”)
AssertionError: Torch not compiled with CUDA enabled

~ Do I need to compile PyTorch myself with CUDA enabled?

~ Can I just swap in the SAM repo folder out in installation for the CPU version posted below.

No, CUDA is not supported on Mac anymore.

This idea sounds valid.
Instead of installing another repository you could also check if the currently used one could also support CPU-only runs or MPS.

Thanks for your reply @ptrblck

~ I checked and it does, and this is the repo I have installed.

You can pull the latest code and reinstall via

run the line below inside the SAM 2 repo git pull; pip uninstall -y SAM-2; rm -f sam2/*.so; pip install -e “.[demo]”

which allows using SAM 2 without CUDA extension (the results should stay the same in most cases, see INSTALL.md for details).

~ but that doesn’t explain why I am getting this error?
Could I be using the wrong PyTorch?

You cannot run CUDA code on a platform that does not support NVIDIA devices and the CUDA toolkit.

but in this post it says I can?

we have recently made the CUDA extension step optional (in #155) as a workaround to this problem. […] which allows using SAM 2 without CUDA extension

No, you cannot run the CUDA extension on your M3 and would need to disable it.

@ptrblck

But if I was to follow this tutorial?

Also @ptrblck I think your missing the part where it says without Cuda extension

Your error shows you are trying to initialize CUDA on an unsupported platform:

File “/Applications/Nuke15.1v5/Nuke15.1v5.app/Contents/MacOS/plugins/ENV_DIR/venv/lib/python3.10/site-packages/torch/cuda/init.py”, line 310, in _lazy_init
raise AssertionError(“Torch not compiled with CUDA enabled”)
AssertionError: Torch not compiled with CUDA enabled

Could you explain where this call comes from and which part of your code tries to initialize CUDA, which is unsupported on Mac M3?

from within nuke it is;

gc.collect()
torch.cuda.empty_cache()

in train.py ;

Initialize torch.distributed and set the CUDA device.
Expects environment variables to be set as per
Distributed communication package - torch.distributed — PyTorch 2.5 documentation
along with the environ variable “LOCAL_RANK” which is used to set the CUDA device.

device = “cuda” if cpu_group is None else “cpu”

orig_device = “cpu” if not tensor.is_cuda else “gpu”

def _setup_torch_dist_and_backend(self, cuda_conf, distributed_conf) → None:
if torch.cuda.is_available():

Great, in this case you would need to disable the CUDA code from your script or the repository as mentioned in the linked issue.