Библиотека · CC BY-SA 4.0

Приключения Алисы в Странедифференцируемых чудес

Alice's Adventures in a Differentiable Wonderland, Volume I: A Tour of the Land

Иллюстрация к книге

Выберите версию

Один и тот же текст на каждом уровне, на всех языках и во всех оформлениях, что здесь есть. Выберите, потом слушайте или скачивайте.

Слушать и смотреть

Тот же плеер, который продукт даёт для вашей книги: голос, рисунки по мере того, как они рисуются, текст.

Современный учебник о том, как на самом деле устроены нейросети: от тензоров и градиентов до трансформеров. Глава 6 показывает, как программа сама находит свои градиенты: автоматическое дифференцирование, обратный проход, на котором обучается любая модель.

Это пробная часть: 1 из 13 (главы).

Из лекций

On the left a small table X of n rows and c columns; an arrow turns it into one long strip of cells; on the right a large square grid labelled flattened Jacobian, much bigger than the table, with a warning label too big to store.
Automatic differentiation

Flattening a Batch into a Vector

On our notation and higher-order Jacobians. We only consider vector-valued quantities for readability, as all resulting gradients are then matrices. In practice, existing primitives may have inputs, weights or outputs of higher rank.

Three primitive boxes in a row; under the first a tangent card W-hat 1 appears; at the second box W-hat 1 is multiplied by the input Jacobian and a new W-hat 2 appears beside it; at the i-th box all earlier tangents are updated together and a new one is added; at the end a row of ones turns each tangent into a gradient.
Forward-mode differentiation

Forward Mode Carries the Tangents

Consider the first instruction in our program, 𝐡₁ = f₁(𝐱, 𝐰₁). Because nothing has been stored up to now, we initialize the tangent matrix for 𝐰₁ as its weight Jacobian: Ŵ₁ = ∂_𝐰₁ 𝐡₁. We now proceed to the second instruction, 𝐡₂ = f₂(𝐡₁, 𝐰₂).

Top row: three boxes f1, f2, f3 run left to right, each dropping its output into a stored note below; bottom row: a red arrow runs back from right to left carrying the adjoint h-tilde, and at each box it hands out a green gradient for that box's weights.
Reverse-mode differentiation

Forward Pass, Then Backward Pass

We can put these observations together to develop a second approach to automatic differentiation, which we call reverse-mode automatic differentiation, or R-AD, outlined next.

A box f with x entering from the left and y leaving to the right; on the way back the adjoint enters from the right and the box returns two things, the input VJP going left and the weight VJP going down.
Vector-Jacobian products

A Primitive With Two VJPs

Hence we can implement an entire automatic differentiation system by first choosing a set of primitive operations, and then augmenting them with the corresponding VJPs, without having to materialize the Jacobians in memory at any point.

Three tensor cards in a row, each with three fields: data, grad (empty) and grad_fn pointing back to the card that made it; a red arrow labelled backward runs from the last card to the first and fills the grad fields as it passes.
Implementing a reverse-mode system

Tensors That Remember Their Origin

As we mentioned, in practice our models are implemented as compositions of objects whose parameters are encapsulated as properties. One possibility is to “purify” the object, turning it into a pure function.

The ReLU graph with its corner at zero; several straight lines pass through the corner with slopes between 0 and 1, all staying below the graph; a small table shows PyTorch returning 0, 1 and 0.5 for three versions of the same function.
Choosing an activation function

Many Slopes at the Corner

Subdifferentiability and automatic differentiation. There is a small detail we avoided discussing until now: the ReLU is not differentiable at 0, which makes the overall network non-smooth. What happens in this case?

Как это сделано

Примеры для: a curious adult with school maths who uses AI apps every day; add one modern instance per idea, such as how a chat assistant or a phone's photo app is trained

Источник

Лекции пересказывают с английского оригинала книгу arXiv 2404.17625 (version 3, 2025), автор — Симоне Скардапане; книга вышла под открытой лицензией, которая разрешает пересказ и перевод. Пересказ, рисунки и голос сделаны ИИ и сверены с книгой второй моделью. Как используется ИИ.

Лекции — переработка оригинала и распространяются под той же лицензией: их можно свободно распространять и перерабатывать с указанием автора и ссылкой на эту страницу: CC BY-SA 4.0

Ваша трудная книга — так же

Загрузите учебник или любую сложную книгу. Первые пять минут бесплатно.

Загрузить книгу