AssertionError: Invalid CUDA '--device 1' requested, use '--device cpu' or pass valid CUDA device(s)

10756007: <p>torch.cuda.is_available()=True<br>
But I stll get AssertionError: Invalid CUDA ‘–device 1’ requested, use ‘–device cpu’ or pass valid CUDA device(s)<br>
Please help me.</p>

ptrblck: <p>Based on the error message it seems you are trying to use a GPU with a device id 1, which is invalid. In case your system has a single GPU, use the device id 0.</p>

10756007: <p>I tried it but got the same result.<br>
AssertionError: Invalid CUDA ‘–device 0’ requested, use ‘–device cpu’ or pass valid CUDA device(s)</p>

10756007: <aside class="quote quote-modified" data-post="1" data-topic="147476">
  <div class="title">
    <div class="quote-controls"></div>
    <img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/luka123/48/51853_2.png" class="avatar">
    <a href="https://discuss.pytorch.org/t/yolov5-2022-3-25-torch-1-8-1-cu111-cuda-0-nvidia-geforce-rtx-3060-laptop-gpu-6144mib-invalid-cuda-device-0/147476">YOLOv5 2022-3-25 torch 1.8.1+cu111 CUDA:0 (NVIDIA GeForce RTX 3060 Laptop GPU, 6144MiB) -&gt; Invalid CUDA '--device 0'</a> <a class="badge-category__wrapper " href="/c/windows/26"><span data-category-id="26" data-drop-close="true" class="badge-category " title="This category is focused on PyTorch on Windows related issues."><span class="badge-category__name">windows</span></span></a>
  </div>
  <blockquote>
    I’m trying to train yolov5s with bdd100k on my GPU locally and getting this error although my GPU check is correctly done. I installed latest version of cuda and pytorch. 
ERROR: github: up to date with <a href="https://github.com/ultralytics/yolov5" class="inline-onebox" rel="noopener nofollow ugc">GitHub - ultralytics/yolov5: YOLOv5 <img width="20" height="20" src="https://discuss.pytorch.org/images/emoji/apple/rocket.png?v=12" title="rocket" alt="rocket" class="emoji"> in PyTorch &gt; ONNX &gt; CoreML &gt; TFLite</a> 
fatal: cannot change to ‘C:\Users\Luka\Desktop\Berkeley’: No such file or directory 
Traceback (most recent call last): 
File “C:\Users\Luka\Desktop\Berkeley dataset\yolov5s_bdd100k\yolov5\train.py”, line 643, in  
main(op…
  </blockquote>
</aside>

<p>I have the same problem as him</p>

ptrblck: <p>In the linked topic the user was installing a CPU-only PyTorch binary and fixed the issue by installing the right PyTorch binary with a CUDA runtime.</p>

10756007: <p>So I need to install a CPU-only PyTorch in a new virtual environment, or how can I do.<br>
I need GPU to run my program</p>

ptrblck: <p>No, if you want to use your GPU you would need to uninstall all CPU-only builds and install the PyTorch binary with the picked CUDA runtime.</p>

10756007: <p>First of all, thank you very much for your help, I am a student still learning AI by myself<br>
I didn’t install CPU-only builds.<br>
By the way, when I execute my program in pycharm, there will be an error message like the topic.<br>
I don’t know if it’s a problem with pycharm or virtual environment.</p>

10756007: <p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/6/3/63c877a13a56dd95b31761f6435c7127843e9d33.png" data-download-href="https://discuss.pytorch.org/uploads/default/63c877a13a56dd95b31761f6435c7127843e9d33" title="螢幕擷取畫面 2022-07-28 150139"><img src="https://discuss.pytorch.org/uploads/default/original/3X/6/3/63c877a13a56dd95b31761f6435c7127843e9d33.png" alt="螢幕擷取畫面 2022-07-28 150139" data-base62-sha1="eeILFeI6rYiIxfZo0i0E0wcL6bF" width="619" height="500" data-dominant-color="171717"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">螢幕擷取畫面 2022-07-28 150139</span><span class="informations">811×655 12.4 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

10756007: <p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/4/4/446dda524200337a0d930e6aa1bfcb53da47e6c5.png" data-download-href="https://discuss.pytorch.org/uploads/default/446dda524200337a0d930e6aa1bfcb53da47e6c5" title="螢幕擷取畫面 2022-07-28 150243"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/4/4/446dda524200337a0d930e6aa1bfcb53da47e6c5_2_690x371.png" alt="螢幕擷取畫面 2022-07-28 150243" data-base62-sha1="9LlPfk2dDTl3w3C5rTCixVDNQot" width="690" height="371" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/4/4/446dda524200337a0d930e6aa1bfcb53da47e6c5_2_690x371.png, https://discuss.pytorch.org/uploads/default/optimized/3X/4/4/446dda524200337a0d930e6aa1bfcb53da47e6c5_2_1035x556.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/4/4/446dda524200337a0d930e6aa1bfcb53da47e6c5_2_1380x742.png 2x" data-dominant-color="323334"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">螢幕擷取畫面 2022-07-28 150243</span><span class="informations">1913×1031 167 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

ptrblck: <p>Based on the error message CUDA is not available either because you’ve installed the wrong binary, have multiple binaries installed and are using the wrong one, your system has any driver issue and cannot communicate with the GPU etc.<br>
Create a new and empty virtual environment, install the PyTorch binary with the desired CUDA runtime, and make sure you are able to use the GPU.</p>

10756007: <p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/9/2/9238429b3d4826cc748652081bdb6846d04b4df3.png" data-download-href="https://discuss.pytorch.org/uploads/default/9238429b3d4826cc748652081bdb6846d04b4df3" title="螢幕擷取畫面 2022-07-28 150749"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/9/2/9238429b3d4826cc748652081bdb6846d04b4df3_2_690x275.png" alt="螢幕擷取畫面 2022-07-28 150749" data-base62-sha1="kRwflEo7MeRCjkPw55Qjlz9DCnh" width="690" height="275" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/9/2/9238429b3d4826cc748652081bdb6846d04b4df3_2_690x275.png, https://discuss.pytorch.org/uploads/default/optimized/3X/9/2/9238429b3d4826cc748652081bdb6846d04b4df3_2_1035x412.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/9/2/9238429b3d4826cc748652081bdb6846d04b4df3.png 2x" data-dominant-color="F6DFDC"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">螢幕擷取畫面 2022-07-28 150749</span><span class="informations">1046×417 24.7 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
I have tried installing CUDA 11.3 in a new and empty virtual environment twice, but failed both times.<br>
Do I need to install CUDA 11.6?</p>