Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yolov8 NotImplementedError with GPU #12843

Open
1 of 2 tasks
erahaman opened this issue May 19, 2024 · 4 comments
Open
1 of 2 tasks

Yolov8 NotImplementedError with GPU #12843

erahaman opened this issue May 19, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@erahaman
Copy link

Search before asking

  • I have searched the YOLOv8 issues and found no similar bug report.

YOLOv8 Component

Train

Bug

I have used Yolov8 to train my dataset with the CPU and it went great when I wanted to use GPU and train another dataset it's giving me NotImplementedError. i have set up cuda and pytroch and they are defined without any problems, How could I fix it. Please help me. Thank you

here is the error:
image

Environment

Ultralytics YOLOv8.2.18 Python-3.11.4 torch-2.3.0+cu121 CUDA:0 (NVIDIA GeForce RTX 3070 Laptop GPU, 8192MiB)
Setup complete (16 CPUs, 15.7 GB RAM, 22.9/64.0 GB disk)

Minimal Reproducible Example

from ultralytics import YOLO

model = YOLO("yolov8m.yaml")

model.train(data="yolo_con.yaml", epochs=100)

Additional

No response

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!
@erahaman erahaman added the bug Something isn't working label May 19, 2024
Copy link

👋 Hello @erahaman, thank you for your interest in Ultralytics YOLOv8 🚀! We recommend a visit to the Docs for new users where you can find many Python and CLI usage examples and where many of the most common questions may already be answered.

If this is a 🐛 Bug Report, please provide a minimum reproducible example to help us debug it.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results.

Join the vibrant Ultralytics Discord 🎧 community for real-time conversations and collaborations. This platform offers a perfect space to inquire, showcase your work, and connect with fellow Ultralytics users.

Install

Pip install the ultralytics package including all requirements in a Python>=3.8 environment with PyTorch>=1.8.

pip install ultralytics

Environments

YOLOv8 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

Ultralytics CI

If this badge is green, all Ultralytics CI tests are currently passing. CI tests verify correct operation of all YOLOv8 Modes and Tasks on macOS, Windows, and Ubuntu every 24 hours and on every commit.

@glenn-jocher
Copy link
Member

Hello! Thanks for reaching out and providing detailed information. It seems like you've encountered a NotImplementedError when trying to train on a GPU. This error typically occurs if there's a mismatch or an unsupported operation for the specific CUDA version or PyTorch build you are using.

Here are a couple of steps you can try to resolve this issue:

  1. Update PyTorch and CUDA: Ensure that your PyTorch and CUDA versions are compatible. You might want to try updating PyTorch to a version that fully supports CUDA 12.1, as there could be compatibility issues with torch-2.3.0 and CUDA 12.1.

  2. Check GPU Availability in Your Script: Before starting the training, add a check to ensure that PyTorch recognizes your GPU:

    import torch
    print(torch.cuda.is_available())
  3. Explicitly Set the Device: Modify your training script to explicitly set the device to GPU:

    from ultralytics import YOLO
    
    device = 'cuda' if torch.cuda.is_available() else 'cpu'
    model = YOLO("yolov8m.yaml", device=device)
    model.train(data="yolo_con.yaml", epochs=100)

If these steps do not resolve the issue, it might be helpful to provide the full traceback of the error, as the screenshot link seems to be broken. This will help in diagnosing the problem more accurately. Let us know how it goes!

@erahaman
Copy link
Author

I still have the same problem I deleted cuda, pytorch and pyhton and reinstalled everything and still get the same problem

I tried this code:
`from ultralytics import YOLO

device = 'cuda' if torch.cuda.is_available() else 'cpu'
model = YOLO("yolov8m.yaml", device=device)
model.train(data="yolo_con.yaml", epochs=100)`

and I got this error:
`TypeError Traceback (most recent call last)
Cell In[9], line 4
1 from ultralytics import YOLO
3 device = 'cuda' if torch.cuda.is_available() else 'cpu'
----> 4 model = YOLO("yolov8m.yaml", device=device)
5 model.train(data="yolo_con.yaml", epochs=100)

TypeError: YOLO.init() got an unexpected keyword argument 'device'`

I tried the original code again and this is the error:

`NotImplementedError Traceback (most recent call last)
Cell In[10], line 3
1 from ultralytics import YOLO
2 model = YOLO("yolov8m.yaml")
----> 3 model.train(data="yolo_con.yaml", epochs=100)

File c:\Users\eraha\AppData\Local\Programs\Python\Python310\lib\site-packages\ultralytics\engine\model.py:674, in Model.train(self, trainer, **kwargs)
671 pass
673 self.trainer.hub_session = self.session # attach optional HUB session
--> 674 self.trainer.train()
675 # Update model and cfg after training
676 if RANK in {-1, 0}:

File c:\Users\eraha\AppData\Local\Programs\Python\Python310\lib\site-packages\ultralytics\engine\trainer.py:199, in BaseTrainer.train(self)
196 ddp_cleanup(self, str(file))
198 else:
--> 199 self._do_train(world_size)

File c:\Users\eraha\AppData\Local\Programs\Python\Python310\lib\site-packages\ultralytics\engine\trainer.py:313, in BaseTrainer._do_train(self, world_size)
311 if world_size > 1:
312 self._setup_ddp(world_size)
--> 313 self._setup_train(world_size)
315 nb = len(self.train_loader) # number of batches
316 nw = max(round(self.args.warmup_epochs * nb), 100) if self.args.warmup_epochs > 0 else -1 # warmup iterations
...
PythonTLSSnapshot: registered at ..\aten\src\ATen\core\PythonFallbackKernel.cpp:162 [backend fallback]
FuncTorchDynamicLayerFrontMode: registered at ..\aten\src\ATen\functorch\DynamicLayer.cpp:493 [backend fallback]
PreDispatch: registered at ..\aten\src\ATen\core\PythonFallbackKernel.cpp:166 [backend fallback]
PythonDispatcher: registered at ..\aten\src\ATen\core\PythonFallbackKernel.cpp:158 [backend fallback]
Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings...`

@glenn-jocher
Copy link
Member

Hello! It looks like you're encountering a TypeError because the YOLO class initializer does not accept a device parameter directly. Instead, you should set the device after initializing the model. Here's how you can modify your code:

from ultralytics import YOLO
import torch

device = 'cuda' if torch.cuda.is_available() else 'cpu'
model = YOLO("yolov8m.yaml").to(device)
model.train(data="yolo_con.yaml", epochs=100)

For the NotImplementedError, this could be due to an issue with the specific operations used in your model configuration or a compatibility issue with your CUDA setup. Make sure that all operations used in your model are supported by the CUDA version you have installed.

If the problem persists, please ensure that your environment is correctly set up and that all dependencies are compatible with each other. If you can provide more details about when the error occurs during the training process, it might help in diagnosing the issue further. 🛠️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants