# PyTorch

> A free tool in Python. You use it to build and train neural networks.

**Field:** Artificial Intelligence  
**Category:** Machine Learning  
**Also known as:** Torch (Python), PyTorch Library

## Think of it like

It is like a box of building bricks for brains. You snap layers together and teach them.

## Definition

PyTorch is a free Python library for building and training neural networks. You write a network as normal Python code, layer by layer. It works out the gradients for you, so training needs little extra code. It runs the same code on a CPU or a graphics card. Most AI research and many large language models are built with it. It is run by the PyTorch Foundation, part of the Linux Foundation.

## Example

Emma builds a small image classifier in 40 lines of PyTorch. She moves it to a graphics card with one line, and it trains ten times faster.

## Example code

```python
import torch.nn as nn
model = nn.Sequential(nn.Linear(12, 64), nn.ReLU(), nn.Linear(64, 1))
print(model)
```

A tiny network: 12 inputs, one hidden layer of 64 neurons, one output.

## Why it matters

It is the most common tool for deep learning today. Papers, courses and open models mostly use it.

## Common mistake

Using it for a plain table of data. A simple tool like scikit-learn is quicker there.

## Three principles

- **Just Python.** Networks are written as code.
- **Gradients for you.** It works out the math of learning.
- **Any chip.** CPU or graphics card, same code.

## Related terms

- [TensorFlow](https://learn.benibix.com/term/ai/tensorflow)
- [scikit-learn](https://learn.benibix.com/term/ai/scikit-learn)
- [Neural Network](https://learn.benibix.com/term/ai/neural-network)
- [Deep Learning](https://learn.benibix.com/term/ai/deep-learning)
- [Backpropagation](https://learn.benibix.com/term/ai/backpropagation)
- [Graphics Processing Unit (GPU)](https://learn.benibix.com/term/infrastructure/graphics-processing-unit)

## Told apart from

- [scikit-learn vs PyTorch](https://learn.benibix.com/compare/scikit-learn-vs-pytorch): People think scikit-learn is a smaller PyTorch, and it is not. scikit-learn holds the classic models, like trees, forests and k-means. It is built for tables that fit on one computer. PyTorch is for building and training neural networks, often on a graphics card. Most table jobs need only the first.

## Taught in

- [scikit-learn and PyTorch](https://learn.benibix.com/learn/ai-machine-learning/scikit-learn-and-pytorch): Machine Learning, 18/18

![Your Python code at the top splits two ways. Left, classic models for table data: scikit-learn and XGBoost, running on a CPU. Right, neural networks: PyTorch and TensorFlow, running on a CPU or a graphics card.](https://learn.benibix.com/diagrams/ai3-ml-frameworks.svg)

---

Source: https://learn.benibix.com/term/ai/pytorch
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
