Implement layer_norm(x, gamma, beta, eps=1e-5) that normalizes x over its last dimension, then applies a learnable affine transform.
Shapes:
x has arbitrary leading shape, with last dim D.gamma (scale) and beta (shift) each have shape (D,).For each example (all dims except the last), compute mean and variance over the last dim, then
with broadcasting on and .
dim=-1 with keepdim=True so the result broadcasts cleanly against x.D, not D - 1. This is what nn.LayerNorm does.gamma and beta are 1-D; broadcasting handles the leading dims automatically once their shape matches the last dim of x.