MCPcopy Create free account
hub / github.com/ml-explore/mlx / layer_norm

Function layer_norm

benchmarks/python/layer_norm_bench.py:10–20  ·  view source on GitHub ↗
(x, w, b, eps)

Source from the content-addressed store, hash-verified

8
9
10def layer_norm(x, w, b, eps):
11 ot = x.dtype
12 x = x.astype(mx.float32)
13 mu = mx.mean(x, -1, keepdims=True)
14 v = mx.var(x, -1, keepdims=True)
15 y = (x - mu) * mx.rsqrt(v + eps)
16 if w is not None:
17 y = y * w
18 if b is not None:
19 y = y + b
20 return y
21
22
23def time_layer_norm(N, dt):

Callers 1

time_layer_normFunction · 0.70

Calls 1

meanMethod · 0.80

Tested by

no test coverage detected