Deep learning for pedestrians: backpropagation in Transformers
Laurent Bou\'e

TL;DR
This paper provides a detailed manual derivation of backpropagation for transformer-based architectures, including layers like embedding, self-attention, and LoRA, enhancing understanding of gradient flow in these models.
Contribution
It extends previous vectorized backpropagation derivations to transformer architectures, offering analytical gradients and a minimal PyTorch implementation for educational purposes.
Findings
Derived explicit gradient expressions for transformer layers
Provided a minimal GPT-like model with analytical gradients
Enhanced understanding of backpropagation in transformers
Abstract
This document is a follow-up to our previous paper dedicated to a vectorized derivation of backpropagation in CNNs. Following the same principles and notations already put in place there, we now focus on transformer-based next-token-prediction architectures. To this end, we apply our lightweight index-free methodology to new types of layers such as embedding, multi-headed self-attention and layer normalization. In addition, we also provide gradient expressions for LoRA layers to illustrate parameter-efficient fine-tuning. Why bother doing manual backpropagation when there are so many tools that do this automatically? Any gap in understanding of how values propagate forward will become evident when attempting to differentiate the loss function. By working through the backward pass manually, we gain a deeper intuition for how each operation influences the final output. A complete PyTorch…
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
TopicsAdvanced Neural Network Applications · Generative Adversarial Networks and Image Synthesis · Adversarial Robustness in Machine Learning
