Search code examples
pytorchgoogle-colaboratoryyolo

How can i fix Autodistill Invalid Cuda Error on Colab?


https://colab.research.google.com/github/roboflow-ai/notebooks/blob/main/notebooks/how-to-auto-train-yolov8-model-with-autodistill.ipynb

I am trying to test this on Colab. on this section:

%cd {HOME}
from autodistill_yolov8 import YOLOv8
target_model = YOLOv8("yolov8n.pt")
target_model.train(DATA_YAML_PATH, epochs=50)

But I couldn't find the solution to this error when I started to train:

/usr/local/lib/python3.10/dist-packages/ultralytics/yolo/utils/torch_utils.py in select_device(device, batch, newline, verbose)
67 install = 'See https://pytorch.org/get-started/locally/ for up-to-date torch install instructions if no '
68 'CUDA devices are seen by torch.\\n' if torch.cuda.device_count() == 0 else ''
\---\> 69 raise ValueError(f"Invalid CUDA 'device={device}' requested."
70 f" Use 'device=cpu' or pass valid CUDA device(s) if available,"
71 f" i.e. 'device=0' or 'device=0,1,2,3' for Multi-GPU.\\n"

ValueError: Invalid CUDA 'device=cuda' requested. Use 'device=cpu' or pass valid CUDA device(s) if available, i.e. 'device=0' or 'device=0,1,2,3' for Multi-GPU.

torch.cuda.is_available(): True
torch.cuda.device_count(): 1
os.environ\['CUDA_VISIBLE_DEVICES'\]: cuda

It seems like I can work with GPU but I couldn't fix that.

I searched for this issue but couldn't find anything.


Solution

  • Apologies for the friction you ran into getting started. I pushed a change to enable mps acceleration support for YOLOv8 training in Autodistill but the default device configuration wasn't set up properly.

    Upgrade to autodistill-yolov8 0.1.3:

    pip install --upgrade autodistill-yolov8==0.1.3
    

    Use this code to train:

    target_model.train(DATA_YAML_PATH, epochs=50, devices=[0,1...])
    

    Where devices is the list of CUDA device IDs you want to use in training.