Class SwiGLULayer
java.lang.Object
io.github.kirstenali.deepj.layers.transformer.SwiGLULayer
SwiGLU feed-forward layer — the FFN used in Llama, Mistral, Qwen, and DeepSeek.
Unlike the standard two-projection MLP, SwiGLU uses three projections and a multiplicative gate:
gate = gateProj(x) [seqLen × dFF] up = upProj(x) [seqLen × dFF] fused = SiLU(gate) · up [seqLen × dFF] (element-wise) out = downProj(fused) [seqLen × dModel]
Backward (chain rule through the gated multiply):
dFused = downProj.backward(dOut) dSiluGate = dFused · up → fed into SiLU.backward → dGate dUp = dFused · SiLU(gate) → fed into upProj.backward dX = gateProj.backward(dGate) + upProj.backward(dUp)
Used as the feed-forward component in LlamaTransformerBlock
and DeepSeekTransformerBlock.
-
Constructor Details
-
SwiGLULayer
- Parameters:
dModel- input and output dimensiondFF- intermediate (hidden) dimension — typically ≈ 8/3 × dModel for Llama stylernd- random source for weight initialisation
-
-
Method Details