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 APPO RLModule inference-only problems. #45111

Merged

Conversation

simonsays1980
Copy link
Collaborator

@simonsays1980 simonsays1980 commented May 2, 2024

Why are these changes needed?

The APPO algorithm could not deal with inference-only, yet. This change does enable inference-only modules for APPO. In addition to the _inference_only_state_dict_keys from PPO, APPO needs to remove the target networks when in inference.

For this to work properly a parent RLModule is needed that triggers the building of the _inference_only_state_dict_keys. Due to inheritance from the PPO module polymorphism did not work out of the box b/c this parent was missing. This parent is added to APPO in this PR as well, named APPORLModule.

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

@simonsays1980 simonsays1980 added rllib RLlib related issues rllib-newstack labels May 2, 2024
@simonsays1980 simonsays1980 self-assigned this May 2, 2024
…rence_only_state_dict_keys'. Modified 'PPOTorchRLModuel' to not register already keys from APPO.

Signed-off-by: Simon Zehnder <[email protected]>
@simonsays1980 simonsays1980 marked this pull request as ready for review May 2, 2024 14:38
@simonsays1980 simonsays1980 changed the title Made APPO RLModule always a learner module. [RLlib] - Fix APPO RLModule inference-only problems. May 2, 2024
@anyscalesam anyscalesam requested a review from sven1977 May 2, 2024 19:42
@sven1977 sven1977 assigned sven1977 and unassigned simonsays1980 May 3, 2024
@@ -15,19 +16,7 @@
_, tf, _ = try_import_tf()


class APPOTfRLModule(PPOTfRLModule, RLModuleWithTargetNetworksInterface):
def setup(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

@@ -14,20 +15,9 @@
from ray.rllib.utils.nested_dict import NestedDict


class APPOTorchRLModule(PPOTorchRLModule, RLModuleWithTargetNetworksInterface):
@override(PPOTorchRLModule)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

@@ -42,8 +32,26 @@ def output_specs_train(self) -> List[str]:

@override(PPOTorchRLModule)
def _forward_train(self, batch: NestedDict):
if self.inference_only:
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Maybe we should move this error into the parent RLModule class' main method?
def forward_train(self, ...):?

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.

LGTM! Just one nit/question about moving an error further up the inheritance chain to have all future sub-classes benefit from this logic.
Thanks @simonsays1980 ! :)

@sven1977 sven1977 merged commit 45d5640 into ray-project:master May 3, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rllib RLlib related issues rllib-newstack
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants