# 【Transformer 与注意力机制】06｜梯度下降与反向传播

DevFeed: [【Transformer 与注意力机制】06｜梯度下降与反向传播](<https://devfeed.tech/articles/transformer-06-144788.md>)

Original publisher: [Read original article](<https://quant67.com/post/transformer/06-backprop/06-backprop.html>)

Author: Liao Tonglang

Published: 2026-04-15T00:00:00Z

Content type: article

Language: zh

Sources: [土法炼钢 - 系统与基础设施](<https://devfeed.tech/sources/source-4.md>)

Topics: [Transformer](<https://devfeed.tech/topics/transformer.md>), [Large Language Model](<https://devfeed.tech/topics/llm.md>), [Python](<https://devfeed.tech/topics/python.md>), [Chinchilla scaling law](<https://devfeed.tech/topics/chinchilla-scaling-law.md>)

Tags: [adamw](<https://devfeed.tech/tags/adamw.md>), [adaptive](<https://devfeed.tech/tags/adaptive.md>), [attention](<https://devfeed.tech/tags/attention.md>), [backpropagation](<https://devfeed.tech/tags/backpropagation.md>), [batch](<https://devfeed.tech/tags/batch.md>), [bf16](<https://devfeed.tech/tags/bf16.md>), [checkpoint](<https://devfeed.tech/tags/checkpoint.md>), [chinchilla](<https://devfeed.tech/tags/chinchilla.md>), [clipping](<https://devfeed.tech/tags/clipping.md>), [condition-number](<https://devfeed.tech/tags/condition-number.md>), [cosine](<https://devfeed.tech/tags/cosine.md>), [embedding](<https://devfeed.tech/tags/embedding.md>), [ffn](<https://devfeed.tech/tags/ffn.md>), [flashattention](<https://devfeed.tech/tags/flashattention.md>), [fp16](<https://devfeed.tech/tags/fp16.md>), [fsdp](<https://devfeed.tech/tags/fsdp.md>), [gilbert-strang](<https://devfeed.tech/tags/gilbert-strang.md>), [gpt](<https://devfeed.tech/tags/gpt.md>), [gpt-3](<https://devfeed.tech/tags/gpt-3.md>), [gradient-descent](<https://devfeed.tech/tags/gradient-descent.md>), [hessian](<https://devfeed.tech/tags/hessian.md>), [python](<https://devfeed.tech/tags/python.md>), [transformer](<https://devfeed.tech/tags/transformer.md>)

## AI overview

The article derives fixed-step gradient descent stability from Hessian eigenvalues: the step size must satisfy 0 < η < 2/λmax, while high condition numbers force slow progress and zigzagging in narrow valleys. It then derives reverse-mode autodiff and the linear-layer VJP, showing that a single-sample weight gradient is an input-error outer product, and walks through a two-layer network with numerical gradient checking. For deep networks, it explains vanishing and exploding gradients through Jacobian products and describes initialization, residual connections, normalization, and clipping as stabilizing measures. It presents AdamW as momentum plus coordinate-wise scaling, with decoupled weight decay, and outlines Transformer training practices including warmup, cosine or WSD schedules, global-norm clipping, and mixed precision. The text also notes the optimizer-state memory cost and motivates sharding with ZeRO or FSDP.

## Source excerpt

从 Gilbert Strang 的二次型特征值与条件数几何出发，推导梯度下降最大稳定步长与锯齿振荡根源，再推导出矩阵微积分 VJP 的秩一外积规则，并用 2->2->1 网络手算与 Python 梯度检验打通从 SGD 到 AdamW 的优化器逻辑。