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] DQN Rainbow Learner with new API stack (and EnvRunner API). #43196

Merged
merged 6 commits into from
Feb 27, 2024

Conversation

simonsays1980
Copy link
Collaborator

@simonsays1980 simonsays1980 commented Feb 15, 2024

Why are these changes needed?

We are moving DQN Rainbow over to the new stack using RLModule API and EnvRunner API. This PR introduces the learners for DQN Rainbow on the new stack.

Related issue number

Closes #37777

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

…tributional loss and simple Q-loss. Double-Q implemented next.

Signed-off-by: Simon Zehnder <simon.zehnder@gmail.com>
@simonsays1980 simonsays1980 changed the title DQN Rainbow with new stack and EnvRunner API DQN Rainbow Learner with new stack and EnvRunner API Feb 15, 2024
Signed-off-by: Simon Zehnder <simon.zehnder@gmail.com>
from ray.rllib.utils.metrics import LAST_TARGET_UPDATE_TS, NUM_TARGET_UPDATES
from ray.rllib.utils.typing import ModuleID

# Now, this is double defined: In `SACRLModule` and here. I would keep it here
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's fine to leave them here as duplicates for better readability.

Imo, it's really not good to cross-import between different algorithms. Everywhere else, this would be ok to share.

timestep=timestep,
)

# TODO (Sven): APPO uses `config.target_update_frequency`. Can we
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 Will revisit once we re-visit APPO/IMPALA on the new stack in a few days.

def _update_module_target_networks(
self, module_id: ModuleID, config: DQNConfig
) -> None:
"""Updates the target Q network(s) of a module.
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, I don't think we need the docstring at all here. Move all the descriptions below into the super (abstract) method.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

To keep the code consistent let's implement the same design into the module definitions:

  • Parent class holds docstrings
  • Child class has no docstrings for inherited methods

@@ -182,8 +182,6 @@ def compute_loss_for_module(
if self.config.twin_q:
q_twin_selected = fwd_out[QF_TWIN_PREDS]

# TODO (simon): Implement twin Q.
Copy link
Contributor

Choose a reason for hiding this comment

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

awesome!

@@ -323,6 +319,12 @@ def _update_module_target_networks(
"""Updates the target Q network(s) of a module.

Applies Polyak averaging for the update.

Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, move this description to the super (abstract) method and remove the docstring here entirely.

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 a few comment-related nits!
Awesome work @simonsays1980 !

@sven1977 sven1977 added the tests-ok The tagger certifies test failures are unrelated and assumes personal liability. label Feb 20, 2024
@sven1977 sven1977 self-assigned this Feb 20, 2024
@sven1977 sven1977 changed the title DQN Rainbow Learner with new stack and EnvRunner API [RLlib] DQN Rainbow Learner with new API stack and EnvRunner API Feb 20, 2024
@sven1977 sven1977 changed the title [RLlib] DQN Rainbow Learner with new API stack and EnvRunner API [RLlib] DQN Rainbow Learner with new API stack (and EnvRunner API). Feb 20, 2024
@sven1977 sven1977 marked this pull request as ready for review February 20, 2024 13:25
sven1977 and others added 4 commits February 20, 2024 14:25
…menets.

Signed-off-by: Simon Zehnder <simon.zehnder@gmail.com>
Signed-off-by: Simon Zehnder <simon.zehnder@gmail.com>
…to dqn-rainbow-learner

Signed-off-by: Simon Zehnder <simon.zehnder@gmail.com>
@sven1977 sven1977 merged commit 359edb9 into ray-project:master Feb 27, 2024
8 of 9 checks passed
@simonsays1980 simonsays1980 deleted the dqn-rainbow-learner branch February 27, 2024 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

[RLlib] Enabling RLModule by default on DQN
2 participants