GDN z-gated output norm: (weight * rms(x)) * silu(z), weight direct.
(x, z, weight, eps=1e-5)
| 91 | |
| 92 | |
| 93 | def gated_norm(x, z, weight, eps=1e-5): |
| 94 | """GDN z-gated output norm: (weight * rms(x)) * silu(z), weight direct.""" |
| 95 | xf = x.float() |
| 96 | xf = xf * torch.rsqrt(xf.pow(2).mean(-1, keepdim=True) + eps) |
| 97 | return (xf * weight.float() * torch.nn.functional.silu(z.float())).to(x.dtype) |
| 98 | |
| 99 | |
| 100 | def fused_add_norm(hidden, residual, weight, eps=1e-5): |