Torch is not working with cuda!

Hello, I have issue in pycharm: AssertionError: Torch not compiled with CUDA enabled.
I Have CUDA toolkit 12.4.0 installed, torch(2.3.0+cu121) torchvision(0.18.0+cu121) and torchaudio(2.3.0+cu121) are installed and no other version installed. I am using pycharm and I have reinstalled packages there. my OS is Windows 11. I could not find any working solution for days, may be someone here knows what the problem might be. Thanks in advance!

Hi @Edgar,

If you’re working within the Pycharm IDE, are you sure your IDE has selected the correct environment/interpreter? You might just be using the base environment (which won’t have any packages installed).

I’m not quite sure about what environment I’m using but I was installing packages in Pycharm after downloading them through pip

Could you check? If you’re using pip make sure to check what virtual environment you’re using (and also where you installed the packges) and make sure you’ve activated this virtual environment within the PyCharm IDE.

Could you explain why as it seems you’ve already downloaded the right pip wheels and might have broken the environment by downloading CPU-only binaries in PyCharm?

I have checked and everything is alright with the interpreter and environment, also checked cuda availability by package “cuda-available” and got positive results there while torch is still using CPU. I was installing torch with cuda using pip on my laptop but perhaps the problem might be with the added torch in the environment, because it doesn’t show any info about having cuda, for example, there is no “+ cu121”

Do you mean that added torch package in Pycharm should also have “+ cu121”? Because I didn’t see any torch with cuda in Pycharm

Yes, assuming you’ve installed another PyTorch pip wheel in Pycharm it should also show the corresponding CUDA runtime version.

Pycharm torch has only versions as “number.number.number” without mentioning cuda. The description of torch says “Tensor and Dynamic neural networks in Python with strong GPU acceleration”. Is there a way to find and add the right torch version?

If torch.version.cuda returns None uninstall this CPU-only binary and either keep the previously installed binary with CUDA support or create a new env and install a single binary only with CUDA support.

Yes, it returned “None”. I do not have a CUDA torch within a list of packages in Pycharm even though I have it installed on my computer. Or I’m not looking in the right place?

I don’t know which virtual environment is used in Pycharm but you should either make sure the one is used where PyTorch with CUDA runtime is installed or create a new one and install the PyTorch binaries with CUDA support. If you get stuck you might want to post in a Pycharm-specific discussion board, as your current issue is related to the IDE and not PyTorch.