Transformer 块(Transformer
Block)由注意力、前馈网络、残差与归一化组合成可重复堆叠的模块。这里采用教学用
Post-LN 顺序,真实架构也常见其他归一化位置。A Transformer block combines attention, a feed-forward network, residual paths, and normalization into a
repeatable module. This lesson uses a post-LN sequence; real architectures also place normalization
differently.
01 · 先装零件,再开机01 · Assemble before powering on
注意力、前馈、旁路与归一化都在桌上:哪个先接,哪个要重复两次?Attention, feed-forward, bypass, and normalization are on the bench. What connects first, and what appears
twice?
▣→▣
02把 4 种积木拖进 6 个槽位Drag Four Part Types into Six Slots
零件 → 一层parts → one layer
已安装Installed
0 / 6
拖入下方槽位drop into lower slots
顺序正确Correct order
0 / 6
从左向右检查checked left to right
数据带状态Data-belt state
WAIT
等待装配waiting for assembly
这是零件页:六槽表示一次完整 Post-LN block。下一页 S3-15 会把这个 block
作为整机里的重复层。This is the parts page: six slots form one complete post-LN block. S3-15 places this block into the full
machine as a repeated layer.
03四种积木各管一件事Each of the Four Part Types Has One Job
look · change · keep · stabilize
PART 01
注意力Attention
让各位置从允许的其他位置汇总信息。Lets positions gather from other allowed positions.
PART 02
残差Residual
把每个子模块的输入直接加回输出。Adds each submodule's input back to its output.
PART 03
LayerNorm
稳定单位置特征的中心与尺度。Stabilizes feature center and scale per position.
PART 04
FFN
逐位置独立做非线性变换。Applies an independent nonlinear transform per position.
正确槽序正好对应两行公式。拖错一块,数据带会在第一个不匹配槽位停下。The correct slot order maps directly to these two equations. Misplace a part and the data belt stops at
the first mismatch.
位置间看信息Look across positionsAttention 改上下文Attention changes context
保留并稳住Keep and stabilizeResidual + LayerNormResidual + LayerNorm
逐位置再加工Transform per positionFFN 后再次保留、稳定FFN, then keep and stabilize again
05边界实验:把 FFN 接到第一个槽Boundary Test: Put FFN in the First Slot
主动制造失败Create a failure
形状也许没坏,信息工序已经断了Shape may still fit while the information process breaks
故意把 FFN
放第一位。它只会逐位置加工,尚未让位置互看;数据带会标出“信息断点”。Place FFN first on purpose. It transforms positions independently before they exchange context, so the
belt flags an information breakpoint.
尚未执行。请自行拖装或制造一次错序。Not run yet. Assemble manually or create one bad order.
✗ Transformer block 只有注意力。A Transformer block is only attention.
→ ✓ 它还包含 FFN、残差与归一化。It also includes FFN, residual paths, and normalization.
✗ FFN 会让不同 token 互相传信息。FFN passes information between tokens.
→ ✓ FFN 对每个位置独立加工。FFN transforms each position independently.
✗ 所有 Transformer 都只有一种顺序。Every Transformer uses one fixed ordering.
→ ✓ Pre-LN、Post-LN 等布局会改变归一化位置。Pre-LN and post-LN layouts place normalization differently.
06 · 一句话带走06 · One line to keep
一个 Transformer block
把注意力、FFN、残差与归一化装成可重复的一层;亲手拖对六个槽位,就能检验每种零件出现在哪里。A Transformer block assembles attention, FFN, residual paths, and normalization into one repeatable layer.
Fill six slots to verify where each part belongs.