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] Issue 21297: Ignore PPO KL-loss term completely if kl-coeff == 0.0 to avoid NaN values due to some discrete action probs==0.0 #21456

Conversation

sven1977
Copy link
Contributor

@sven1977 sven1977 commented Jan 7, 2022

Issue 21297: Ignore PPO KL-loss term completely if kl-coeff == 0.0 to avoid NaN values due to some discrete action probs==0.0

Why are these changes needed?

#21297

Related issue number

Checks

  • 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 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 :(

Copy link
Member

@gjoliver gjoliver left a comment

Choose a reason for hiding this comment

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

just a minor comment.
thanks.

policy.config["vf_loss_coeff"] * vf_loss -
policy.entropy_coeff * curr_entropy)
# Add mean_kl_loss (already processed through `reduce_mean_valid`),
# if necessary.
if policy.config["kl_coeff"] > 0.0:
Copy link
Member

Choose a reason for hiding this comment

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

seems this if statement is not necessary, 0.0 case, mean_kl_loss is zero. same below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Normally, yes, but if the calculated kl is Inf (due to some actions having almost 0.0 probability -> log(a) = -inf), then multiplying it with 0.0 will result in NaN. :)

Copy link
Member

Choose a reason for hiding this comment

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

sorry, wasn't clear enough.
I mean if policy.config["kl_coeff"] <= 0.0, mean_kl_loss is hardcoded to be 0.0 now.
so it seems like we don't really need to have this particular if statement here.

the above one is critical, for sure.

@sven1977 sven1977 merged commit 4eaf709 into ray-project:master Jan 10, 2022
@sven1977 sven1977 deleted the issue_21297_ignore_kl_loss_entirely_if_kl_coeff_zero branch June 2, 2023 20:17
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.

2 participants