The deep learning big bang
Why did in 2012 what did not work in 1990?
Lesson complete
If you like:
Backpropagation was published in 1986, and convolutional networks were reading zip codes by 1989. Yet the takeoff of deep learning, networks with many layers, came only in 2012. What changed?
No voice: the lesson advances on its own with subtitles.
The voice for this lesson is being recorded: for now it advances on its own with subtitles.
Review modeComment on this stepI finished the lesson
What you will achieve
- Explain why deep learning took off around 2012: massive data, compute with GPUs, and a few training tricks.
- Predict when a GPU beats a CPU at multiplying matrices and why its advantage grows with the size of the problem.
- Explain what a residual connection does to the gradient and why it makes it possible to stack many more layers.
Key ideas
- The takeoff of deep learning did not come from a new idea, but from three ingredients that coincided: massive data, compute, and training tricks.
- ImageNet put millions of labeled photos within everyone’s reach, and the ILSVRC contest measured progress with a common yardstick: the top-5 error.
- A GPU multiplies matrices with thousands of cores at once, exactly the work of training; its advantage grows with the size of the problem.
- AlexNet (2012) cut the top-5 error from the runner-up’s 26.2% to 15.3% with ReLU, dropout, and two GPUs; GPU memory already limited the size of the network.
- A residual connection, y = x + F(x), gives the gradient a direct path and made networks of more than a hundred layers possible; the compute of the largest training runs doubled every few months.
What many people believe
Common belief Deep learning took off in 2012 because someone finally invented a revolutionary idea.
What is true Backpropagation and convolutions already existed in the 1980s and 1990s, and training on GPUs had even been tried before. What changed was scale: millions of labeled images, GPUs, and a few tricks (ReLU, dropout, residual shortcuts).
Check yourself
Four questions. No grade, no account: they just show whether the idea stuck.
Under the hoodFor those who want the math and the code. You do not need it to follow the course.
The 2012 numbers
From the AlexNet paper (Krizhevsky, Sutskever and Hinton, 2012): eight layers with weights (five convolutional and three dense), about 60 million parameters, about 650,000 neurons, more than 1.2 million training images, and five to six days on two GTX 580 3 GB GPUs. The input has 150,528 values (). Two more details from the same paper: in its figure 1, a four-layer network on CIFAR-10 reached 25% training error six times faster with ReLU than with tanh (the authors note the effect varies with the architecture), and dropout, with probability 0.5 in the first two dense layers, was used because without it the network overfit substantially, at the cost of roughly doubling the iterations needed.
| Model in ILSVRC 2012 | Top-5 error |
|---|---|
| SIFT + Fisher vectors (runner-up) | 26.2% |
| 1 convolutional network (validation) | 18.2% |
| 5 networks averaged | 16.4% |
| 7 networks, 2 of them pre-trained on 15 M images | 15.3% |
So the “15.3%” figure comes from an ensemble of seven networks and extra data; with only the contest data it was 16.4%. Even so, the gap to the runner-up is huge.
Multiplying matrices: why the GPU wins
The product of two matrices is
That is independent cells, each costing multiply-adds: in total, or floating-point operations (FLOP: one addition or multiplication with decimals). With cores doing one multiply-add per step, the ideal number of steps is
With (GTX 580) the ideal ceiling on the advantage is 64; with (RTX 3060), 448. It is an idealized count: it ignores memory bandwidth, the cost of moving data to the GPU, and the fact that each GPU core is slower than a CPU core. The real measurements of Raina, Madhavan and Ng (2009), with a GTX 280 GPU against a dual-core CPU, were between 12.9 and 72.6 times faster, depending on the model size.
A chip’s peak speed is : TFLOP/s for the GTX 580 (the figure OpenAI uses) and, by the same arithmetic, about 12.7 TFLOP/s for the RTX 3060.
The cost of training AlexNet
According to the estimate by Amodei and Hernandez (OpenAI, 2018), the forward pass costs about multiply-adds per image; training adds 2 operations per multiply-add, the backward pass (a factor of 3), and about 90 passes over the dataset:
That is consistent with two GTX 580s for 5.5 days at 33% of their peak, which is what OpenAI assumes: . Since 2012 (from AlexNet to AlphaGo Zero, in late 2017), OpenAI measured the compute of the largest training runs doubling every 3.4 months; later estimates (Sevilla et al., 2022) give about 6 months for the deep learning era. Either way, growth is exponential.
The gradient through the layers
In a plain stack, and the gradient flows back as
so its norm is multiplied, at each layer, by a factor of roughly . With the era’s “standard” initialization, (Glorot and Bengio, 2010, eq. 15), the factor is about 0.5; in the lesson’s toy it comes out ≈ 0.55, and .
With a shortcut, and, according to He et al. (2016, eq. 5),
The term carries the gradient from the output to any layer without passing through any weight. In the toy, each block also adds its contribution and the norm grows a little (between 2 and 18 at 40 layers, depending on the seed).
What the toy does not say
The toy network is untrained, uses no normalization, and all its layers are alike. In real networks, initialization and batch normalization keep signals healthy. In fact, He et al. (2015, §4.1 and figure 1) argue that the difficulty of training deep plain networks does not seem to come from vanishing gradients: their plain networks had gradients of healthy norm and still the 34-layer one had higher training error than the 18-layer one, and the 56-layer one more than the 20-layer one on CIFAR-10. They called it the degradation problem. Their hypothesis is that it is easier for a block to learn (identity) than to fit an identity with nonlinear layers; the authors themselves leave that explanation as an open question. What was measured is clear: with shortcuts, networks of 50, 101, and 152 layers improved with depth. ResNet-152 (11.3 billion multiply-adds) costs less than VGG-19 (19.6 billion); on its own it reached 4.49% top-5 error on validation, and an ensemble of six models, 3.57% on the test set.
In code
import numpy as np
def grad_norms(depth, residual, width=16, seed=0):
rng = np.random.default_rng(seed)
W = rng.normal(0, np.sqrt(1/3) / np.sqrt(width), size=(depth, width, width))
h = rng.normal(size=width)
cache = []
for l in range(depth): # forward pass
t = np.tanh(W[l] @ h)
cache.append(t)
h = h + t if residual else t
g = np.ones(width) / np.sqrt(width) # gradient of norm 1 at the output
norms = [np.linalg.norm(g)]
for l in reversed(range(depth)): # backpropagation
branch = W[l].T @ (g * (1 - cache[l] ** 2))
g = g + branch if residual else branch # with a shortcut, the gradient passes untouched and the branch is added
norms.append(np.linalg.norm(g))
return norms # norms[k]: norm after k layers backward
for res in (False, True):
n = grad_norms(40, res)
print("with shortcuts" if res else "plain", f"after 10 layers: {n[10]:.2e} after 40: {n[40]:.2e}")
# plain after 10 layers: 5.30e-03 after 40: 1.16e-10
# with shortcuts after 10 layers: 2.51e+00 after 40: 1.48e+01
The exact numbers depend on the seed and the random generator (the lesson’s gradients.py file also checks backpropagation against finite differences); the order of magnitude does not. And the ideal race count:
from math import ceil
def steps(n, cores): # n² independent cells; each costs n multiply-adds
return ceil(n * n / cores) * n
print(steps(64, 8), steps(64, 512), steps(64, 3584)) # 8-core CPU, GTX 580, RTX 3060
# 32768 512 128
What comes next
Residual connections and normalization reappear in every block of the transformer (lesson 22). Lesson 14 moves from seeing to representing meaning with embeddings. The accounting of FLOPs, data, and cost is formalized in lesson 24, and GPU memory, which already limited AlexNet, rules in lesson 25.
Decision lens
What this idea means if your job is to decide, not to code.
- When someone says “our model is better,” ask what changed: more data (whose, and under what license?), more compute (how many GPU hours, at what cost?), or a better method. Those are the three engines of modern progress.
- A result on a public benchmark describes a specific task, not yours: a 3.57% error on ImageNet does not tell you how often it will fail on your photos. Ask for a test with your own data and with the real cost of each kind of error.
- Compute is a budget and access item: GPUs bought or rented by the hour, with limited memory. Training a large model from scratch is out of reach for almost every organization; the usual route is to start from a pre-trained one.
- Deeper or bigger is not automatically better: without the right ideas (normalization, shortcuts), a deep network does not even train well. Ask for results on unseen data, not just the number of parameters or layers.
Terms in this lesson
- Backpropagation An algorithm that computes the gradient of the loss with respect to every weight of a network in a single backward sweep, applying the chain rule layer by layer. It computes the blames; it does not move the weights (in the 1986 paper, the name covered the whole learning procedure).
- Gradient The list of the slopes of the error, one for each weight. Seen as an arrow, it points to where the error rises fastest.
- Vanishing gradient The phenomenon in which the gradient (the blame) is multiplied by factors below one as it travels back through many steps or layers and ends up near zero, so what is far away is not learned. With factors above one the opposite happens: the gradient explodes.
- ReLU Rectified linear unit: an activation function that returns zero if the sum is negative and the sum itself if it is positive, max(0, z). A hinge with a single corner.
- Overfitting When a model learns the noise in its training data and therefore fails on new data. It shows as a large gap between training and validation error.
- Regularization Any change to learning meant to reduce the error on new data, even if it does not lower the training error. The simplest penalizes model complexity (for example, large weights); early stopping and dropout are other forms.
- Convolutional network (CNN) A neural network that uses convolutions, activations, and pooling to process grid-structured data such as images.
- Layer A group of neurons that receive the same inputs and compute at the same time. A network is a chain of layers: input, one or more hidden ones, and output.
- Deep network A network with several hidden layers. Each layer builds on what the previous one already transformed; for certain functions, this reaches complex shapes with far fewer neurons than a single wide layer.
- Forward pass Computing a network’s output: the numbers move on layer by layer, from input to output.
- Weight (w) In a linear model, the number that multiplies the input: the slope of the line. It tells how much the prediction rises for each unit the input grows.
- Parameter Each of the numbers a model adjusts while training and in which it stores what it learned.
- GPU Graphics processing unit: a chip with hundreds or thousands of simple cores, built to draw graphics and very efficient at multiplying matrices in parallel, the central operation of training.
- ImageNet A database of more than fourteen million images labeled by people, in more than twenty-one thousand categories. Its ILSVRC contest subset (a thousand classes, more than 1.2 million training photos) was the proving ground of computer vision.
- Deep learning Machine learning with many-layered neural networks that learn the useful features themselves, from edges to objects, from large amounts of data and compute.
- Residual connection (shortcut) Adding a block’s input to its output: y = x + F(x). It gives the gradient a direct path backward and made it possible to stack many more layers.
- Compute The amount of arithmetic operations needed to train or run a model. Along with data and algorithms, it is one of the three engines of progress in machine learning.
- Dropout A technique against overfitting: at each training step every neuron of a layer is switched off at random with some probability (0.5 in AlexNet), so no neuron can depend on a particular other one.
Full transcript
Sources
- Krizhevsky, A., Sutskever, I., Hinton, G. E. (2012). ImageNet Classification with Deep Convolutional Neural Networks
- Russakovsky, O., Deng, J., Su, H., et al. (2015). ImageNet Large Scale Visual Recognition Challenge
- Deng, J., Dong, W., Socher, R., Li, L.-J., Li, K., Fei-Fei, L. (2009). ImageNet: A Large-Scale Hierarchical Image Database
- He, K., Zhang, X., Ren, S., Sun, J. (2015). Deep Residual Learning for Image Recognition
- He, K., Zhang, X., Ren, S., Sun, J. (2016). Identity Mappings in Deep Residual Networks
- Glorot, X., Bengio, Y. (2010). Understanding the difficulty of training deep feedforward neural networks
- Raina, R., Madhavan, A., Ng, A. Y. (2009). Large-scale Deep Unsupervised Learning using Graphics Processors
- Amodei, D., Hernandez, D. (2018). AI and Compute
- Sevilla, J., Heim, L., Ho, A., Besiroglu, T., Hobbhahn, M., Villalobos, P. (2022). Compute Trends Across Three Eras of Machine Learning
- Hinton, G. E., Srivastava, N., Krizhevsky, A., Sutskever, I., Salakhutdinov, R. R. (2012). Improving neural networks by preventing co-adaptation of feature detectors
- Szegedy, C., et al. (2014). Going deeper with convolutions
CommentsThis lesson’s public conversation: questions, facts to check, ideas.
Comments live in GitHub Discussions, in the course’s public repository; writing one requires a GitHub account. They load from giscus.app when you open this section. The course reviewers read them, and if a change is accepted, it is applied in both languages. Open the thread on GitHub