Skip to content

Commit

Permalink
fix: more efficient implementation of layernorm (ivy-llc#23620)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomatillos authored and iababio committed Sep 27, 2023
1 parent 42ebaf8 commit a830408
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions ivy/functional/ivy/norms.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,8 @@ def layer_norm(
"""
mean = ivy.mean(x, axis=normalized_idxs, keepdims=True)
var = ivy.var(x, axis=normalized_idxs, keepdims=True)
x = ivy.divide(
ivy.add(ivy.negative(mean), x), ivy.stable_pow(var, 0.5, min_base=eps)
)

x = (x - mean) / (var + eps) ** 0.5

if scale is not None:
if offset is not None:
Expand Down

0 comments on commit a830408

Please sign in to comment.