← Back to LLMs Mind Map
⚡ LLMsID: feedforward-swiglu

FFN & SwiGLU

前馈层与激活
🎯Core Definition
the Transformer feed-forward layer FFN(x)=W2⋅GELU(W1x)FFN(x) = W_2 \cdot GELU(W_1 x) holds roughly 2/3 of model parameters (excluding embeddings); SwiGLU is a gated activation: SwiGLU(x)=(SiLU(xWg))⋅(xWu)WdSwiGLU(x) = (SiLU(x W_g)) \cdot (x W_u) W_d with SiLU(x)=x⋅sigmoid(x)SiLU(x) = x \cdot sigmoid(x) (Swish), shrinking the intermediate width from 4d4d to 83d\frac{8}{3}d (LLaMA-2 7B: hidden 4096 → intermediate 11008).
💡Use Cases
every mainstream model after 2023 (LLaMA-2/3, Qwen, Mistral, Gemma) replaced GELU MLPs with SwiGLU; interviews often probe "why gating", "why 8/3 d" and activation memory during training.
⚡Key Problems Solved
plain ReLU/GELU MLPs have no input-conditional selection — information flows the same way for every token; the 4d4d intermediate width inflates parameters and activations; SwiGLU lets different tokens traverse different "sub-networks" via input-dependent gating, improving quality at equal parameter count while actually shrinking parameters and training activation memory (4d→83d4d \rightarrow \frac{8}{3}d).
🎯Core Interview Exam Points
Fundamentals · Production Scenarios · Deep Dive
Core Def
Explain the core definition, underlying mechanism/math, and key principles of FFN & SwiGLU.
Use Cases
In production engineering, what are the primary use cases for FFN & SwiGLU and what core pain points does it solve?
🔥 High-Frequency Deep-Dive Questions
1
Why does FFN hold ~2/3 of parameters? Design of intermediate width 4d4d vs 83d\frac{8}{3}d?
2
Essential difference between SwiGLU and a plain GELU MLP (input-dependent gating)?
3
Properties of SiLU/Swish: why smoother and saturation-free vs ReLU?
4
GLU family: activations used by ReGLU, GEGLU and SwiGLU?
5
Why is FFN activation memory large in training, and how to mitigate (caching, recomputation)?
Updated 2026-08-12
🎯
Verify Mastery: Practice Exam Questions for "FFN & SwiGLU"
Take pitfall multiple-choice questions with derivation options; mistakes are automatically logged.
🚀 Start Card Practice ➔
← Previous CardRoPE Extrapolation PI/NTK/YaRNNext Card →Pre-LN & RMSNorm

🔗 More LLMs Knowledge Cards

引用出处: TalentMe 450+ 工业级 AI 架构考点知识库 (Tech Vault) · 遵循 CC-BY-4.0 知识共享协议
URL: https://talentme.airsota.com/resources/tech/roadmap/mindmap/LLM/card/feedforward-swiglu
中文速览与面试要点

前馈层与激活 (FFN & SwiGLU)

定义: Transformer 前馈层 FFN(x) = W_2 GELU(W_1 x),占模型参数约 2/3(非嵌入参数);SwiGLU 是门控激活:SwiGLU(x) = (SiLU(x W_g)) (x W_u) W_d,其中 SiLU(x) = x sigmoid(x) 即 Swish,中间维度从 4d 降到 83d(LLaMA-2 7B: 隐藏维 4096 → 中间维 11008)。 使用场景: LLaMA-2/3、Qwen、Mistral、Gemma 等 2023 后主流模型全部用 SwiGLU 替代 GELU MLP;面试常考"为什么用门控激活""中间维为什么是 8/3 d"以及训练时的激活显存问题。 解决的问题: 普通 MLP 的 ReLU/GELU 无输入条件选择,信息对所有 token 固定流动;4d 中间维带来大量参数与激活;SwiGLU 用输入依赖的门控让不同 token 走不同"子网络",同等参数量下质量更好,同时中间维缩小(4d 83d),参数与训练激活显存反而下降。

核心要点

  • FFN 为什么占参数约 2/3?中间维度 4d 与 83d 的设计?
  • SwiGLU 与普通 GELU MLP 的本质区别?(输入依赖的门控机制)
  • SiLU/Swish 的性质:为什么比 ReLU 更平滑、无饱和?
  • GLU 家族对比:ReGLU、GEGLU、SwiGLU 分别用什么激活?
  • 训练时 FFN 激活显存为什么大?如何缓解?(激活缓存、重算)