-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RLlib] APEX_DDPG (PyTorch) test case and docs. (#8288)
APEX_DDPG (PyTorch) test case and docs.
- Loading branch information
Showing
9 changed files
with
90 additions
and
23 deletions.
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
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
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,56 @@ | ||
import pytest | ||
import unittest | ||
|
||
import ray | ||
import ray.rllib.agents.ddpg.apex as apex_ddpg | ||
from ray.rllib.utils.test_utils import check, framework_iterator | ||
|
||
|
||
class TestApexDDPG(unittest.TestCase): | ||
def setUp(self): | ||
ray.init(num_cpus=4) | ||
|
||
def tearDown(self): | ||
ray.shutdown() | ||
|
||
def test_apex_ddpg_compilation_and_per_worker_epsilon_values(self): | ||
"""Test whether an APEX-DDPGTrainer can be built on all frameworks.""" | ||
config = apex_ddpg.APEX_DDPG_DEFAULT_CONFIG.copy() | ||
config["num_workers"] = 3 | ||
config["prioritized_replay"] = True | ||
config["timesteps_per_iteration"] = 100 | ||
config["min_iter_time_s"] = 1 | ||
config["learning_starts"] = 0 | ||
config["optimizer"]["num_replay_buffer_shards"] = 1 | ||
num_iterations = 1 | ||
for _ in framework_iterator(config, ("torch", "tf")): | ||
plain_config = config.copy() | ||
trainer = apex_ddpg.ApexDDPGTrainer( | ||
config=plain_config, env="Pendulum-v0") | ||
|
||
# Test per-worker scale distribution. | ||
infos = trainer.workers.foreach_policy( | ||
lambda p, _: p.get_exploration_info()) | ||
scale = [i["cur_scale"] for i in infos] | ||
expected = [ | ||
0.4**(1 + (i + 1) / float(config["num_workers"] - 1) * 7) | ||
for i in range(config["num_workers"]) | ||
] | ||
check(scale, [0.0] + expected) | ||
|
||
for _ in range(num_iterations): | ||
print(trainer.train()) | ||
|
||
# Test again per-worker scale distribution | ||
# (should not have changed). | ||
infos = trainer.workers.foreach_policy( | ||
lambda p, _: p.get_exploration_info()) | ||
scale = [i["cur_scale"] for i in infos] | ||
check(scale, [0.0] + expected) | ||
|
||
trainer.stop() | ||
|
||
|
||
if __name__ == "__main__": | ||
import sys | ||
sys.exit(pytest.main(["-v", __file__])) |
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
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
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
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
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
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