perf: vectorize REINFORCE++ discounted returns#2205
Open
morluto wants to merge 2 commits into
Open
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
get_reinforce_plus_plus_returnscomputes every token return in a Python reverse loop for every sample. That host-side loop becomes expensive for batched long responses, whileppo_utils.pyalready contains a chunked discounted scan for GAE.Change
chunked_discounted_returns.chunked_gae.The change does not add a dependency or alter context-parallel gather/slice behavior.
Correctness
The CPU tests compare the scan against the previous reverse recurrence for
float32andfloat64, discounts0,0.5,0.99, and1, and lengths around the 128-token chunk boundary. Right-padded positions remain zero and are trimmed before caller-visible results.git diff --check origin/mainalso passes.CPU microbenchmark
Environment: 4-core DO-Premium-AMD CPU, Python 3.12.3, PyTorch 2.11.0, one PyTorch thread, random
float32rewards, discount0.99, chunk size 128, one warmup, median of three repetitions.The candidate used
chunked_gae(rewards, zeros_like(rewards), 0.99, 1.0)[0], which is the pre-existing recurrence extracted by this PR.This measures CPU return computation only. It is not a GPU or end-to-end training-throughput claim.
Review notes
Suggested order: review
chunked_discounted_returns, then the REINFORCE++ batching/trim path, then the CPU regression tests and generated CI entry.Disclosure
This contribution was prepared with AI-assisted research and implementation, followed by CPU validation and structured code review.