Nº26 · Machine Learning
PyTorch
The flexible, Pythonic deep learning framework.
What is it?
PyTorch is an open-source deep learning framework for Python. Its core unit is the tensor: a multi-dimensional array much like NumPy's, but with two superpowers — it runs on the GPU and ships with autograd (automatic differentiation). On top of that it offers ready-made building blocks (torch.nn, optimizers, loss functions) to construct and train neural networks.
What is it for?
- Computer vision. Image classification, object detection, segmentation — with convolutional networks and pretrained models.
- NLP and LLMs. It is the reference framework for language processing and for training or fine-tuning large language models; most of the ecosystem (e.g. Hugging Face) is built on top of it.
- Custom models. Any architecture of your own that needs gradients: autograd handles the derivatives, you define the model and the loss.
- Research and production. Its dynamic API makes it comfortable to experiment with, while tools like TorchScript and
torch.compiletake it to production.
When to use it / when not to?
Use it for deep learning on unstructured data — images, text, audio, complex sequences — where neural networks add real value, and when you want to leverage the GPU to train at scale.
Think twice for classic ML on tabular data: there scikit-learn is simpler, faster to get going, and almost always enough. If a linear model or a decision tree solves your problem, don't take it to PyTorch — you'd add complexity without gaining accuracy. The honest boundary is this: scikit-learn for tabular and baselines; PyTorch once you step into deep learning.
Start in 1 minute
pip install torch
import torch
# A tensor that tracks its gradient
x = torch.tensor([2.0], requires_grad=True)
# Any operation: y = x^2 + 3x
y = x ** 2 + 3 * x
# autograd computes dy/dx automatically
y.backward()
print(x.grad) # dy/dx = 2x + 3 = 7.0 at x=2
x.grad shows the gradient PyTorch worked out on its own: that same mechanism, applied to millions of parameters, is what trains a neural network. The natural next step is to build a model with torch.nn.Module and train it with an optimizer from torch.optim. The official documentation includes tutorials for every case.
Quick trivia — test what you just read.
How much do you know about PyTorch?
Official documentation
The source of truth lives there. Here we orient you; the depth is up to you.
Open official docs ↗What to learn next
See alsoNº26 · Updated 2026-06-26