Solve the sudden RuntimeError: No CUDA GPUs are available problem in ubuntu system

The code was running fine, but one day I opened it and found that the graphics card was no longer available. When I ran the model, it showed RuntimeError: No CUDA GPUs are available.

1. First check whether the graphics card can be used, and enter in the python console interface:

import torch
print(torch.cuda.device_count()) // or print(torch.cuda.is_available())

If the output is not 0 or true, it means that the graphics card is available. Check whether there is a problem with the code calling the graphics card serial number or whether the cuda environment is installed correctly.

If the output is 0 or false, or an error is reported when typing nvidia-smi in the terminal, it means that the graphics card cannot be used. It is a mismatch in the graphics card driver caused by the Linux kernel upgrade. You can downgrade the graphics card driver to the original version. When you open the software and update the additional driver, you can also see that the driver has been automatically upgraded. Originally, I installed version 530. I will try downgrading the driver version first.

2. Find the previous driver version from the official website, and search for the available driver in the trial version driver under the driver below.

What I downloaded is NVIDIA-Linux-x86_64-530.41.03.run (because I remember this was the previous version)

3. Uninstall the previous driver and restart. Be sure to uninstall it. If the driver is not cleanly uninstalled, an error will be reported during the installation process.

sudo apt-get remove --purge nvidia*
reboot

3. Open the terminal in the download folder and enter

sudo ./NVIDIA-Linux-x86_64-530.41.03.run

Trampling record:

Step 3: An error occurs during installation. If it displays ERROR: An error occurred while performing the step: “Building kernel modules, you need to lower the kernel version. Enter uname -r at the terminal to view the kernel version and the installed kernel image. I display linux here. -image-5.15.0-87-generic is install, so the kernel version will be 5.15.0-87

//View installed kernel images
dpkg --get-selections | grep linux-image

