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

Function layer_norm

python/tests/test_fast.py:57–68  ·  view source on GitHub ↗
(x, weight, bias, eps)

Source from the content-addressed store, hash-verified

55
56
57def layer_norm(x, weight, bias, eps):
58 ot = x.dtype
59 x = x.astype(mx.float32)
60 mean = x.mean(axis=-1, keepdims=True)
61 var = x.var(axis=-1, keepdims=True)
62 x = (x - mean) * mx.rsqrt(var + eps)
63 x = x.astype(ot)
64 if weight is not None:
65 x = x * weight
66 if bias is not None:
67 x = x + bias
68 return x
69
70
71class TestFast(mlx_tests.MLXTestCase):

Calls 1

meanMethod · 0.80

Tested by

no test coverage detected