If we see the first transformer architecture that was introduced by Google in the "Attention Is All You Need" paper, their use of LayerNorm is wrong, and nowadays we use LayerNorm before the attention/FF sublayer. But what is really a good place to sit LayerNorm? I will explain all of this in this blog.
First, the architecture
Before seeing where LayerNorm should be used, we should look at the architecture. Think like we have a residual stream, the main highway, and we want to protect our original tokens, so we stay with the original tokens and just make another road, which means the sublayer (attention/FF). These sublayers contribute or give us some information, so we add it into the original tokens on the main highway.
Think like on the highway we have a big truck that comes from our factory, and in the middle of the highway we put the exact same product on another truck and send it to a sideway road. On the sideway road the product is enhanced for the client.…