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] Cleanup examples folder #15: Add example script for policy (RLModule) inference w/ ConnectorV2. #45845

Conversation

sven1977
Copy link
Contributor

@sven1977 sven1977 commented Jun 10, 2024

Cleanup examples folder #15: Add example script for policy (RLModule) inference w/ ConnectorV2.

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

Signed-off-by: sven1977 <[email protected]>
Signed-off-by: sven1977 <[email protected]>
@sven1977 sven1977 added the tests-ok The tagger certifies test failures are unrelated and assumes personal liability. label Jun 11, 2024
@sven1977 sven1977 enabled auto-merge (squash) June 11, 2024 08:02
@github-actions github-actions bot added the go add ONLY when ready to merge, run all tests label Jun 11, 2024
Signed-off-by: sven1977 <[email protected]>
Copy link
Collaborator

@simonsays1980 simonsays1980 left a comment

Choose a reason for hiding this comment

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

LGTM. Next step: Let’s think about how to use a naked module without RLlib connectors and episodes, e.g. on the edge.

@@ -60,6 +75,7 @@ def __call__(
Each connector piece receives as input the output of the previous connector
piece in the pipeline.
"""
shared_data = shared_data if shared_data is not None else {}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice! This should spare us some naughty definitions in learner code

input_observation_space=env.observation_space,
input_action_space=env.action_space,
connectors=[
AddObservationsFromEpisodesToBatch(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here we need more documentation which connectors are needed. For the module we get its inputs from the input specs.
imo this example is still an easy one b/c the connectors are stateless themselves. This could be done w/o connectors easily but with a mean_std filter we need the actual state of the connector.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, this example wouldn't work with stateful connectors.
I'll add more documentation to the examples. Need to write all the ConnectorV2 docs still anyways :)

)
# Create new Algorithm and restore its state from the last checkpoint.
rl_module = RLModule.from_checkpoint(
os.path.join(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this also work with patchilb?

Copy link
Collaborator

Choose a reason for hiding this comment

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

pathlib

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think so. For joining, I like to use os.path.join. Seems simpler to use.


# For the module-to-env pipeline, we will use the convenient config utility.
print("Module-to-env ConnectorV2 ...")
module_to_env = base_config.build_module_to_env_connector(env=env)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why can we build this easily from the alto and the env-to-module not?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can do both with config.build_[env_to_module/module_to_env]_connector, just wanted to show both ways.

reward,
terminated=terminated,
truncated=truncated,
# Same here: [0] b/c RLModule output is batched (w/ B=1).
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should give here also the hint that we use the episode here to store the states of the module such that it can be used in the connectors and module without intervention.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The user might otherwise question why to store all this and harm performance with it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True! I agree, the next thing should be an "on-the-edge" example:

  • RLModule (as ONNX re-import?)
  • stateful ConnectorV2 (loaded from checkpoint?)
  • Episode (how do we make this efficient and not carry around a maybe 10k ts episode?) <- here, I have to say though, extending an episode is just adding items to a list, which does NOT pose a large performance penalty
  • what if all the above must run on non-python, e.g. C++ ??

@sven1977 sven1977 enabled auto-merge (squash) June 11, 2024 09:51
@sven1977 sven1977 merged commit 333eed3 into ray-project:master Jun 11, 2024
7 checks passed
@sven1977 sven1977 deleted the cleanup_examples_folder_15_policy_inference_w_connector branch June 11, 2024 12:28
richardsliu pushed a commit to richardsliu/ray that referenced this pull request Jun 12, 2024
…r policy (RLModule) inference w/ ConnectorV2. (ray-project#45845)

Signed-off-by: Richard Liu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go add ONLY when ready to merge, run all tests tests-ok The tagger certifies test failures are unrelated and assumes personal liability.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants