Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RLlib] Fix error in PPO with use_kl_loss=False #45031

Conversation

simonsays1980
Copy link
Collaborator

@simonsays1980 simonsays1980 commented Apr 29, 2024

Why are these changes needed?

Using no KL loss in PPO throws an AssertionError b/c the sampled_kl_values are empty. This PR fixes this error by moving the assertion only into the case where use_kl_loss=True. Furthermore, the sampled KL values were passed to the PPOLearner that does not use them and instead passed them over to the TorchLearner that has no use of them either. This argument was removed from PPOLearner.additional_update_for_module.

Related issue number

Checks

  • I've signed off every commit(by using the -s flag, i.e., git commit -s) in this PR.
  • I've run scripts/format.sh to lint the changes in this PR.
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
    • I've added any new APIs to the API Reference. For example, if I added a
      method in Tune, I've added it in doc/source/tune/api/ under the
      corresponding .rst file.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
    • Release tests
    • This PR is not tested :(

…kl_loss=True' and otherwise throws an error. Furthermore, removed the 'kl_sampled_values' from 'PPOLeanrer.additional_update_for_module' b/c it is unused.

Signed-off-by: Simon Zehnder <simon.zehnder@gmail.com>
Signed-off-by: Simon Zehnder <simon.zehnder@gmail.com>
Signed-off-by: Simon Zehnder <simon.zehnder@gmail.com>
)

# Update KL coefficient.
if config.use_kl_loss:
assert sampled_kl_values, "Sampled KL values are empty."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@@ -22,6 +22,7 @@
lr=0.0003,
num_sgd_iter=6,
vf_loss_coeff=0.01,
use_kl_loss=True,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True by default, but yes, setting this explicitly here is always better :)

Copy link
Contributor

@sven1977 sven1977 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch @simonsays1980 !
LGTM.

@sven1977 sven1977 marked this pull request as ready for review April 30, 2024 11:45
@sven1977 sven1977 merged commit 89a6393 into ray-project:master Apr 30, 2024
5 checks passed
ryanaoleary pushed a commit to ryanaoleary/ray that referenced this pull request Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants