How to run PyTorch on GPU with CUDA 10.2 on Windows 7?

Question:

I want to test run some finite-difference time domain (FDTD) simulations using parallelization on a GPU and compare the speed to CPU-based simulation runs. This is basically my very first attempt at using GPU acceleration for scientific computing.

My system configuration:

CPU: Intel Core i7-4930K @ 3.40 GHz
GPU: Gigabte GeForce GTX 1650 OC LP 4.0 GB
RAM: 32.0 GB (16.0 GB usable)
OS: Windows 7 Home Premium 64-bit

This GPU has 896 CUDA cores and compute capability 7.5, so I’m expecting a significant acceleration when compared to running my simulation on "only" 12 CPU cores.

The simulation script uses the fdtd simulation package and I’m using Jupyter notebooks for convenience. If you’re interested in some actual code reference, I can recommend taking a look at the short example scripts on the fdtd GitHub page.

I’ve installed the CUDA ToolKit version 10.2 as this appears to be the last version with Windows 7 support. Version 11.0+ appears to support Windows 10+ only, at least according to the download page (can anyone confirm this?).

I’ve also installed torch + torchvision + torchaudio, simply because PyTorch includes these packages during installation procedure. However, I got stuck when trying to install the Python CUDA ToolKit as it seems to require another package called nvidia-pyindex, which is not available for Windows. Moreover, I’m confused by the PyTorch installation command for CUDA 10.2 which says "CUDA-10.2 PyTorch builds are no longer available for Windows, please use CUDA-11.6", especially since they clearly state:

Supported Windows Distributions

PyTorch is supported on the following Windows distributions:

Windows 7 and greater; Windows 10 or greater recommended.
Windows Server 2008 r2 and greater

In the Python interpreter, I’m getting

Python 3.8.10 (tags/v3.8.10:3d8993a, May  3 2021, 11:48:03) [MSC v.1928 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.cuda.is_available()
False

and trying to set the CUDA backend in the simulation package returns

import fdtd

fdtd.set_backend("torch.cuda.float64")

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Input In [3], in <cell line: 35>()
     31 display(HTML("<style>.container {width:100% !important;}</style>"))
     33 #fdtd.set_backend("numpy")
     34 #fdtd.set_backend("torch.float64")
---> 35 fdtd.set_backend("torch.cuda.float64")

File C:Program FilesPython38libsite-packagesfdtdbackend.py:376, in set_backend(name)
    374     raise RuntimeError("Torch backend is not available. Is PyTorch installed?")
    375 if name.startswith("torch.cuda") and not TORCH_CUDA_AVAILABLE:
--> 376     raise RuntimeError(
    377         "Torch cuda backend is not available.n"
    378         "Do you have a GPU on your computer?n"
    379         "Is PyTorch with cuda support installed?"
    380     )
    382 if name.count(".") == 0:
    383     dtype, device = "float64", "cpu"

RuntimeError: Torch cuda backend is not available.
Do you have a GPU on your computer?
Is PyTorch with cuda support installed?

How should I progress from here?

Asked By: user19548472

||

Answers:

Unfortunately, there seems to be fairly little you can do with your current software stack – Windows 7 is going to become an increasingly larger pain in the butt as software progresses, especially GPU drivers. The simplest way would be to upgrade that to Windows 10.

If you really, really don’t want to or can’t switch, you could also look into dual-booting a Linux system on the same machine. That should get you some more flexibility for the NVIDIA driver.


edit: There may be another way to sidestep this – it’s downgrading Pytorch, like I said before in the comments. According to the interactive table at https://pytorch.org/get-started/locally/#start-locally, PyTorch LTS 1.8.2 does support Windows 7 with CUDA 10.2, if you run it through Python 3.8, which I see you do. You can try installing that particular version with (found from that table):

pip3 install torch==1.8.2 torchvision==0.9.2 torchaudio===0.8.2 --extra-index-url https://download.pytorch.org/whl/lts/1.8/cu102

Once you get that installed, you should of course verify it’s running via GPU using the import torch; torch.cuda.is_available() you used earlier.

fdtd doesn’t have a particular minimal version dependency on PyTorch, which usually means things might break – but there’s a chance they won’t.

Answered By: Dominik StaƄczak
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.