So hi, I’m trying to develop an AI model that requires GPU for training. However, I seem to not understand how to download pytorch correctly so it can use cuda. When running this code snippet, this is what I get:
import torch
#torch.zeros(1).cuda()
print(f"PyTorch version: {torch.__version__}")
print(f"CUDA version: {torch.version.cuda}")
print(f"CUDA available: {torch.cuda.is_available()}")
print(f"Number of GPUs: {torch.cuda.device_count()}")
PyTorch version: 2.3.0
CUDA version: None
CUDA available: False
Number of GPUs: 0
First of all, I do have a GPU, the result of the nvidia-smi command I type in the command prompt is here:
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 555.85 Driver Version: 555.85 CUDA Version: 12.5 |
|-----------------------------------------+------------------------+----------------------+
| GPU Name Driver-Model | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+========================+======================|
| 0 NVIDIA GeForce RTX 3050 ... WDDM | 00000000:F3:00.0 Off | N/A |
| N/A 44C P8 4W / 49W | 193MiB / 4096MiB | 0% Default |
| | | N/A |
+-----------------------------------------+------------------------+----------------------+
+-----------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=========================================================================================|
| 0 N/A N/A 24196 C+G ...Brave-BrowserApplicationbrave.exe N/A |
+-----------------------------------------------------------------------------------------+
I also have CUDA 11.8 installed and verified by nvcc --version
. I also have anaconda installed but because it is getting painful now, I am trying to get something working on the base environment and I have not installed another pytorch on a new conda environment. I also downloaded the pytorch from the official website with this code:
conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia
Honestly I have no idea what I should do now, I’ve checked some other posts on this same question and nothing seems to help that much.
Some other posts I checked included this: No module named “Torch”
“AssertionError: Torch not compiled with CUDA enabled” in spite upgrading to CUDA version
Reinstalling as suggested sometimes doesn’t work quite properly, and installing with pip doesn’t seem to work either, it’s the exact same thing (same version cuda not responding). Although for once, I recreated a conda environment and redownloaded pytorch and somehow it worked (it works in one environment but not the current environment I’m working with).