ElemedexA pocket encyclopedia of AI architectures

Glossary (TM) › Architectural parts

TM086

Feedforward (MLP) block

Also: feed-forward network, FFN, MLP layer

In Spanish: Bloque feedforward (MLP)

A small two-layer network that, inside each transformer block, processes each token separately; it holds most of the model's parameters.

"Feedforward" designates any network in which information flows in one direction, without loops: the 1986 multilayer perceptron is the classic case. Inside a transformer block, the term names the second sublayer: two linear transformations with an activation function in between, applied to each position separately and identically (Vaswani et al., 2017, sec. 3.3):

FFN(x) = max(0, x·W₁ + b₁)·W₂ + b₂

The vector is expanded (from 512 to 2048 dimensions in the original) and compressed again. In GPT-3 the inner layer is always four times as wide as the model (Brown et al., 2020, sec. 2.1); recent models swap the ReLU for SwiGLU (Alammar & Grootendorst, 2024, p. 101; Touvron, Lavril, et al., 2023, sec. 2.2).

Division of labor. Attention mixes information between tokens; the feedforward network does not look at neighbors, it transforms what each token already has. With the usual proportions, its two matrices make up about two thirds of each block's parameters (our own arithmetic: 8d² against attention's 4d²). Alammar & Grootendorst (2024) describe it as housing much of the processing capacity and, probably, of the memorization: that "The Shawshank" continues with "Redemption" would depend on information stored there (2024, pp. 86–87). Geva et al. (2021) proposed reading these layers as key–value memories: the first matrix detects textual patterns and the second pushes toward certain output words.

Variants. In a mixture of experts, this block is replaced by many parallel blocks and a router that picks a few per token (Mixture of experts (Mixtral)).

A caveat. That "facts" live in these layers is a useful hypothesis, not a map: the same machinery that memorizes also interpolates between examples and generalizes (Alammar & Grootendorst, 2024, p. 87), and information tends to be distributed across many layers and superposed in the same neurons.

Sources

  • Alammar, J., & Grootendorst, M. (2024). Hands-on large language models: Language understanding and generation. O’Reilly Media. §
  • Brown, T. B., Mann, B., Ryder, N., Subbiah, M., Kaplan, J., Dhariwal, P., Neelakantan, A., Shyam, P., Sastry, G., Askell, A., Agarwal, S., Herbert-Voss, A., Krueger, G., Henighan, T., Child, R., Ramesh, A., Ziegler, D. M., Wu, J., Winter, C., . . . Amodei, D. (2020). Language models are few-shot learners. In Advances in Neural Information Processing Systems (Vol. 33, pp. 1877–1901). Curran Associates. https://proceedings.neurips.cc/paper_files/paper/2020/hash/1457c0d6bfcb4967418bfb8ac142f64a-Abstract.html §
  • Geva, M., Schuster, R., Berant, J., & Levy, O. (2021). Transformer feed-forward layers are key-value memories. In M.-F. Moens, X. Huang, L. Specia, & S. W. Yih (Eds.), Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing (pp. 5484–5495). Association for Computational Linguistics. https://doi.org/10.18653/v1/2021.emnlp-main.446 §
  • Touvron, H., Lavril, T., Izacard, G., Martinet, X., Lachaux, M.-A., Lacroix, T., Rozière, B., Goyal, N., Hambro, E., Azhar, F., Rodriguez, A., Joulin, A., Grave, E., & Lample, G. (2023). LLaMA: Open and efficient foundation language models (arXiv:2302.13971). arXiv. https://doi.org/10.48550/arXiv.2302.13971 §
  • Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A. N., Kaiser, Ł., & Polosukhin, I. (2017). Attention is all you need. In Advances in Neural Information Processing Systems (Vol. 30). Curran Associates. https://proceedings.neurips.cc/paper_files/paper/2017/hash/3f5ee243547dee91fbd053c1c4a845aa-Abstract.html §