PyTorch
PyTorch is a free Python library for building and training neural networks, with fast maths on GPUs and automatic gradients.
PyTorch is a free, open-source library for Python that people use to build and train neural networks. It gives you two main things. The first is tensors: grids of numbers, a bit like a spreadsheet, that can also run on a GPU, a graphics chip that does lots of maths at once, for speed. The second is autograd, a tool that works out gradients for you.
A gradient tells you which way to nudge each setting inside a model, called a parameter, to make its error smaller. Training is a loop. The model makes a guess, a loss function measures how wrong the guess was, and each parameter is adjusted a little. Think of practising basketball free throws. You shoot, see how far you missed, and adjust your aim. PyTorch does the “how far, and which way” part for every setting at once.
The clever part is how it finds gradients. As your code runs, autograd records every operation in a graph. When you call backward(), it walks that graph from the answer back to the inputs and applies the chain rule, a maths rule for working out how a small change flows through each step. Because the graph is rebuilt on every run, your model can use normal Python if-statements and loops. When something breaks, the error points to where that part of your code was written.
PyTorch suits quick experiments and serious research. It is not a ready-made AI. You still choose the data, the model design and settings such as the learning rate. Today it is looked after by the PyTorch Foundation, a group not owned by any one company, hosted by the Linux Foundation.
Training a neural network by hand would mean a lot of slow, error-prone maths.
Follow one training step through PyTorch.
- 1 · tensorsData goes in as tensors, grids of numbers that can live on a CPU or a GPU.
- 2 · forwardThe model runs on the tensors, and autograd records each operation in a graph.
- 3 · lossA loss function measures how far the guess is from the right answer.
- 4 · backwardCalling loss.backward() walks the graph backwards and computes a gradient for every parameter.
- 5 · stepThe optimizer nudges each parameter using its gradient, then the gradients are reset for the next round.
PyTorch's key trick is recording the maths as it runs, so the gradients come for free.
| Who | What they ask | What it works with |
|---|---|---|
| Student learning deep learning | “How do I train my first image classifier?” | A small network trained with a PyTorch training loop |
| Research lab | “Can we try a new model idea this afternoon?” | Ordinary Python code the team can change and debug line by line |
| Data scientist | “Can I move this NumPy-style maths onto a GPU?” | Tensors moved to the GPU |
| Engineering team | “Where are PyTorch's tools for bigger training jobs?” | The torch.distributed package in the docs |
- Tensors run fast maths on GPUs as well as CPUs.
- Autograd computes gradients automatically, so you do not derive them by hand.
- Models are plain Python, so error messages point to where your code was written.
- The graph is rebuilt on every run, so ordinary if-statements and loops can change the model.
- It does not pick your data, model design or settings such as the learning rate.
- Tensors start on the CPU, so you must move them to a GPU yourself.
- Gradients add up by default, so a training loop must reset them each round.
- Some newer features are marked unstable and may still change.
Sources used
This explainer is written in original language. The links below support its factual claims.
- docsPyTorch documentation, PyTorch · read 28 Sept 2026
- repopytorch/pytorch, PyTorch on GitHub · read 28 Sept 2026
- docsTensors, PyTorch Tutorials · read 28 Sept 2026
- docsAutomatic Differentiation with torch.autograd, PyTorch Tutorials · read 28 Sept 2026
- docsOptimizing Model Parameters, PyTorch Tutorials · read 28 Sept 2026
- paperPyTorch: An Imperative Style, High-Performance Deep Learning Library, Paszke et al., NeurIPS 2019 · read 28 Sept 2026
- officialPyTorch Foundation, PyTorch Foundation · read 28 Sept 2026