Fix PPO importance-sampling ratio bias with squashed-Gaussian policies#118
Open
jmtoepperwien wants to merge 2 commits into
Open
Fix PPO importance-sampling ratio bias with squashed-Gaussian policies#118jmtoepperwien wants to merge 2 commits into
jmtoepperwien wants to merge 2 commits into
Conversation
With squashed-Gaussian policies, old_log_probs stored during rollout lacked the tanh correction while new_log_probs in the update included it. The correction did not cancel in the IS ratio, introducing a multiplicative bias that grows as actions approach ±1. Fix: remove the sac= gate from sample_nondeterministic_logprobs and always apply the correction for 4-tuple model output, which is the canonical signal that tanh squashing is active.
Rather than inferring squashing from the output tuple shape, read the model's tanh_squash attribute directly. SACModel gains tanh_squash=True as a class attribute to match the existing PPOModel pattern. sample_nondeterministic_logprobs now takes an explicit tanh_squash flag.
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.
Fix PPO importance-sampling ratio bias with squashed-Gaussian policies
Problem
When PPO uses a squashed-Gaussian policy (4-tuple output:
action, z, mean, log_std), the importance-sampling ratio becomes biased:old_log_probsstored in the buffer are computed without the tanh change-of-variables correctionnew_log_probsinclude the correction1/(1 - tanh(z)²)factor explodes as actions approach ±1, causing gradient instabilitySolution
Two commits:
Always apply tanh correction at rollout time (97e8391)
sac=gate fromsample_nondeterministic_logprobsold_log_probsstored in the buffer are already corrected, so the correction cancels correctly in the PPO updateCheck tanh_squash attribute explicitly (5e59c37)
tanh_squash=TruetoSACModelas a class attribute (matchingPPOModel)tanh_squash=getattr(self.model, "tanh_squash", False)tosample_nondeterministic_logprobsat each call site