AI
PyTorch
What is PyTorch?
PyTorch is an open-source machine learning library developed by Facebook's AI Research lab. It is based on the Torch library and is used for applications such as natural language processing. PyTorch provides two high-level features:
- Tensor computation (like NumPy) with strong GPU acceleration
- Deep neural networks built on a tape-based autograd system
PyTorch is widely used in the research community and is known for its flexibility and ease of use.
Installation
Check out the latest version of PyTorch installation instructions on the official website.
It's recommended to create a virtual environment before installing PyTorch to avoid conflicts with other Python packages.
Linux
Platform | CUDA Version | Command |
---|---|---|
Linux | None | pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu |
Linux | CUDA 11.8 | pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 |
Linux | CUDA 12.4 | pip install torch torchvision torchaudio |
Linux | CUDA 12.6 | pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126 |
MacOS | None | pip install torch torchvision torchaudio |
Windows | None | pip install torch torchvision torchaudio |
Windows | CUDA 11.8 | pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 |
Windows | CUDA 12.4 | pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124 |
Windows | CUDA 12.6 | pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126 |
Verify Installation
To make sure PyTorch is installed correctly, you can run the following Python code:
import torch
x = torch.rand(5, 3)
print(x)
Output:
tensor([[0.3380, 0.3845, 0.3217],
[0.8337, 0.9050, 0.2650],
[0.2979, 0.7141, 0.9069],
[0.1449, 0.1132, 0.1375],
[0.4675, 0.3947, 0.1426]])
NVIDIA CUDA Toolkit
Learn more about CUDA Toolkit.