MCPcopy
hub / github.com/jaymody/picoGPT / layer_norm

Function layer_norm

gpt2.py:13–17  ·  view source on GitHub ↗
(x, g, b, eps: float = 1e-5)

Source from the content-addressed store, hash-verified

11
12
13def layer_norm(x, g, b, eps: float = 1e-5):
14 mean = np.mean(x, axis=-1, keepdims=True)
15 variance = np.var(x, axis=-1, keepdims=True)
16 x = (x - mean) / np.sqrt(variance + eps) # normalize x to have mean=0 and var=1 over last axis
17 return g * x + b # scale and offset with gamma/beta params
18
19
20def linear(x, w, b): # [m, in], [in, out], [out] -> [m, out]

Callers 2

transformer_blockFunction · 0.70
gpt2Function · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected