MIC-DKFZ / TractSeg

Automatic White Matter Bundle Segmentation
Apache License 2.0
231 stars 75 forks source link

CUDA error with M1 chip #237

Open ravenep opened 1 year ago

ravenep commented 1 year ago

Hi Jakob, Ihave been working through your example to train my own model. The directories and data seem to be sourced correctly using the config files, but I have a new error that I was hoping you might be able to understand.

AssertionError("Torch not compiled with CUDA enabled")

I am using a MacBook Pro w/ Apple M1 Pro chip, OS 13.3.1, python 3.11, torch 2.0.0

I ran this test you suggested to another user:

import torch
torch.device("cuda" if torch.cuda.is_available() else "cpu")

And indeed, my machine only is finding the CPU, even though it has a GPU

from digging around, I found that the Apple M1 chip uses the 'mps' device option versus CUDA to access the GPU. https://towardsdatascience.com/installing-pytorch-on-apple-m1-chip-with-gpu-acceleration-3351dc44d67c

I have confirmed my environment does have access to the GPU using this device option.

Do you know if it is possible to use this instead of the CUDA with your code? If yes, could you please refer where I might make the switch? Thank you!!

wasserth commented 1 year ago

Unfortunately changing this might involve a few places in the code. You can try to search the entire codebase for "cuda" and replace it accordingly.

ravenep commented 1 year ago

Thanks for the suggestion! I found "cuda" in base_model.py and tried to modify the device to mps. It did not work for me, but do have a plan b in mind and will try this on a linux system moving forward.