9951 explained code solutions for 126 technologies


python-pytorchHow do I install PyTorch with GPU support using Python?


To install PyTorch with GPU support using Python, you can follow these steps:

  1. Install the CUDA Toolkit from Nvidia, which contains the necessary libraries for GPU support.

  2. Install the cuDNN library from Nvidia.

  3. Install the PyTorch package using the pip package manager. To install with GPU support, use the following command:

pip install torch torchvision
  1. To verify the installation, you can check the version of PyTorch installed using the following command:
python -c "import torch; print(torch.__version__)"

Output example

1.6.0+cu101
  1. To check if GPU support is enabled, you can use the following command:
python -c "import torch; print(torch.cuda.is_available())"

Output example

True
  1. To check the version of CUDA installed, use the following command:
python -c "import torch; print(torch.version.cuda)"

Output example

10.1
  1. To check the version of cuDNN installed, use the following command:
python -c "import torch; print(torch.backends.cudnn.version())"

Output example

7603

Edit this code on GitHub