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] RLModule API change: If "actions" key returned from forward_inference|exploration, use actions as-is. #36067

Conversation

sven1977
Copy link
Contributor

@sven1977 sven1977 commented Jun 5, 2023

RLModule API change:

  • If "actions" key returned from forward_inference|exploration, use actions as-is.
  • If - additionally - action_dist_inputs are returned, use these to construct a distribution and compute action probs/logs from it.
  • If "actions" key is NOT returned, continue using "action_dist_inputs" (no change wrt current behavior).

Changed the docs to reflect this.

Why are these changes needed?

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

sven1977 added 2 commits June 5, 2023 14:08
Signed-off-by: sven1977 <svenmika1977@gmail.com>
Signed-off-by: sven1977 <svenmika1977@gmail.com>
Signed-off-by: sven1977 <svenmika1977@gmail.com>
Copy link
Contributor

@kouroshHakha kouroshHakha left a comment

Choose a reason for hiding this comment

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

Implementation looks good. We need to clean up the docs a little bit. Left some comments on my concerns.

Also I think these details should be now reflected as part of the RLModule API references under the three forward methods. That's probably where the advanced users will look for information on implementation details the most.
We need to be more clear on what the output will be treated in the doc-string of those functions (under Returns section)

return a dictionary that either contains the key "actions" and/or the key "action_dist_inputs".

If you return the "actions" key:
* RLlib will use the actions provided thereunder directly and as-is.
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

* RLlib will create a ``ray.rllib.models.distributions.Distribution`` object from the distribution parameters under that key and sample actions from the thus generated distribution.
* In the case of ``forward_exploration()``, RLlib will also compute action probs and logp values from the sampled actions automatically.

Note that in the case of ``forward_inference()``, the generated distributions (from returned key "action_dist_inputs") will always be made deterministic via
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's make this a Note box via .. note::?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


If you do not return the "actions" key:
* You must return the "action_dist_inputs" key instead from your ``forward_inference()`` and ``forward_exploration()`` methods.
* RLlib will create a ``ray.rllib.models.distributions.Distribution`` object from the distribution parameters under that key and sample actions from the thus generated distribution.
Copy link
Contributor

Choose a reason for hiding this comment

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

All of these classes we mention here have to be linked to their class definition API reference. You can use something like :py:class:~ray.rllib.models.distributions.Distribution to achieve this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed all of these via :py:meth:.. and :py:class:.. links.

Copy link
Contributor

@kouroshHakha kouroshHakha Jun 7, 2023

Choose a reason for hiding this comment

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

This added documentation is not specific to those who are migrating from policy API. We should put it under the right section. I think adding it somewhere close to Writing Custom Single Agent RL Modules would be the way to go (it requires getting rid of those policy specific numenclature)

Maybe we can consolidate your paragraph with the description of what needs to be implemented for each forward method shown here?

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, I moved this up into the suggested section and created a new table to explain the difference between returning the "actions" key and NOT returning the "actions" key.

@sven1977
Copy link
Contributor Author

sven1977 commented Jun 9, 2023

Thanks for your review @kouroshHakha ! All very valid concerns and suggestions. I'll make these changes :)

sven1977 added 4 commits June 15, 2023 17:30
…odule_api_change_use_returned_actions_if_any
Signed-off-by: sven1977 <svenmika1977@gmail.com>
…odule_api_change_use_returned_actions_if_any
Signed-off-by: sven1977 <svenmika1977@gmail.com>
@sven1977 sven1977 merged commit 31ab8a7 into ray-project:master Jun 17, 2023
arvind-chandra pushed a commit to lmco/ray that referenced this pull request Aug 31, 2023
…nference|exploration, use actions as-is. (ray-project#36067)

Signed-off-by: e428265 <arvind.chandramouli@lmco.com>
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