Skip to content

intermediate/rpc_tutorial: fix REINFORCE return calculation across observers#3893

Open
getchebarne wants to merge 1 commit into
pytorch:mainfrom
getchebarne:fix/rpc-tutorial-trajectory-mixing
Open

intermediate/rpc_tutorial: fix REINFORCE return calculation across observers#3893
getchebarne wants to merge 1 commit into
pytorch:mainfrom
getchebarne:fix/rpc-tutorial-trajectory-mixing

Conversation

@getchebarne
Copy link
Copy Markdown

@getchebarne getchebarne commented May 12, 2026

Description

The finish_episode code block in intermediate/rpc_tutorial merges every observer's rewards into one flat list before doing the reverse discounted sum. Because R never gets reset between observers, the early steps of observer 1's trajectory end up with observer 2's whole return tacked onto their tail. Those rewards came from an independent environment, which is conceptually wrong in many levels.

The fix: compute the discounted return per observer, then concatenate. Everything around it (running reward, buffer clear, normalization, loss, optimizer step) stays the same. Single-observer behavior is unchanged.

Same change is going up against the mirrored runnable code in pytorch/examples: http://github.com/pytorch/examples/pull/1422.

Checklist

  • Only one issue is addressed in this pull request
  • Labels from the issue that this PR is fixing are added to this pull request
  • No unnecessary issues are included into this pull request.

@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented May 12, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/tutorials/3893

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant