MCPcopy Create free account
hub / github.com/apple/axlearn / l2_normalize

Function l2_normalize

axlearn/common/normalize.py:10–22  ·  view source on GitHub ↗

l2_normalize Normalizes along the dimension `axis` using an L2 norm. Args: x: Input tensor. axis: Dimension along which to normalize. eps: A lower bound value for the norm. Defaults to 1e-8. Returns: A Tensor with the same shape as x.

(x: Tensor, eps: float = 1e-8, axis: int = -1)

Source from the content-addressed store, hash-verified

8
9
10def l2_normalize(x: Tensor, eps: float = 1e-8, axis: int = -1) -> Tensor:
11 """l2_normalize Normalizes along the dimension `axis` using an L2 norm.
12
13 Args:
14 x: Input tensor.
15 axis: Dimension along which to normalize.
16 eps: A lower bound value for the norm. Defaults to 1e-8.
17
18 Returns:
19 A Tensor with the same shape as x.
20 """
21 sum2 = (x * x).sum(axis=axis, keepdims=True)
22 return x * jax.lax.rsqrt(sum2 + eps)

Callers 10

koleo_lossFunction · 0.90
forwardMethod · 0.90
forwardMethod · 0.90
test_l2_normalizeMethod · 0.90
forwardMethod · 0.90
forwardMethod · 0.90
test_quantizeMethod · 0.90
test_forwardMethod · 0.90

Calls

no outgoing calls

Tested by 3

test_l2_normalizeMethod · 0.72
test_quantizeMethod · 0.72
test_forwardMethod · 0.72