Matmul forward and backward
- Derive dA = dY Bᵀ and dB = Aᵀ dY from one entry of Y = AB, and check them with the shapes
- Why a weight shared by a whole batch gets the sum of the batch's gradients, and why PyTorch hides a missing sum
- Write a torch.autograd.Function that saves its inputs in forward and returns one gradient per input from backward
- Why backward uses the formula instead of calling autograd, and a Linear layer with a bias on top
- Prove it with gradcheck in float64, and know what each common bug looks like when it fails
- Answer the follow-ups on FLOPs, saved inputs, checkpointing and mixed precision
Matrix multiplication's backward, from a skeleton
One OpenAI ML engineer candidate reports an ML coding round that asked for a matrix multiplication's forward pass and backprop in PyTorch, starting from a code skeleton (1 report). Matmuls do most of a transformer's arithmetic, so the question tests whether you can write a backward pass that autograd usually writes for you. Our version hands you this skeleton:
class MatMul(torch.autograd.Function):
@staticmethod
def forward(
ctx: FunctionCtx, a: torch.Tensor, b: torch.Tensor
) -> torch.Tensor:
...
@staticmethod
def backward(
ctx: FunctionCtx, grad_out: torch.Tensor
) -> tuple[torch.Tensor, torch.Tensor]:
...
forward returns a @ b. That's one line. backward is the whole job: it gets the gradient of the loss with respect to the output, and it returns one gradient for a and one for b. ctx is the object that carries tensors from one to the other. Its type, FunctionCtx, comes from torch.autograd.function.
The practice comes in four levels. Level 1 is a 2-D a and b, checked by gradcheck. Level 2 gives a a batch axis, with one weight b shared by the whole batch. Level 3 allows any number of leading axes, and a b with a batch of its own. Level 4 puts a Linear layer on top and trains it.
You don't write it yet. The lesson derives the two gradients from one entry, handles a batch that shares the weight, plugs both into autograd, puts a Linear layer on top, and proves it all with gradcheck. At the end you solve the whole problem, level by level, in an interview simulation with a 40-minute timer.
This lesson builds on the backprop lesson, where the same two gradients came out of the shape rule in NumPy. Here you derive them from one entry, and hand them to PyTorch's autograd as a node of your own.
How autograd runs your Function
The skeleton is a node in autograd's graph, and it helps to see where it sits before you fill it in.
This is how PyTorch runs that picture:
- Autograd, PyTorch's gradient machinery, records each op whose inputs require grad as a node in a graph.
loss.backward()walks that graph in reverse and calls each node's backward with the gradient flowing in.- The results are added into the
.gradof the tensors you made withrequires_grad=True, such as the weights.
A torch.autograd.Function is a node of your own. You write its forward and its backward, and the engine calls your backward when its turn comes.
Read the two gradients off one entry of Y
One entry of Y is a row of A times a column of B
Start from one entry of the product, because both gradients fall out of it.
import torch
A = torch.tensor([[1., 2., 0.],
[0., 1., 3.]])
B = torch.tensor([[1., -1.],
[2., 0.],
[0., 1.]])
Y = A @ B
print(Y)
print(A[1] @ B[:, 0])
A is [[1, 2, 0], [0, 1, 3]], and B's first column is [1, 2, 0]. What is Y[1, 0], row 1 of A times column 0 of B?
dY is how the loss moves with each entry of Y
Some loss sits after . Write for : for each entry of , how fast the loss moves when that entry moves. It's one number per entry, so it has 's shape.
Backward is handed , as grad_out, and has to produce and : one number per entry of and of .
One entry of A reaches one row of Y
Nudge one entry of A and watch what moves:
A2 = A.clone()
A2[1, 0] += 0.001
print(A2 @ B - Y)
Nudge A[1, 0] up by 0.001. Which entries of Y move?
One entry of B reaches one column of Y
feeds column of , and in each it's multiplied by :
A (2, 3)B (3, 2)Y = A @ BdYAdd up its effect down the column:
That's column of times column of . Column of is row of , so it's entry of .
In the editor, write dB_entry(A, dY, p, j): that sum down column j, as a loop.
Every entry follows the same rule, so each gradient is one matmul
The two loops are the same rule written once for every entry.
In code, next to the forward:
| Code | |
|---|---|
| forward | y = a @ b |
| backward | grad_a = grad_out @ bᵀ |
| backward | grad_b = aᵀ @ grad_out |
Each gradient uses the other input, turned over, on the side where that input sat in the forward. In PyTorch, bᵀ is b.transpose(-1, -2).
In the editor, write grads(A, B, dY): both gradients, one matmul each.
The video builds the Jacobian, the grid of slopes of every output entry with respect to every input entry, one entry at a time.
Why a custom op has to supply its own backward, then this lesson's derivation on a 1 by 3 input and a 3 by 4 weight, where the Jacobian built entry by entry turns out to be W transposed. His X and W are this lesson's A and B.
The shapes leave one way to write each product
A gradient has the shape of its input
The derivation is the proof, but the shapes are the fastest check.
must be like , and must be like . With the practice tests' sizes, a is (3, 4), b is (4, 5) and grad_out is (3, 5). Try each product:
grad_out(3n,5m)@b.T(5m,4k)=result(3n,4k)matches a (3, 4)grad_a has n rows and so does grad_out, so grad_out goes on the left. The other factor must be (m, k), and the only one is b transposed.
grad_b has m columns and so does grad_out, so grad_out goes on the right. The other factor must be (k, n), which is a transposed.
Forget the formulas under pressure and you can rebuild them this way in a few seconds. With the practice's names:
| Tensor | Shape | What it is |
|---|---|---|
a | (n, k) | the first input |
b | (k, m) | the second input, a weight |
y | (n, m) | the output, a @ b |
grad_out | like y | handed to backward |
grad_a | like a | grad_out @ b.transpose(-1, -2) |
grad_b | like b | a.transpose(-1, -2) @ grad_out |
In the editor, write shapes(n, k, m): the shapes of grad_out, grad_a and grad_b as tuples, for any sizes.
Square shapes can't tell right from wrong
Make every size 4, and both products fit:
grad_out(4n,4m)@b(4k,4m)=result(4n,4m)matches a (4, 4)Make every size the same and every arrangement fits. Shapes are a check, not a proof. The derivation is the proof, and gradcheck, near the end, is the test.
In the editor, write errors(n, k, m): whether the wrong product, grad_out @ b, fails loudly at those sizes.
Swap the last two axes, never use .T
Once a has a batch axis, how you transpose matters.
x = torch.randn(2, 3, 4)
print(x.mT.shape)
print(x.T.shape)
x is (2, 3, 4), a batch of two matrices. What are x.mT.shape and x.T.shape?
A weight shared by a batch gets the sum of the batch's gradients
Each batch element is its own matmul
A real layer sees a whole batch at once.
In a real layer, a carries a batch: (S, n, k), sequences of tokens each. The practice calls the batch size B, but here is the matrix, so the batch size is . The weight b stays (k, m), one matrix for the whole batch. Step through a batch of two:
a @ b broadcasts b across the batch. In symbols, for each element from 1 to .
grad_a needs nothing new. grad_out @ b.transpose(-1, -2) broadcasts the same way and gives each element its own .
b is used S times, so it collects S gradients, added up
A variable used in several places collects a gradient from each use, added up. b is used once per batch element:
is element 's input and is its output's gradient.
When the batch is folded into the rows, as (S·n, k), the product aᵀ @ grad_out does this adding for you, because the sum over rows happens inside the matmul. Here the batch is an axis of its own, outside the matmul, so the sum is yours to write.
| Tensor | Shape | What it is |
|---|---|---|
a | (S, n, k) | a batch of inputs |
b | (k, m) | one weight for the whole batch |
y, grad_out | (S, n, m) | outputs and their gradient |
grad_a | (S, n, k) | grad_out @ b.transpose(-1, -2) |
per-element grad_b | (S, k, m) | a.transpose(-1, -2) @ grad_out |
grad_b | (k, m) | that, summed over dim=0 |
In the editor, write grad_b_loop(a, grad_out): the sum, one batch element at a time.
Three ways to write the sum, all equal
A loop is clear, but not how you'd write it in practice. Here are two more ways, by_einsum and by_fold, which you write in this step's task, against the sum of the batched products:
torch.manual_seed(0)
a = torch.randn(2, 3, 4, dtype=torch.float64)
grad_out = torch.randn(2, 3, 5, dtype=torch.float64)
s1 = (a.transpose(-1, -2) @ grad_out).sum(dim=0)
s2 = by_einsum(a, grad_out)
s3 = by_fold(a, grad_out)
print(tuple(s1.shape), torch.allclose(s1, s2), torch.allclose(s1, s3))
Three ways to get b's gradient over a batch: sum the batched products, an einsum, or fold the batch into the rows first. Do they agree?
Sum over every leading axis, behind an if
A batch can have more than one leading axis.
a | Per-element grad_b | Sum over |
|---|---|---|
(n, k) | (k, m) | nothing |
(S, n, k) | (S, k, m) | axis 0 |
(P, S, n, k) | (P, S, k, m) | axes 0 and 1 |
For code that takes a 2-D or a 3-D a, or more, sum every axis in front of the last two:
if grad_b.dim() > b.dim():
grad_b = grad_b.sum(dim=tuple(range(grad_b.dim() - b.dim())))
Read the second line from the inside out:
grad_b.dim() - b.dim()counts the leading axes thatbdoesn't have.rangenumbers them from 0.tuplehands them tosumas the axes to remove:(0,)for a 3-Daand(0, 1)for a 4-D one.
What's left has b's shape.
The if matters. With a 2-D a, the tuple is empty.
Without the if, a 2-D a gives grad_b.sum(dim=()). What happens?
PyTorch hides a missing sum, and NumPy doesn't
Here is a backward that forgets the sum:
from torch.autograd.function import FunctionCtx
class NoSum(torch.autograd.Function):
@staticmethod
def forward(
ctx: FunctionCtx, a: torch.Tensor, b: torch.Tensor
) -> torch.Tensor:
ctx.save_for_backward(a, b)
return a @ b
@staticmethod
def backward(
ctx: FunctionCtx, grad_out: torch.Tensor
) -> tuple[torch.Tensor, torch.Tensor]:
a, b = ctx.saved_tensors
# (2, 4, 5), never summed
grad_b = a.transpose(-1, -2) @ grad_out
print("returned", tuple(grad_b.shape))
return grad_out @ b.transpose(-1, -2), grad_b
a = torch.randn(2, 3, 4, requires_grad=True)
b = torch.randn(4, 5, requires_grad=True)
NoSum.apply(a, b).sum().backward()
print("b.grad ", tuple(b.grad.shape))
NoSum's backward returns a.transpose(-1, -2) @ grad_out for b, with no sum. What shape is that, before PyTorch sees it?
In NumPy, W is (4, 5) and an unsummed dW is (2, 4, 5). What shape is W - 0.1 * dW?
torch.autograd.Function: save in forward, return gradients in backward
With both gradients derived and the batch handled, the formulas go into a Function.
Here's the whole Function, with the sum, and one call to it:
class MatMul(torch.autograd.Function):
@staticmethod
def forward(
ctx: FunctionCtx, a: torch.Tensor, b: torch.Tensor
) -> torch.Tensor:
"""a: (..., n, k), b: (k, m). Returns a @ b, (..., n, m)."""
ctx.save_for_backward(a, b)
return a @ b
@staticmethod
def backward(
ctx: FunctionCtx, grad_out: torch.Tensor
) -> tuple[torch.Tensor | None, torch.Tensor | None]:
"""Returns (grad_a, grad_b), shaped like a and b."""
a, b = ctx.saved_tensors
grad_a = grad_b = None
if ctx.needs_input_grad[0]:
grad_a = grad_out @ b.transpose(-1, -2)
if ctx.needs_input_grad[1]:
grad_b = a.transpose(-1, -2) @ grad_out
# sum the batch axes
if grad_b.dim() > b.dim():
grad_b = grad_b.sum(dim=tuple(range(grad_b.dim() - b.dim())))
return grad_a, grad_b
a = torch.randn(2, 3, 4, requires_grad=True)
b = torch.randn(4, 5, requires_grad=True)
y = MatMul.apply(a, b)
print(tuple(y.shape), type(y.grad_fn).__name__)
y.sum().backward()
print(tuple(a.grad.shape), tuple(b.grad.shape))
a is (2, 3, 4) and b is (4, 5). After y.sum().backward(), what shapes are a.grad and b.grad?
You call an instance, MatMul()(a, b), instead of MatMul.apply(a, b). What happens?
ctx carries tensors from forward to backward
Tensors go in through ctx.save_for_backward(...) and come back out of ctx.saved_tensors. The PyTorch docs ask for this route for every tensor that backward uses: it prevents wrong gradients and memory leaks.
Saving copies nothing. It keeps the tensor alive until backward has run.
Non-tensors, like an int or a float, go straight onto ctx as attributes: ctx.scale = scale.
The stub puts ctx in forward, the older of two styles. Since PyTorch 2.0 you can also write a forward without ctx, plus a separate setup_context(ctx, inputs, output) that does the saving. The docs recommend that style. The math is the same in both styles.
needs_input_grad skips a gradient nobody wants
In a first layer, a is raw data and b is the weight.
ctx.needs_input_grad holds one True or False per input, in order. What is it in a first layer?
Return one gradient per input, in forward's order
The engine has one more rule for what backward returns.
| Position | 0 | 1 | 2 |
|---|---|---|---|
forward(ctx, ...) takes | a | b | scale |
backward returns | grad_a | grad_b | None |
The engine matches gradients to inputs by position, not by name. Use None for an input that needs no gradient or isn't a tensor, like the float scale in this step's task.
The wrong count fails with function MatMulBackward returned an incorrect number of gradients (expected 2, got 1).
Backward gets one gradient per output of forward. Here that's only grad_out, shaped like y. Treat it as read-only: the docs say never to change it in place.
In the editor, write ScaledMatMul, a Function with three inputs: two tensors and a plain float that gets None.
Write ScaledMatMul, a torch.autograd.Function whose forward(ctx, a, b, scale) returns scale * (a @ b) for 2-D a and b. scale is a plain float, so it gets no gradient. Build the gradients from tensor ops, without calling autograd.
Autograd is off inside backward, so write the formula
Why write the formula at all, when autograd could work it out?
class Peek(torch.autograd.Function):
@staticmethod
def forward(ctx: FunctionCtx, a: torch.Tensor) -> torch.Tensor:
print("forward, grad mode on:", torch.is_grad_enabled())
return a * 2
@staticmethod
def backward(ctx: FunctionCtx, grad_out: torch.Tensor) -> torch.Tensor:
print("backward, grad mode on:", torch.is_grad_enabled())
return grad_out * 2
Peek.apply(torch.ones(3, requires_grad=True)).sum().backward()
Is grad mode, autograd's recording switch, on inside a custom forward, and inside its backward?
gradgradcheck checks the gradient of your backward itself. Does MatMul pass?
A Linear layer is MatMul plus a bias
The practice's last level puts a layer on top of your Function.
from torch import nn
class Linear(nn.Module):
def __init__(self, in_features: int, out_features: int) -> None:
super().__init__()
self.weight = nn.Parameter(torch.randn(in_features, out_features) / in_features ** 0.5)
self.bias = nn.Parameter(torch.zeros(out_features))
def forward(self, x: torch.Tensor) -> torch.Tensor:
"""x: (..., in). Returns (..., out)."""
return MatMul.apply(x, self.weight) + self.bias
layer = Linear(3, 1)
print([(name, tuple(p.shape)) for name, p in layer.named_parameters()])
Linear(3, 1) stores a weight and a bias as nn.Parameter. What does named_parameters() list?
Divide by the square root of in to keep the outputs' scale
A layer also has to start with weights of the right size.
torch.manual_seed(0)
x = torch.randn(1000, 400)
w = torch.randn(400, 300)
print(f"{(x @ w).std():.2f}", f"{(x @ (w / 400 ** 0.5)).std():.2f}")
x is (1000, 400) and w is (400, 300), both with spread 1. What is the spread of x @ w, and of x @ (w / √400)?
The practice trains it to the exact answer
The practice trains Linear(3, 1) on 64 random points of with plain SGD:
torch.manual_seed(0)
layer = Linear(3, 1)
x = torch.randn(64, 3)
y = x @ torch.tensor([[1.0], [-2.0], [0.5]]) + 0.3
opt = torch.optim.SGD(layer.parameters(), lr=0.1)
for step in range(1, 101):
loss = ((layer(x) - y) ** 2).mean()
if step in (1, 100):
print(step, f"{loss.item():.3g}")
opt.zero_grad()
loss.backward()
opt.step()
print(layer.weight.detach().flatten(), layer.bias.detach())
Train Linear(3, 1) with SGD for 100 steps on data made from weights [1, -2, 0.5] and bias 0.3, with no noise. Where do the weights end?
gradcheck proves the backward
One call checks every entry of every gradient.
torch.manual_seed(0)
a = torch.randn(2, 3, 4, dtype=torch.float64, requires_grad=True)
b = torch.randn(4, 5, dtype=torch.float64, requires_grad=True)
print(torch.autograd.gradcheck(MatMul.apply, (a, b)))
True
True means your backward agrees with a numerical estimate at every entry. A wrong one raises a GradcheckError that says where.
In the editor, write check(fn, *shapes): gradcheck on random float64 inputs of the shapes you name.
gradcheck builds the Jacobian two ways
gradcheck builds the Jacobian, the grid of every output's slope against every input, twice. Then it compares the two with allclose:
| Side | How it builds the Jacobian |
|---|---|
| Numerical | nudge one input entry by ±1e-6 and see how every output moves: one column per input entry |
| Analytical | run your backward with grad_out = 1 at one output entry and 0 elsewhere: one row per output entry |
| Then | compare the two grids with allclose |
The numerical side takes the central difference: the change in the outputs between the two nudges, divided by .
y is (2, 3, 5), a is (2, 3, 4) and b is (4, 5). How big is the Jacobian gradcheck builds?
Run it in float64
The nudge is tiny, so precision decides whether the check works.
a32 = a.detach().float().requires_grad_()
b32 = b.detach().float().requires_grad_()
print(torch.autograd.gradcheck(MatMul.apply, (a32, b32), raise_exception=False))
Run the same gradcheck on float32 copies of a and b. What does it return?
A worked example
Use the trick the practice's tests use. Pick a fixed matrix and set the loss to , which in code is (y * g).sum(). Then exactly, so you choose the gradient backward receives.
The code checks autograd against worked(), this step's task, which returns dA and dB from the formulas:
A = torch.tensor([[1., 2., 0.], [0., 1., 3.]])
B = torch.tensor([[1., -1.], [2., 0.], [0., 1.]])
G = torch.tensor([[1., 0.], [-1., 2.]])
a = A.clone().requires_grad_()
b = B.clone().requires_grad_()
loss = (a @ b * G).sum()
loss.backward()
print(loss.item())
dA, dB = worked()
print(torch.equal(a.grad, dA), torch.equal(b.grad, dB))
With loss = (a @ b * G).sum(), G is the gradient that arrives at Y. Does autograd agree with the formulas' dA and dB, from worked()?
Two batch elements, A with G and A2 with G2, share one b. What is b.grad?
What interviewers ask next
FLOPs: the backward costs twice the forward
The first follow-up is usually the cost.
| Product | Sizes | Multiply-adds | |
|---|---|---|---|
| Forward | y = a @ b | (n×k)(k×m) | nkm |
| Backward | grad_a = grad_out @ bᵀ | (n×m)(m×k) | nkm |
| Backward | grad_b = aᵀ @ grad_out | (k×n)(n×m) | nkm |
The forward is one matmul: multiply-adds, or FLOPs. The backward is two matmuls with the same three sizes, so it costs , twice the forward. A training step costs about three forwards.
That's the rule of thumb of 6 FLOPs per parameter per token: 2 in the forward and 4 in the backward. Kaplan et al. (2020) count the backward the same way, at about twice the forward.
For a 4,096 by 4,096 weight and a batch of 16,384 tokens, that's FLOPs forward and backward.
A first layer's input is raw data. What does that layer's backward cost, against its forward?
Memory: forward keeps its inputs alive
FLOPs are half the cost. Memory is the other half.
| Gradient | Needs | Cost |
|---|---|---|
grad_a | b, the weight, held anyway | nothing extra |
grad_b | a, an activation that could be freed after this matmul | 128 MiB for one (8, 2048, 4096) bf16 |
a is an activation, an intermediate result that could otherwise be freed. Activations are where training memory goes, because every linear layer in every block saves one like it.
The weight b is frozen. Which input can the forward skip saving for backward?
Save each block's input only, and rerun the block during backward. What does a training step cost now?
Why it's two matmuls and never the full Jacobian
An interviewer may ask why the backward isn't the textbook recipe, the gradient times the Jacobian.
| Numbers at n = k = m = 4,096 | |
|---|---|
| The full Jacobian ∂Y/∂A, (n·m) × (n·k) | , about : 1 PiB in fp32, nearly all of it zero |
| B itself, k × m | 16.8 million |
changes in a straight line with , so its backward is one more matmul: multiply by where the forward multiplied by . The same holds for , with .
So both gradients are matmuls with the forward's own three sizes: the same cost, the same fast kernels, and transposes that are free views.
The general recipe, the incoming gradient times the Jacobian, would never fit in memory. All but a share of its numbers are zero, because depends only on row of . gets the same answer without building any of it.
In the editor, write jacobian_entries(n, k, m) and nonzero_share(n).
Mixed precision needs two decorators
The last follow-up is precision.
| What runs | The result | |
|---|---|---|
| Forward, under autocast | a @ b runs in bf16 | y is bf16 |
| Backward, no decorator | grad_out bf16 @ b fp32 | a dtype error |
Backward, with custom_bwd | the same autocast state as forward | runs |
Under autocast, PyTorch's switch that runs matmuls in 16-bit floats, your forward's a @ b comes out in 16 bits. Your backward runs outside the autocast region, though. Two decorators fix it:
class MatMul(torch.autograd.Function):
@staticmethod
@torch.amp.custom_fwd(device_type="cuda")
def forward(
ctx: FunctionCtx, a: torch.Tensor, b: torch.Tensor
) -> torch.Tensor:
...
@staticmethod
@torch.amp.custom_bwd(device_type="cuda")
def backward(
ctx: FunctionCtx, grad_out: torch.Tensor
) -> tuple[torch.Tensor, torch.Tensor]:
...
With them, both gradient matmuls run in half precision. The engine casts each returned gradient to its input's dtype, so fp32 weights still get an fp32 .grad.
fp16 has one more hazard. What does it store for a gradient of 1e-8?
The practice problem, start to finish
That's every piece the practice problem needs. It asks for the four levels from the start of the lesson, from a blank file, and the interviewer follows up after each one.
1.
y = a @ bwithaof shape(8, 16)andbof shape(16, 32). Which line computes the gradient fora?2.Your backward ends with
return grad_b, grad_a. Withaof shape(3, 4)andbof shape(4, 5), PyTorch raises an error. What happens whenaandbare both(4, 4)?3.You average
grad_bover the batch instead of summing it. The practice's batched tests use a batch of 2. What do the tests see?4.
ais(S, n, k)andbis(k, m). Your backward returnsa.transpose(-1, -2) @ grad_outforband never sums it. What happens in PyTorch?5.
ais(n, k)andbis(k, m), and both need gradients. The forward costs 2nkm FLOPs. What does the backward cost?
Where this shows up
The reports behind this lesson, each with its source.
Same report, ML coding round: matrix multiplication forward pass and backprop in PyTorch, from a given code skeleton.
Practice
Sources (7)
- Extending PyTorch: Extending torch.autograd · PyTorch 2.15 documentation · Sep 16, 2026
“It should return as many tensors as there were inputs, with each of them containing the gradient w.r.t. its corresponding input.”
- torch.autograd.function.FunctionCtx.save_for_backward · PyTorch 2.15 documentation · Oct 28, 2026
“All tensors intended to be used in the backward pass should be saved with save_for_backward (as opposed to directly on ctx) to prevent incorrect gradients and memory leaks, and enable the application of saved tensor hooks.”
- torch.autograd.gradcheck.gradcheck · PyTorch 2.15 documentation · Oct 28, 2026
“The default values are designed for input of double precision. This check will likely fail if input is of less precision, e.g., FloatTensor.”
- Automatic Mixed Precision examples: Autocast and Custom Autograd Functions · PyTorch 2.15 documentation · May 7, 2026
“These ensure forward executes with the current autocast state and backward executes with the same autocast state as forward (which can prevent type mismatch errors)”
- torch.utils.checkpoint · PyTorch 2.15 documentation · Jul 27, 2026
“Activation checkpointing is a technique that trades compute for memory.”
- Scaling Laws for Neural Language Models · arXiv 2001.08361 · Jan 23, 2020
“Accounting for the backwards pass (approximately twice the compute as the forwards pass)”
- Training Deep Nets with Sublinear Memory Cost · arXiv 1604.06174 · Apr 21, 2016
“Specifically, we design an algorithm that costs O(sqrt(n)) memory to train a n layer network, with only the computational cost of an extra forward pass per mini-batch.”