gpt-oss does not use the textbook SwiGLU. Its expert MLP produces one projection of width 2h whose entries alternate between a gate half and a linear half, and it reshapes the activation in three ways: a scaled sigmoid, clamping, and a constant added to the linear half.
Write gptoss_swiglu(x, alpha=1.702, limit=7.0) for a numpy array x whose last dimension has even length 2h:
- Split the last dimension by position: g = the entries at even indices 0,2,4,… and ℓ = the entries at odd indices 1,3,5,…. Both have length h.
- Clamp g from above only: g←min(g,limit). Clamp ℓ on both sides: ℓ←min(max(ℓ,−limit),limit).
- Return g⋅σ(αg)⋅(ℓ+1), where σ is the logistic sigmoid.
The output has the same leading dimensions as x and last dimension h. Work in float64.