(x, weight, bias, eps)
| 55 | |
| 56 | |
| 57 | def 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 | |
| 71 | class TestFast(mlx_tests.MLXTestCase): |
no test coverage detected