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

PlatformCUDA VersionCommand
LinuxNonepip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
LinuxCUDA 11.8pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
LinuxCUDA 12.4pip install torch torchvision torchaudio
LinuxCUDA 12.6pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126
MacOSNonepip install torch torchvision torchaudio
WindowsNonepip install torch torchvision torchaudio
WindowsCUDA 11.8pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
WindowsCUDA 12.4pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124
WindowsCUDA 12.6pip 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.

Previous
OpenAI Agents