linux-image-5.15.0-1039-nvidia deinstall
linux-image-5.15.0-1043-intel-iotg deinstall
linux-image-5.15.0-1045-gcp deinstall
linux-image-5.15.0-1046-oracle deinstall
linux-image-5.15.0-1048-aws deinstall
linux-image-5.15.0-1050-azure deinstall
linux-image-5.15.0-43-generic deinstall
linux-image-5.15.0-87-generic install
linux-image-5.15.0-87-lowlatency deinstall
linux-image-5.17.0-1035-oem deinstall
linux-image-5.19.0-41-generic deinstall
linux-image-5.19.0-42-generic deinstall
linux-image-5.19.0-43-generic deinstall
linux-image-5.19.0-45-generic deinstall
linux-image-5.19.0-46-generic deinstall
linux-image-6.1.0-1024-oem deinstall
linux-image-6.2.0-1010-nvidia deinstall
linux-image-6.2.0-1014-aws deinstall
linux-image-6.2.0-1014-oracle deinstall
linux-image-6.2.0-1015-azuredeinstall
linux-image-6.2.0-1015-lowlatency deinstall
linux-image-6.2.0-1017-gcp install
linux-image-6.2.0-34-generic deinstall
linux-image-6.2.0-35-generic install
linux-image-6.5.0-1004-oem install
linux-image-generic install
linux-image-generic-hwe-22.04 install
//View the specified version of the kernel package
apt-cache search linux | grep 5.15.0-87-generic
linux-buildinfo-5.15.0-87-generic - Linux kernel buildinfo for version 5.15.0 on 64 bit x86 SMP
linux-cloud-tools-5.15.0-87-generic - Linux kernel version specific cloud tools for version 5.15.0-87
linux-headers-5.15.0-87-generic - Linux kernel headers for version 5.15.0 on 64 bit x86 SMP
linux-image-5.15.0-87-generic - Signed kernel image generic
linux-image-unsigned-5.15.0-87-generic - Linux kernel image for version 5.15.0 on 64 bit x86 SMP
linux-modules-5.15.0-87-generic - Linux kernel extra modules for version 5.15.0 on 64 bit x86 SMP
linux-modules-extra-5.15.0-87-generic - Linux kernel extra modules for version 5.15.0 on 64 bit x86 SMP
linux-modules-iwlwifi-5.15.0-87-generic - Linux kernel iwlwifi modules for version 5.15.0-87
linux-tools-5.15.0-87-generic - Linux kernel version specific tools for version 5.15.0-87
linux-modules-nvidia-390-5.15.0-87-generic - Linux kernel nvidia modules for version 5.15.0-87
linux-modules-nvidia-418-server-5.15.0-87-generic - Linux kernel nvidia modules for version 5.15.0-87
linux-modules-nvidia-450-server-5.15.0-87-generic - Linux kernel nvidia modules for version 5.15.0-87
linux-modules-nvidia-470-5.15.0-87-generic - Linux kernel nvidia modules for version 5.15.0-87
linux-modules-nvidia-470-server-5.15.0-87-generic - Linux kernel nvidia modules for version 5.15.0-87
linux-modules-nvidia-525-5.15.0-87-generic - Linux kernel nvidia modules for version 5.15.0-87
linux-modules-nvidia-525-open-5.15.0-87-generic - Linux kernel nvidia modules for version 5.15.0-87
linux-modules-nvidia-525-server-5.15.0-87-generic - Linux kernel nvidia modules for version 5.15.0-87
linux-modules-nvidia-535-5.15.0-87-generic - Linux kernel nvidia modules for version 5.15.0-87
linux-modules-nvidia-535-open-5.15.0-87-generic - Linux kernel nvidia modules for version 5.15.0-87
linux-modules-nvidia-535-server-5.15.0-87-generic - Linux kernel nvidia modules for version 5.15.0-87
linux-modules-nvidia-535-server-open-5.15.0-87-generic - Linux kernel nvidia modules for version 5.15.0-87
linux-objects-nvidia-390-5.15.0-87-generic - Linux kernel nvidia modules for version 5.15.0-87 (objects)
linux-objects-nvidia-418-server-5.15.0-87-generic - Linux kernel nvidia modules for version 5.15.0-87 (objects)
linux-objects-nvidia-450-server-5.15.0-87-generic - Linux kernel nvidia modules for version 5.15.0-87 (objects)
linux-objects-nvidia-470-5.15.0-87-generic - Linux kernel nvidia modules for version 5.15.0-87 (objects)
linux-objects-nvidia-470-server-5.15.0-87-generic - Linux kernel nvidia modules for version 5.15.0-87 (objects)
linux-objects-nvidia-525-5.15.0-87-generic - Linux kernel nvidia modules for version 5.15.0-87 (objects)
linux-objects-nvidia-525-open-5.15.0-87-generic - Linux kernel nvidia modules for version 5.15.0-87 (objects)
linux-objects-nvidia-525-server-5.15.0-87-generic - Linux kernel nvidia modules for version 5.15.0-87 (objects)
linux-objects-nvidia-535-5.15.0-87-generic - Linux kernel nvidia modules for version 5.15.0-87 (objects)
linux-objects-nvidia-535-open-5.15.0-87-generic - Linux kernel nvidia modules for version 5.15.0-87 (objects)
linux-objects-nvidia-535-server-5.15.0-87-generic - Linux kernel nvidia modules for version 5.15.0-87 (objects)
linux-objects-nvidia-535-server-open-5.15.0-87-generic - Linux kernel nvidia modules for version 5.15.0-87 (objects)
linux-signatures-nvidia-5.15.0-87-generic - Linux kernel signatures for nvidia modules for version 5.15.0-87-generic
//Install the specified version
sudo apt-get install linux-headers-5.15.0-87-generic linux-image-5.15.0-87-generic
//Execute the following command to see the current kernel and the newly installed kernel
grep menuentry /boot/grub/grub.cfg
//Specify the kernel startup sequence in the system
sudo vim /etc/default/grub
Change GRUB_DEFAULT=0 to GRUB_DEFAULT="Advanced options for Ubuntu>Ubuntu, with Linux 5.15.0-87-generic"
//Update configuration and restart
sudo update-grub
reboot

After restarting, you can enter uname -r to check the kernel version. You can see that the change has been successful.

After the change is successful, re-execute step 3 to install the graphics card driver. The graphics card can be re-invoked if other cuda environments have not changed.

The knowledge points of the article match the official knowledge files, and you can further learn relevant knowledge. Python entry skill treeHomepageOverview 384549 people are learning the system