Example 1
Arguments: [
[
[
1
]
],
[
[
0
]
],
[
[
2
]
],
[
[
3
]
]
]
Expected result: [
[
0
]
]SiLU(0) is zero, so the entire layer returns zero.
Tensor and numerical foundations · Medium
Problem 8 of 50 · Python and NumPy
Implement the bias-free SwiGLU feed-forward sublayer: silu(x @ gate_weight) * (x @ up_weight), followed by multiplication by down_weight. Here silu(z) = z/(1+exp(−z)), and * means elementwise multiplication. Return the projected token rows; do not add a residual.
def swiglu(x, gate_weight, up_weight, down_weight):Arguments: [
[
[
1
]
],
[
[
0
]
],
[
[
2
]
],
[
[
3
]
]
]
Expected result: [
[
0
]
]SiLU(0) is zero, so the entire layer returns zero.
Arguments: [
[
[
1
]
],
[
[
1
]
],
[
[
2
]
],
[
[
3
]
]
]
Expected result: [
[
4.38635147178003
]
]SiLU(1) = 1/(1+e⁻¹); multiplying by 2 and then 3 gives approximately 4.38635.