順伝播でキャッシュし、逆伝播で再利用する
順伝播中に活性化を保存する理由を学びます
「順伝播でキャッシュし、逆伝播で再利用する」はCoddyKit上の無料Deep Learning Academyレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはDeep Learning Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Deep Learning Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Two Passes, One Goal
Training each batch runs two passes: a forward pass to predict and compute loss, then a backward pass to compute gradients. They work as a pair.
The Forward Pass Computes Values
Going forward, each layer turns its input into an output and sends it onward. By the end you have a prediction and a single loss number.
Backward Needs Forward Values
To compute a layer's gradient, the chain rule needs the very activations that layer produced going forward. Those values are not optional.
So We Cache Them
During the forward pass the network quietly caches each layer's inputs and outputs in memory, ready for the backward pass to grab. 💾
A Concrete Example
The derivative of a layer often reuses its own output. For a sigmoid, the gradient depends on the saved output value, so caching it saves recomputation.
sigmoid_grad = saved_output * (1 - saved_output)Backward Reuses the Cache
The backward pass walks layers in reverse, and at each one it pulls the matching cached values to multiply into the gradient. Nothing is recomputed.
Cache Costs Memory
Storing every activation is why training a deep net uses far more memory than just running it for predictions. Bigger nets need bigger caches.
Inference Skips the Cache
When you only need predictions, there is no backward pass, so PyTorch skips the cache entirely. That is why inference is lighter on memory.
with torch.no_grad():
preds = model(x)PyTorch Does This for You
Every operation on a tensor with requires_grad records what it needs into the computation graph, building the cache automatically as you go.
One Backward Frees It
By default, calling backward() consumes the cached graph and frees it. That is why a second backward() on the same graph raises an error.
loss.backward()Why This Design Wins
Caching forward values means each gradient is one cheap lookup-and-multiply instead of a fresh recomputation, making backprop fast and exact.
Quick Check
Let's check the cache idea.
Recap
The forward pass caches activations, and the backward pass reuses them to build gradients. That trade of memory for speed is what makes backprop practical. 💾
よくある質問
「順伝播でキャッシュし、逆伝播で再利用する」レッスンは無料ですか?
はい。「順伝播でキャッシュし、逆伝播で再利用する」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Deep Learning Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Deep Learning Academyコースには全4レッスンが含まれています。
「順伝播でキャッシュし、逆伝播で再利用する」で何を学びますか?
順伝播中に活性化を保存する理由を学びます ブラウザで直接実行するハンズオンコードでDeep Learning Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Deep Learning Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのDeep Learning Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。
「順伝播でキャッシュし、逆伝播で再利用する」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このDeep Learning Academyレッスンでコードを書いて実行できますか?
はい。すべてのDeep Learning Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- レイヤーごとにたどる連鎖律
- 順伝播でキャッシュし、逆伝播で再利用する
- 小さなネットワークを手計算で逆伝播する
- 勾配消失と勾配爆発