To install PyTorch with GPU support using a requirements.txt file, you can follow these steps:
Step 1: Create a requirements.txt file
First, create a new text file on your computer and name it requirements.txt. This file will contain all the packages that you want to install, including PyTorch with GPU support.
Step 2: Add PyTorch with GPU support to the requirements.txt file
Open the requirements.txt file using a text editor and add the following line:
torch==1.9.0+cu102
This line tells pip to install PyTorch version 1.9.0 with CUDA (cu) support for CUDA version 10.2. You can change the version number or CUDA version depending on your requirements.
Step 3: Install PyTorch with GPU support using the requirements.txt file
Now open a terminal or command prompt on your computer and navigate to the directory where the requirements.txt file is located.
To install all the packages listed in the requirements.txt file, run the following command:
pip install -r requirements.txt
This will download and install PyTorch with GPU support along with any other packages listed in the requirements.txt file.
Step 4: Verify the installation
To verify that PyTorch with GPU support has been installed successfully, you can open a Python interpreter and run the following commands:
import torch
print(torch.cuda.is_available())
print(torch.cuda.current_device())
print(torch.cuda.get_device_name(0))
If everything is installed correctly, you should see output indicating that PyTorch is using the GPU for computation.
That’s it! You have successfully installed PyTorch with GPU support using a requirements.txt file. You can now start using PyTorch for deep learning tasks on your GPU-enabled machine.