What an elementwise function does to a shape
shape▲△△State the output shape of an elementwise activation applied to a tensor of shape , and the shape of its Jacobian if written out in full. Then name three operations that look like activations but do not preserve shape or elementwiseness, and say where each belongs.
Hint
The full Jacobian of a map from numbers to numbers is , even when almost all of it is zero.
Solution
The output shape. — identical. That is the defining property: an elementwise function applies a scalar map to each entry independently, so nothing about the arrangement changes.
The Jacobian’s shape. Flattening the tensor to numbers, the full Jacobian is . At , , that is entries — around petabytes in bf16.
Nobody stores it, and the reason is the point. The Jacobian is diagonal: whenever , because depends on alone. So it is represented by its diagonal entries, and the backward pass is one elementwise multiply rather than a matrix product. Elementwiseness is not a stylistic choice — it is what makes the backward pass affordable (I.3.X08 shows the contrast).
Three impostors.
Softmax. Shape , so it passes the shape test. But entry depends on every entry in its row, so its Jacobian is dense within each row — blocks, not a diagonal. It is a normalisation, and it belongs with the losses in Chapter I.4 and with attention in II.3.
LayerNorm. Same shape in and out, and again not elementwise: subtracting the mean and dividing by the standard deviation couples every entry in the normalised group. Its backward pass has three terms rather than one, which is exactly problem I.8.B02. It belongs in Chapter I.8.
Max-pooling. Not even shape-preserving: for a window. It is a downsampling, its Jacobian routes each output gradient to exactly one input, and it belongs in Chapter I.11.
The test to remember. Ask whether changing one input entry can change any other output entry. If yes, it is not elementwise, its Jacobian is not diagonal, and its backward pass is not one multiply — three consequences that always arrive together.