Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mlx/backend/cuda/layer_norm.cu
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ __global__ void layer_norm_vjp(
} else {
for (int i = index * N_READS; i < axis_size; ++i) {
float t = static_cast<float>(x[i]) - mean;
float wi = wn[i];
float gi = gn[i];
float wi = wn[i - index * N_READS];
float gi = gn[i - index * N_READS];
float wg = wi * gi;
factors = plus_f3(factors, {wg, wg * t, t * t});
}
Expand Down
11 changes: 10 additions & 1 deletion python/tests/test_fast.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,16 @@ def test_slice_into_layer_norm(self):
def test_layer_norm_grad(self):
eps = 1e-5
tolerances = {mx.float32: 5e-5, mx.float16: 1e-2, mx.bfloat16: 8e-2}
shapes = [(8, 100, 32), (3, 128), (3, 1024), (3, 4096), (8, 100, 8192)]
shapes = [
(8, 100, 32),
(3, 33),
(3, 36),
(3, 128),
(3, 1024),
(3, 1025),
(3, 4096),
(8, 100, 8192),
]
for dtype, tol in tolerances.items():
for shape in shapes:
with self.subTest(dtype=dtype, shape=shape):
Expand Down
Loading