Example 1
Arguments: [
[
[
1,
-1
]
],
[
1,
1
],
0
]
Expected result: [
[
1,
-1
]
]Each row has mean square 1, so [1,-1] is unchanged.
Tensor and numerical foundations · Medium
Problem 4 of 50 · Python and NumPy
Implement RMSNorm over the last dimension of a two-dimensional activation matrix: y = x * weight / sqrt(mean(x²) + eps). Do not subtract the mean. Return the same shape as x.
def rms_norm(x, weight, eps):Arguments: [
[
[
1,
-1
]
],
[
1,
1
],
0
]
Expected result: [
[
1,
-1
]
]Each row has mean square 1, so [1,-1] is unchanged.
Arguments: [
[
[
0,
0
]
],
[
2,
3
],
0.25
]
Expected result: [
[
0,
0
]
]The denominator is sqrt(0.25), but multiplying a zero row still returns zeros.