Skip to content

Commit

Permalink
[tune/wandb] Fix WandbTrainableMixin config for rllib trainables (#22063
Browse files Browse the repository at this point in the history
)

The WandbTrainableMixin doesn't work with RLLib trainables as they won't recognize the wandb parameter. Thus we should pop the wandb config before we initialize the rest of the trainable.
  • Loading branch information
krfricke authored Feb 3, 2022
1 parent 3f03ef8 commit bbc64eb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions python/ray/tune/integration/wandb.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,6 @@ def __init__(self, config: Dict, *args, **kwargs):
"`class YourTrainable(WandbTrainableMixin)`."
)

super().__init__(config, *args, **kwargs)

_config = config.copy()

try:
Expand All @@ -540,6 +538,8 @@ def __init__(self, config: Dict, *args, **kwargs):
"containing at least a `project` specification."
)

super().__init__(_config, *args, **kwargs)

api_key_file = wandb_config.pop("api_key_file", None)
if api_key_file:
api_key_file = os.path.expanduser(api_key_file)
Expand Down
23 changes: 23 additions & 0 deletions python/ray/tune/tests/test_integration_wandb.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,29 @@ def train_fn(config):
self.assertEqual(wrapped.wandb.kwargs["id"], trial.trial_id)
self.assertEqual(wrapped.wandb.kwargs["name"], trial.trial_name)

def testWandbMixinRllib(self):
"""Test compatibility with RLLib configuration dicts"""
# Local import to avoid tune dependency on rllib
try:
from ray.rllib.agents.ppo import PPOTrainer
except ImportError:
self.skipTest("ray[rllib] not available")
return

class WandbPPOTrainer(_MockWandbTrainableMixin, PPOTrainer):
pass

config = {
"env": "CartPole-v0",
"wandb": {
"project": "test_project",
"api_key": "1234",
},
}

# Test that trainer object can be initialized
WandbPPOTrainer(config)


if __name__ == "__main__":
import pytest
Expand Down

0 comments on commit bbc64eb

Please sign in to comment.