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

Add warning when using PPO on GPU and update doc #2017

Merged
merged 2 commits into from
Oct 7, 2024

Conversation

Dev1nW
Copy link
Contributor

@Dev1nW Dev1nW commented Oct 2, 2024

Closes issue #2012.

Added comment to PPO documentation that CPU should primarily be used unless using CNN as well as sample code. Added warning to user for both PPO and A2C that CPU should be used if the user is running GPU without using a CNN, reference Issue #1245.

Description

Added lines 91-107 of docs/modules/ppo.rst to explain that PPO should use CPU rather than GPU unless using CNN. Gave a code example just like in A2C documentation.

Added lines 122-134 to stable_baselines/a2c/a2c.py to give error if the device is not cpu and the policy is not CNN, this only warns the user.

Added lines 137-149 to stable_baselines/ppo/ppo.py to give error if the device is not cpu and the policy is not CNN, this only warns the user.

Motivation and Context

Closes issue #2012.

  • I have raised an issue to propose this change (required for new features and bug fixes)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (update in the documentation)

Checklist

  • I've read the CONTRIBUTION guide (required)
  • I have updated the changelog accordingly (required).
  • My change requires a change to the documentation.
  • I have updated the tests accordingly (required for a bug fix or a new feature).
  • I have updated the documentation accordingly.
  • I have opened an associated PR on the SB3-Contrib repository (if necessary)
  • I have opened an associated PR on the RL-Zoo3 repository (if necessary)
  • I have reformatted the code using make format (required)
  • I have checked the codestyle using make check-codestyle and make lint (required)
  • I have ensured make pytest and make type both pass. (required)
  • I have checked that the documentation builds using make doc (required)

Note: You can run most of the checks using make commit-checks.

Note: we are using a maximum length of 127 characters per line

Sorry, something went wrong.

Added comment to PPO documentation that CPU should primarily be used unless using CNN as well as sample code. Added warning to user for both PPO and A2C that CPU should be used if the user is running GPU without using a CNN, reference Issue DLR-RM#1245.
@@ -118,6 +119,19 @@ def __init__(
),
)

try:
if isinstance(device, str) and device != "cpu" and isinstance(policy, str) and policy != "CnnPolicy":
with warnings.catch_warnings():
Copy link
Member

Choose a reason for hiding this comment

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

why do you need to catch the warning?

Also, please make it a helper function, so it can be re-used by PPO and others (for instance, in the SB3 contrib repo).

The condition should be policy == "MlpPolicy" and the device object should be a pytorch device one (so using self.device if I recall).

@@ -134,6 +134,19 @@ def __init__(
spaces.MultiBinary,
),
)
try:
Copy link
Member

Choose a reason for hiding this comment

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

why do you need try/except?

please also add a test

@araffin araffin changed the title Update documentation Add warning when using PPO on GPU and update doc Oct 7, 2024
@araffin araffin merged commit 56c153f into DLR-RM:master Oct 7, 2024
4 checks passed
@Dev1nW Dev1nW deleted the doc-branch branch October 7, 2024 15:03
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