การส่งต่อเก็บแคช การย้อนกลับนำกลับมาใช้
เหตุใดจึงเก็บค่าการกระตุ้นไว้ระหว่างการส่งต่อ
การส่งต่อเก็บแคช การย้อนกลับนำกลับมาใช้ เป็นบทเรียน Deep Learning Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน 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. 💾
คำถามที่พบบ่อย
บทเรียน “การส่งต่อเก็บแคช การย้อนกลับนำกลับมาใช้” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “การส่งต่อเก็บแคช การย้อนกลับนำกลับมาใช้” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Deep Learning Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Deep Learning Academy มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “การส่งต่อเก็บแคช การย้อนกลับนำกลับมาใช้”
เหตุใดจึงเก็บค่าการกระตุ้นไว้ระหว่างการส่งต่อ คุณปฏิบัติ Deep Learning Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Deep Learning Academy หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Deep Learning Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน
บทเรียน “การส่งต่อเก็บแคช การย้อนกลับนำกลับมาใช้” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Deep Learning Academy นี้ได้ไหม
ได้ บทเรียน Deep Learning Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- กฎลูกโซ่ทีละชั้น
- การส่งต่อเก็บแคช การย้อนกลับนำกลับมาใช้
- ทำการแพร่ย้อนกลับของโครงข่ายเล็ก ๆ ด้วยมือ
- เกรเดียนต์หายและเกรเดียนต์ระเบิด