PyTorch is a Python library for tensor computation and deep learning. It gives you NumPy-like tensors that run on CPU or GPU, plus a tape-based autograd system for building and training neural networks. It's aimed at researchers and engineers who want a Python-first, imperative framework rather than a static-graph compiler wrapped in Python bindings.
PyTorch fits deep learning research and production model development where you need to change network architecture or control flow at runtime, for example RNNs with variable-length sequences, models with conditional branching, or rapid experimentation with new layer types. It also works well as a general GPU-accelerated tensor library if you're doing numerical computing beyond NumPy's CPU limits.
It's a good match if you want Python-native debugging, direct interop with NumPy/SciPy/Cython, and the ability to write custom autograd-compatible layers without wrapper code.
It's less of a fit if you need a fully static, ahead-of-time compiled graph for constrained embedded deployment without any Python runtime (though TorchScript covers part of that gap), or if your team is standardized on another framework's ecosystem (TensorFlow, JAX) and switching cost outweighs the benefit. Building from source also demands real setup time and disk space, so if you just want a quick install, use the prebuilt binaries instead.
The simplest path is installing prebuilt binaries via pip or Conda, with exact commands generated at pytorch.org/get-started/locally based on your OS, package manager, and CUDA version.
To build from source, first clone the repo and its submodules:
git clone https://github.com/pytorch/pytorch
cd pytorch
git submodule sync
git submodule update --init --recursive
Prerequisites: Python 3.10+, a C++20-capable compiler (gcc 11.3.0+ on Linux), at least 10 GB free disk space, and 30-60 minutes for the initial build. On Linux, set up a virtual environment (Conda or a tool like uv), then install dependencies:
pip install --group dev
pip install mkl-static mkl-include
# optional CUDA LAPACK support
.ci/docker/common/install_magma_conda.sh 12.4
# optional, for torch.compile with inductor/triton
make triton
Then build and install in editable mode:
export CMAKE_PREFIX_PATH="${CONDA_PREFIX:-'$(dirname $(which conda))/../'}:${CMAKE_PREFIX_PATH}"
python -m pip install --no-build-isolation -v -e .
For CUDA support, install NVIDIA CUDA and cuDNN (v9.0+) first, or set USE_CUDA=0 to disable it. For AMD GPUs, install ROCm 4.0+ and run python tools/amd_build/build_amd.py before the install step, or set USE_ROCM=0 to disable it. Intel GPU support is enabled via USE_XPU=1 and disabled with USE_XPU=0. Docker images and NVIDIA Jetson wheels are also available for platforms where building from source isn't practical.