Basic Neural Network
Feedforward networks from first principles — approximation theory, the statistical meaning of loss functions, reverse-mode differentiation, and a memory-accounting treatment of why CUDA runs out of memory — followed by a DeepSpeed implementation.
The running example is deliberately trivial: recovering with a one-parameter-pair linear model. The point is not the model. It is that every mechanism you will use at 70B parameters — the optimizer's memory footprint, FP16 loss scaling, the batch-size invariant, the allocator's fragmentation behaviour — is already present and observable at this scale, where you can reason about it exactly.
1. What a Neural Network Is
A neural network is a parametric family of functions built by composing affine maps with a fixed pointwise nonlinearity. Training is the search for a minimizing an empirical risk. That is the whole object; the biological framing is historical.
Formally, for depth :
where each is affine and acts elementwise. The parameter vector is the concatenation of all .
The nonlinearity is what makes the object non-trivial. If every were the identity, the composition of affine maps would collapse:
A 100-layer linear network has exactly the expressive power of one affine layer. Depth buys nothing without nonlinearity — a fact worth stating precisely, because it is the reason activation functions exist at all.
1.1 The single unit
The pre-activation is an inner product: geometrically, is a direction in input space and measures the signed projection of onto it, offset by . The set is a hyperplane, and determines how sharply the unit distinguishes the two sides of it. A ReLU unit computes a hinge about that hyperplane; a network of them tiles input space into polyhedral regions on each of which is affine.
2. Activation Functions
2.1 The classical saturating pair
Sigmoid.
The derivative is bounded by , attained at . This bound is the entire story of why deep sigmoid networks were untrainable. Chaining layers multiplies such factors, so gradient magnitude decays at least as fast as — at that is a factor of before any weight matrix is considered. Sigmoid is also not zero-centred, so all gradients entering a downstream weight share a sign, producing the characteristic zig-zag in optimization trajectories.
Hyperbolic tangent.