(x, g, b, eps: float = 1e-5)
| 11 | |
| 12 | |
| 13 | def 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 | |
| 20 | def linear(x, w, b): # [m, in], [in, out], [out] -> [m, out] |
no outgoing calls
no test coverage detected