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 vol. 41: Add new example on async gym vector env. #49527

Conversation

sven1977
Copy link
Contributor

@sven1977 sven1977 commented Jan 1, 2025

Cleanup examples folder vol. 41: Add new example on async gym vector env.

  • The script demo's that using vector envs with gymnasium's async vectorize mode speeds up the EnvRunners significantly.
  • Added to CI as a test, comparing both SYNC and ASYNC modes with each other.
  • Added to rllib-examples.rst page (and cleanup up that page through vale).

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 <svenmika1977@gmail.com>
Signed-off-by: sven1977 <svenmika1977@gmail.com>
@sven1977 sven1977 requested review from maxpumperla and a team as code owners January 1, 2025 15:44
@sven1977 sven1977 added rllib RLlib related issues rllib-env rllib env related issues rllib-docs-or-examples Issues related to RLlib documentation or rllib/examples rllib-newstack rllib-envrunners Issues around the sampling backend of RLlib labels Jan 1, 2025
k
Signed-off-by: sven1977 <svenmika1977@gmail.com>
@sven1977 sven1977 enabled auto-merge (squash) January 1, 2025 19:01
@sven1977 sven1977 disabled auto-merge January 1, 2025 19:01
@github-actions github-actions bot added the go add ONLY when ready to merge, run all tests label Jan 1, 2025
Signed-off-by: sven1977 <svenmika1977@gmail.com>
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. Just two small nits for readability

if self.config.remote_worker_envs
else VectorizeMode.SYNC
vectorize_mode
if isinstance(vectorize_mode, gym.envs.registration.VectorizeMode)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't this already validated in AlgorithmConfig? Imo we need to validate only once. Either here or in the AlgorithmConfig.

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, but an AlgorithmConfig only gets validated in the algo, not when it enters an EnvRunner. So - in theory - users could still run into this if they instantiate an EnvRunner in isolation with some config that has this defined as a string (e.g. "SYNC").

----------------------
`python [script file name].py --enable-new-api-stack `

Use the `--vectorize-mode=BOTH` option to run both modes (SYNC and ASYNC)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Awesome!


tune.register_env("slow-env", _env_creator)

if args.vectorize_mode == "BOTH" and args.no_tune:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not just setting no_tune=False if vectorize_mode="BOTH"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Added an error, instead and simplified the if-statement.

@@ -1087,9 +1087,11 @@ def run_rllib_example_script_experiment(
enable_env_runner_and_connector_v2=False,
)

# Define EnvRunner/RolloutWorker scaling and behavior.
Copy link
Collaborator

Choose a reason for hiding this comment

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

And ... gone :D

@sven1977 sven1977 enabled auto-merge (squash) January 3, 2025 11:16
Signed-off-by: sven1977 <svenmika1977@gmail.com>
@github-actions github-actions bot disabled auto-merge January 3, 2025 11:16
@sven1977 sven1977 enabled auto-merge (squash) January 3, 2025 11:17
Signed-off-by: sven1977 <svenmika1977@gmail.com>
@github-actions github-actions bot disabled auto-merge January 3, 2025 12:23
@sven1977 sven1977 enabled auto-merge (squash) January 3, 2025 13:01
@sven1977 sven1977 merged commit 474448c into ray-project:master Jan 3, 2025
6 checks passed
@sven1977 sven1977 deleted the cleanup_examples_folder_41_async_vector_env branch January 3, 2025 13:53
roshankathawate pushed a commit to roshankathawate/ray that referenced this pull request Jan 7, 2025
roshankathawate pushed a commit to roshankathawate/ray that referenced this pull request Jan 9, 2025
… vector env. (ray-project#49527)

Signed-off-by: Roshan Kathawate <roshankathawate@gmail.com>
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 rllib RLlib related issues rllib-docs-or-examples Issues related to RLlib documentation or rllib/examples rllib-env rllib env related issues rllib-envrunners Issues around the sampling backend of RLlib rllib-newstack
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants