-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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] New API stack: Add systematic IMPALA learning tests for [CartPole|Pendulum] | [CPU|GPU|multi-CPU|multi-GPU] | [single- and multi-agent]. #46162
Merged
sven1977
merged 11 commits into
ray-project:master
from
sven1977:impala_systematic_learning_tests
Jun 22, 2024
+167
−109
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5984347
wip
sven1977 5fa71a4
wip
sven1977 3731f1c
Merge branch 'master' of https://github.com/ray-project/ray into impa…
sven1977 2fda5d2
Merge branch 'master' of https://github.com/ray-project/ray into impa…
sven1977 e35c1e1
wip
sven1977 0d325f1
Merge branch 'master' of https://github.com/ray-project/ray into impa…
sven1977 24906b4
wip
sven1977 33a8020
Merge branch 'master' of https://github.com/ray-project/ray into impa…
sven1977 4601df3
fix
sven1977 2855336
fix
sven1977 83c04c9
wip
sven1977 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 36 additions & 21 deletions
57
rllib/tuned_examples/impala/multi_agent_cartpole_impala.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,58 @@ | ||
# @OldAPIStack | ||
from ray.rllib.algorithms.impala import ImpalaConfig | ||
from ray.rllib.connectors.env_to_module.mean_std_filter import MeanStdFilter | ||
from ray.rllib.examples.envs.classes.multi_agent import MultiAgentCartPole | ||
from ray.rllib.utils.metrics import ( | ||
ENV_RUNNER_RESULTS, | ||
EPISODE_RETURN_MEAN, | ||
NUM_ENV_STEPS_SAMPLED_LIFETIME, | ||
) | ||
from ray import tune | ||
from ray.rllib.utils.test_utils import add_rllib_example_script_args | ||
from ray.tune.registry import register_env | ||
|
||
tune.registry.register_env("env", lambda cfg: MultiAgentCartPole(config=cfg)) | ||
parser = add_rllib_example_script_args() | ||
# Use `parser` to add your own custom command line options to this script | ||
# and (if needed) use their values toset up `config` below. | ||
args = parser.parse_args() | ||
|
||
register_env("env", lambda cfg: MultiAgentCartPole(config=cfg)) | ||
|
||
|
||
config = ( | ||
ImpalaConfig() | ||
.environment("env", env_config={"num_agents": 4}) | ||
.env_runners( | ||
num_envs_per_env_runner=5, | ||
num_env_runners=4, | ||
observation_filter="MeanStdFilter", | ||
.api_stack( | ||
enable_rl_module_and_learner=True, | ||
enable_env_runner_and_connector_v2=True, | ||
) | ||
.resources(num_gpus=1, _fake_gpus=True) | ||
.multi_agent( | ||
policies=["p0", "p1", "p2", "p3"], | ||
policy_mapping_fn=(lambda agent_id, episode, worker, **kwargs: f"p{agent_id}"), | ||
.environment("env", env_config={"num_agents": 2}) | ||
.env_runners( | ||
env_to_module_connector=lambda env: MeanStdFilter(multi_agent=True), | ||
) | ||
.training( | ||
num_sgd_iter=1, | ||
vf_loss_coeff=0.005, | ||
vtrace=True, | ||
model={ | ||
"fcnet_hiddens": [32], | ||
"fcnet_activation": "linear", | ||
train_batch_size_per_learner=500, | ||
grad_clip=40.0, | ||
grad_clip_by="global_norm", | ||
lr=0.0005, | ||
vf_loss_coeff=0.1, | ||
) | ||
.rl_module( | ||
model_config_dict={ | ||
"vf_share_layers": True, | ||
"uses_new_env_runners": True, | ||
}, | ||
replay_proportion=0.0, | ||
) | ||
.multi_agent( | ||
policies=["p0", "p1"], | ||
policy_mapping_fn=(lambda agent_id, episode, **kwargs: f"p{agent_id}"), | ||
) | ||
) | ||
|
||
stop = { | ||
f"{ENV_RUNNER_RESULTS}/{EPISODE_RETURN_MEAN}": 600, # 600 / 4 (==num_agents) = 150 | ||
f"{NUM_ENV_STEPS_SAMPLED_LIFETIME}": 200000, | ||
f"{ENV_RUNNER_RESULTS}/{EPISODE_RETURN_MEAN}": 800.0, | ||
NUM_ENV_STEPS_SAMPLED_LIFETIME: 400000, | ||
} | ||
|
||
|
||
if __name__ == "__main__": | ||
from ray.rllib.utils.test_utils import run_rllib_example_script_experiment | ||
|
||
run_rllib_example_script_experiment(config, args, stop=stop) |
46 changes: 0 additions & 46 deletions
46
rllib/tuned_examples/impala/multi_agent_cartpole_impala_envrunner.py
This file was deleted.
Oops, something went wrong.
43 changes: 43 additions & 0 deletions
43
rllib/tuned_examples/impala/multi_agent_cartpole_impala_old_api_stack.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# @OldAPIStack | ||
from ray.rllib.algorithms.impala import ImpalaConfig | ||
from ray.rllib.examples.envs.classes.multi_agent import MultiAgentCartPole | ||
from ray.rllib.utils.metrics import ( | ||
ENV_RUNNER_RESULTS, | ||
EPISODE_RETURN_MEAN, | ||
NUM_ENV_STEPS_SAMPLED_LIFETIME, | ||
) | ||
from ray import tune | ||
|
||
tune.registry.register_env("env", lambda cfg: MultiAgentCartPole(config=cfg)) | ||
|
||
|
||
config = ( | ||
ImpalaConfig() | ||
.environment("env", env_config={"num_agents": 4}) | ||
.env_runners( | ||
num_envs_per_env_runner=5, | ||
num_env_runners=4, | ||
observation_filter="MeanStdFilter", | ||
) | ||
.resources(num_gpus=1, _fake_gpus=True) | ||
.multi_agent( | ||
policies=["p0", "p1", "p2", "p3"], | ||
policy_mapping_fn=(lambda agent_id, episode, worker, **kwargs: f"p{agent_id}"), | ||
) | ||
.training( | ||
num_sgd_iter=1, | ||
vf_loss_coeff=0.005, | ||
vtrace=True, | ||
model={ | ||
"fcnet_hiddens": [32], | ||
"fcnet_activation": "linear", | ||
"vf_share_layers": True, | ||
}, | ||
replay_proportion=0.0, | ||
) | ||
) | ||
|
||
stop = { | ||
f"{ENV_RUNNER_RESULTS}/{EPISODE_RETURN_MEAN}": 600, # 600 / 4 (==num_agents) = 150 | ||
f"{NUM_ENV_STEPS_SAMPLED_LIFETIME}": 200000, | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"-stop-reward=" might error out.