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] Fix stateful module errors with inference only mode. #45465

Conversation

simonsays1980
Copy link
Collaborator

@simonsays1980 simonsays1980 commented May 21, 2024

Why are these changes needed?

Stateful models need to collect states from the critic during sampling, therefore they cannot be inference-only. This PR fixes this error by setting inference-only=False for stateful modules and checking statefulness in the get_state.

Related issue number

Related to #44758

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: Simon Zehnder <simon.zehnder@gmail.com>
Signed-off-by: Simon Zehnder <simon.zehnder@gmail.com>
Signed-off-by: Simon Zehnder <simon.zehnder@gmail.com>
Signed-off-by: Simon Zehnder <simon.zehnder@gmail.com>
Signed-off-by: Simon Zehnder <simon.zehnder@gmail.com>
Signed-off-by: Simon Zehnder <simon.zehnder@gmail.com>
…' mode.

Signed-off-by: Simon Zehnder <simon.zehnder@gmail.com>
Signed-off-by: Simon Zehnder <simon.zehnder@gmail.com>
@@ -20,6 +20,9 @@ class PPORLModule(RLModule, abc.ABC):
def setup(self):
# __sphinx_doc_begin__
catalog = self.config.get_catalog()
# If we have a stateful model states for the critic need to be collected
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we also use is_stateful() here? What if the user doesn't use the built-in use_lstm option, but comes with their own stateful model?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@sven1977 this was my first intend, however at this point in time is_stateful() cannot be called, yet b/c the encoder is not yet defined.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree that this is not a nice solution, but at this point in the code we need to know, if the module is stateful or not, but the is_stateful() depends on the encoder which is defined depending on inference-only being True/False.

@sven1977 sven1977 marked this pull request as ready for review May 21, 2024 15:58
@sven1977 sven1977 changed the title [RLlib] - Fix stateful module errors with inference only mode [RLlib] Fix stateful module errors with inference only mode. May 21, 2024
Copy link
Contributor

@sven1977 sven1977 left a comment

Choose a reason for hiding this comment

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

Just one question about use_lstm not being generic enough as a criterion to determine statefulnes..

…ecurrentEncoderConfig' and added an additional check for 'inference-only' b/c negation resulted in learner modules being 'inference-only'. This is fixed now.

Signed-off-by: Simon Zehnder <simon.zehnder@gmail.com>
@simonsays1980
Copy link
Collaborator Author

Just one question about use_lstm not being generic enough as a criterion to determine statefulnes..

I replaced this now with a more generic approach using RecurrentEncoderConfig (we might need to define in the future a StatefulEncoderConfig when attention is joining the club).

@sven1977 sven1977 enabled auto-merge (squash) May 22, 2024 10:21
@github-actions github-actions bot added the go add ONLY when ready to merge, run all tests label May 22, 2024
@sven1977 sven1977 merged commit 1afa2ab into ray-project:master May 22, 2024
8 checks passed
ryanaoleary pushed a commit to ryanaoleary/ray that referenced this pull request Jun 6, 2024
ryanaoleary pushed a commit to ryanaoleary/ray that referenced this pull request Jun 6, 2024
GabeChurch pushed a commit to GabeChurch/ray that referenced this pull request Jun 11, 2024
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants