Note: This post is a writeup of a set of slides from May 2025. The text is essentially unchanged from the slides, just reformatted as a post; the original slides are available as a PDF.
Outline
We will begin by formalizing deep learning as an optimization problem and briefly cover:
- terminology
- training
- gradient descent
- backpropagation
Then we will discuss how deep learning is not quite an optimization problem, at least in the way we formulated it. How do our goals vary from the simple formulation and what can we do about it?
Note: This is “Eric’s take” rather than anything comprehensive. Everything discussed has many alternatives, variants, and generalizations — it’s a big field.
Deep learning as optimization
Deep learning terminology
A deep learning model (a network) is a parametrized function , where:
- are the parameters of the network. In 2025, is typically in the millions or billions, although smaller networks can still be practical and useful.
- Llama 3 70B, an open-weights large language model (LLM) from Meta, has 70B parameters
- is the input to the network. While we often think of inputs as living in other domains, we will assume they have been injected into prior to being passed to the network.
- For a small 28x28 pixel grayscale image, .
- For Llama 3 70B, token ids (its “context length”); the first layer embeds each into (its “embedding dimension”), numbers in all
- is the architecture, typically a composition of simple functions called layers.
- The architecture can be quite important, as a “good” architecture can make a problem tractable with much less data.
- is the output of the network.
- The output dimension varies widely. In classic tasks like regression or classification, is usually much less than ; for example, in binary classification.
- However for generative models and LLMs, can be quite large; for Llama 3 70B, for example, .
Training
Training is optimizing a network over its parameters to minimize a loss function .
To train a network, one needs a “train set” consisting of pairs . Here, are the inputs to the network, and are the corresponding desired outputs.
Typically, training proceeds by attempting to solve the following optimization problem:
That is, we want to optimize over the parameters to minimize the loss of over the train set.
This approach is sometimes called “empirical risk minimization”: we seek to minimize the “risk” (loss) empirically over the data we have (the train set).
Gradient descent
Often, the optimization problem
is solved by variants of gradient descent. Gradient descent is a simple iterative algorithm. To minimize some function over some values , we start with some initial point , then iteratively compute
where is a hyperparameterA hyperparameter is a value that is chosen before training and fixed, rather than optimized over called the learning rate (or step size). Here is the gradient of with respect to , also denoted for clarity sometimes.
In some scenarios, this procedure can be guaranteed to converge, meaning the sequence of tends toward some fixed limit. This is neither necessary nor sufficient for it to be useful.
Applying gradient descent to deep learning models
Recall that the optimization problem we want to solve is:
To solve this with gradient descent (directly/naively), our function must be
That is, to perform one update of gradient descent we pass through the entire train set. In practice, we often perform stochastic gradient descent instead:
- Initialize with some point
- At step , draw a random pair from the train set at random
- Update the parameters as
Advantages of stochastic gradient descent (SGD)
Stochastic gradient descent has several important advantages over ordinary gradient descent:
- if the train set is very large (or infinite, in the case of randomly generated data), we might never finish completing a single update. Instead, with SGD, a single update can be finished relatively quickly.
- the random noise incurred by performing individual random updates can actually be helpful. The model “jumps around” more in parameter space over the course of training, which can help escape local minimaThis is a thing people say, and it makes sense, but I haven’t read any papers about it nor ever tried full-dataset gradient descent..
SGD variants
In practice, there are often many more adjustments made to SGD. For example:
- rather than performing updates with a single sample , a batch (or equivalently, minibatch) of such samples is used, so the update step becomeswhere is the th batch of training data.
- the learning rate may be set to decay over time (“learning rate scheduler”) or depend on previous updates in some deterministic fashion (adaptive step size) or be divided by the batch size (convention)
- a “momentum” term may be added to the update rule, consisting of an exponentially decaying average of previous gradients
- many more…
Review: Jacobians
Let be a vector-valued function. Then we can write it as scalar-valued functions as:
Then the Jacobian matrix of at is defined as:
which is the matrix of partial derivatives.
Computing the gradient
Recall that is frequently composed of simpler functions called layers. The gradient of can thus be computed via the chain rule from the gradient of each individual layer.
The chain rule says if , then we can take the derivative with respect to as
This is a matrix-multiplication between and . If we had for some value , then
we have matrix multiplications. The computational complexity of this operation depends on the sizes of all the individual matrices, and the order in which the product is conducted. Since matrix multiplication is associative, , we can choose the order to minimize the computation time.
Backpropagation as optimized matrix multiplication associativity
Wikipedia gives the concrete case that if A is a 10 × 30 matrix, B is a 30 × 5 matrix, and C is a 5 × 60 matrix, then
- computing needs (10×30×5) + (10×5×60) = 1500 + 3000 = 4500 operations, while
- computing needs (30×5×60) + (10×30×60) = 9000 + 18000 = 27000 operations.
using that the straightforward multiplication of a matrix that is by a matrix that is requires ordinary multiplications and ordinary additions.
Backpropagation is the insight that when , that is, there are many fewer outputs than inputs, the best order in which to conduct this large matrix product is often from the output layer back toward the input.
Deep learning as human-in-the-loop meta-optimization
Deep learning is not a tractable mechanical optimization problem
The goals of deep learning frequently differ from solving the optimization problem
as follows:
- the loss function is often chosen for computational convenience (nice smooth derivatives). Perhaps the actual evaluation of the output on a sample requires an extensive simulation or is otherwise intractable.
- we don’t actually care about the train set! Those are the examples we already labeled, we know the idealized output for each . We typically care about performance on new, potentially never-seen-before data.
Typically, what we want to solve is more like:
where:
- “real world” represents the set of all possible inputs
- captures that some inputs are more important than others and may have a higher weight. We may not know in advance which these are.
- represents some intractable evaluation like “is the same output that a panel of human experts would provide after deliberative review of ” or “is a ‘good answer’ to a plain-text question encoded as a vector?”
and typically each of those items is infeasible to obtain or compute in general, and we have little hope that we can run some mechanical code (e.g. gradient descent) to solve this.
Deep learning as meta-optimization
So, how do we tackle deep learning problems? We manually approximate each quantity in the previous intractable problem and iterate, iterate, iterate (“grad-student descent”).
Typically, this involves:
- collecting a train and test dataset
- iterating over update rules (“optimizers”), architectures, loss functions, initialization procedures, hyperparameters, and an increasing variety of other techniques (regularization, data augmentation, self-supervised pretraining, data resampling, ensembles of networks, etc.)
- until one finds a network that performs “well” on the test dataset, typically evaluated in many different domain-specific ways (not just an average loss)
One test dataset is not enough
The process of developing a network sometimes “burns” the test dataset: while the network wasn’t trained on it, the optimization of generating the network has encoded dataset-specific properties into the network, such that it won’t perform quite as well on truly unseen data. Alternatively, the test dataset may not be truly representative of real-world data.
So, a truly held-out test dataset must be collected and evaluated. If performance is not up-to-snuff, or the network shows performance issues down the line, the whole process is repeated.
Alternative philosophy: bootstrapping proxies
Another complementary way to see deep learning is as an opportunistic exploitation of proxies to the true problem we want to solve:
- Gradient-based optimization is an incredibly effective tool, so let’s change our problem to one we can use it on
- Statistical sampling is powerful and the performance of statistical estimates typically depends on the number of samples you have, not the total population size.
- e.g. you can get opinion polls of 300M Americans with ~3% margin of error by surveying just 1,000 people… as long as they are uniformly randomly sampled (they aren’t)
- truly representative test sets don’t need to be huge (the problem is they aren’t truly representative)
Instead of solving intractable problems, find a sequence of similar-but-tractable oneswith “tractable” being more important than “similar”.
Why do all that?
Machine learning approaches (deep learning + classical ML) can take some problems that have been at < 50% solved for decades to 80% solved in days/weeks/months and to 95%+ solved in months/years, and frequently the best performance comes from deep learning models. This approach fundamentally improves the capabilities of computers.
That is not to say we can’t do better than deep learning, nor that deep learning techniques can tackle every problem. We almost certainly can and will do better in time. But deep learning is likely an important step in the journey.
