Products
Features
YouTube Video Summarizer
Summarize YouTube videos
Web & PDF Highlighter
Highlight web pages & PDFs
Chat with PDF
Ask any PDF questions with AI
Ask AI Clone
Chat with your highlights & memories
Audio Transcriber
Transcribe audio files to text
Glasp Reader
Read and highlight articles
Kindle Highlight Export
Export your Kindle highlights
Idea Hatch
Hatch ideas from your highlights
Integrations
Obsidian Plugin
Notion Integration
Pocket Integration
Instapaper Integration
Medium Integration
Readwise Integration
Snipd Integration
Hypothesis Integration
Apps & Extensions
Chrome Extension
Safari Extension
Edge Add-ons
Firefox Add-ons
iOS App
Android App
Discover
Discover
Ideas
Discover new ideas and insights
Articles
Curated articles and insights
Books
Book recommendations by great minds
Posts
Essays and notes from readers
Quotes
Inspiring quotes collection
Videos
Curated videos and summaries
Explore Glasp
Glasp Newsletter
Weekly insights and updates
Glasp Talk
Interview series with great minds
Glasp Blog
Latest news and articles
Glasp Use Cases
Learn how others use Glasp
Build & Support
Glasp API
Access Glasp's API for developers
MCP Connector
Connect Glasp to Claude & ChatGPT
Community
Glasp Reddit Community
Students
Student discount and benefits
FAQs
Frequently Asked Questions
AboutPricing
DashboardLog inSign up

Why Do We Add Losses Before Back Propagating in PyTorch

October 8, 2021
by
Machine Learning with Phil
YouTube video player
Why Do We Add Losses Before Back Propagating in PyTorch

TL;DR

Actor and critic networks in an actor-critic architecture share lower layers, requiring the sum of losses before back propagation to ensure gradients are properly calculated and retained.

Transcript

hello everybody i just want to do a really quick video today so i got a question in the discord chat which if you are not on our discord you should be there are quite a few very smart individuals on there answering questions driving discussions it's a great place to be check it out but the question is why uh why is it that we have to do the sum of ... Read More

Key Insights

  • 🧑‍🏭 Actor and critic networks in an actor-critic architecture share lower layers, requiring loss combination before back propagation for proper gradient calculation.
  • 🥺 PyTorch conventionally throws out gradients after each back propagation, leading to the need to retain the graph or combine losses.
  • 👻 Separate architectures for actor and critic networks allow sequential back propagation without loss combination.
  • 🐢 Retaining the graph during back propagation can slow down future calculations due to gradient accumulation.
  • 😷 Discord chat is a valuable resource for asking questions and engaging in discussions on the topic.
  • 🍵 PyTorch may handle back propagation differently compared to TensorFlow.
  • 🧑‍🏭 Testing separate networks for actor and critic functions in PyTorch confirmed the ability to back propagate through separate graphs without loss combination.

Install to Summarize YouTube Videos and Get Transcripts

Explore YouTube Video Summarizer or Get YouTube Transcript Extractor

Questions & Answers

Q: Why do we need to add the losses of the actor and critic networks before back propagation?

The actor and critic networks share lower layers, and the derivative of the actor with respect to the critic's parameters will be zero without adding the losses together. This ensures shared gradients in the lower layers are properly calculated.

Q: Can we calculate gradients in any order in PyTorch?

Yes, it is valid to calculate gradients in any order in PyTorch. However, PyTorch conventionally throws out gradients once one loss function is back propagated, leading to the need to combine losses in actor-critic networks.

Q: What happens if we don't retain the graph when back propagating in PyTorch?

If the retain_graph parameter is not specified, PyTorch throws out gradients associated with the second network when calculating back propagation for the first network. This can result in incorrect gradient calculation.

Q: Can separate actor and critic networks be back propagated sequentially without combining losses?

Yes, if the actor and critic networks have separate architectures and do not share input layers, it is valid to back propagate through them sequentially without combining losses.

Summary & Key Takeaways

  • Actor and critic networks in actor-critic architectures share lower layers, serving as the interface with the environment, before branching out into separate outputs.

  • Back propagation in PyTorch conventionally requires adding the losses of the actor and critic networks together to ensure proper gradient calculation.

  • If actor and critic networks have separate architectures, it is valid to back propagate through them sequentially without combining losses.


Read in Other Languages (beta)

English

Share This Summary 📚

Summarize YouTube Videos and Get Video Transcripts with 1-Click

Download browser extensions on:

Try YouTube Summary with ChatGPT & Claude or YouTube Transcript Generator

Explore More Summaries from Machine Learning with Phil 📚

Reinforcement Learning in Continuous Action Spaces | DDPG Tutorial (Pytorch) thumbnail
Reinforcement Learning in Continuous Action Spaces | DDPG Tutorial (Pytorch)
Machine Learning with Phil
A Physicists Thoughts On Writing Deep Learning Papers thumbnail
A Physicists Thoughts On Writing Deep Learning Papers
Machine Learning with Phil
Data Science & Machine Learning Freelancer Part 1 -  Choosing A Platform thumbnail
Data Science & Machine Learning Freelancer Part 1 - Choosing A Platform
Machine Learning with Phil
How to Code A Deep Neural Network From Scratch | PyTorch Tutorial thumbnail
How to Code A Deep Neural Network From Scratch | PyTorch Tutorial
Machine Learning with Phil
Machine Learning Freelancer Part 3 -  How To Find Good Machine Learning Jobs thumbnail
Machine Learning Freelancer Part 3 - How To Find Good Machine Learning Jobs
Machine Learning with Phil
How to Code Policy Evaluation | Free Reinforcement Learning Course Module 5a thumbnail
How to Code Policy Evaluation | Free Reinforcement Learning Course Module 5a
Machine Learning with Phil

Summarize YouTube Videos and Get Video Transcripts with 1-Click

Download browser extensions on:

Try YouTube Summary with ChatGPT & Claude or YouTube Transcript Generator

Apps & Extensions

  • Chrome Extension
  • Safari Extension
  • Edge Add-ons
  • Firefox Add-ons
  • iOS App
  • Android App

Key Features

  • YouTube Video Summarizer
  • Web & PDF Summarizer
  • Web & PDF Highlighter
  • Chat with PDF
  • Ask AI Clone
  • Audio Transcriber
  • Glasp Reader
  • Kindle Highlight Export
  • Idea Hatch

Integrations

  • Obsidian Plugin
  • Notion Integration
  • Pocket Integration
  • Instapaper Integration
  • Medium Integration
  • Readwise Integration
  • Snipd Integration
  • Hypothesis Integration

More Features

  • APIs
  • MCP Connector
  • Blog & Post
  • Embed Links
  • Image Highlight
  • Personality Test
  • Quote Shots

Company

  • About us
  • Blog
  • Community
  • FAQs
  • Job Board
  • Newsletter
  • Pricing
Terms

•

Privacy

•

Guidelines

© 2026 Glasp Inc. All rights reserved.