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] Learner API: Policies using RLModules (for sampler only) do not need loss/stats/mixins. #34445

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
47c003c
wip
sven1977 Apr 15, 2023
cc25d0c
wip
sven1977 Apr 15, 2023
e6f2d3b
merge
sven1977 May 4, 2023
0248ce8
wip
sven1977 May 4, 2023
04595b3
wip
sven1977 May 4, 2023
bf78988
wip
sven1977 May 4, 2023
ceb8caa
wip
sven1977 May 4, 2023
cc632cb
Merge branch 'master' of https://github.com/ray-project/ray into lear…
sven1977 May 5, 2023
904bfda
merge
sven1977 May 5, 2023
b36304d
wip
sven1977 May 5, 2023
a112d5b
wip
sven1977 May 5, 2023
4b600ef
wip
sven1977 May 6, 2023
6dba48b
wip
sven1977 May 6, 2023
95fd464
wip
sven1977 May 6, 2023
6e8ab3f
wip
sven1977 May 6, 2023
b224d9f
wip
sven1977 May 6, 2023
26bdf8d
fix
sven1977 May 6, 2023
07409be
fix
sven1977 May 6, 2023
74f159f
wip
sven1977 May 6, 2023
70e6127
fix
sven1977 May 6, 2023
e4a58ee
fix
sven1977 May 6, 2023
c40cb8d
fix
sven1977 May 6, 2023
a2bc97a
fix
sven1977 May 6, 2023
81bcbd5
fix
sven1977 May 6, 2023
499d818
wip
sven1977 May 6, 2023
fd61ef6
LINT
sven1977 May 6, 2023
a53b043
fix
sven1977 May 6, 2023
f175a39
LINT
sven1977 May 6, 2023
3e95159
fix
sven1977 May 6, 2023
0ad186f
fix
sven1977 May 6, 2023
3a85eae
wip
sven1977 May 6, 2023
1380cb6
Merge remote-tracking branch 'origin/learner_rlm_policies_simplificat…
sven1977 May 6, 2023
e9ad050
merge
sven1977 May 6, 2023
05103ba
fix
sven1977 May 6, 2023
f0c1145
LINT
sven1977 May 6, 2023
90ee0ab
Add new Scheduler API.
sven1977 May 7, 2023
a628043
Merge branch 'master' of https://github.com/ray-project/ray into lear…
sven1977 May 7, 2023
6e9b0cd
wip
sven1977 May 7, 2023
7f85d0a
LINT
sven1977 May 7, 2023
1bb3ec2
fix
sven1977 May 7, 2023
21486d7
Merge branch 'master' of https://github.com/ray-project/ray into lear…
sven1977 May 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
wip
Signed-off-by: sven1977 <[email protected]>
  • Loading branch information
sven1977 committed May 6, 2023
commit 499d818e989070f67d1a15bbb060a7cc7d956ec4
5 changes: 3 additions & 2 deletions rllib/algorithms/impala/tests/test_impala_learner.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest

import numpy as np
import tree # pip install dm_tree

import ray
from ray.rllib.algorithms.impala import ImpalaConfig
Expand Down Expand Up @@ -83,9 +84,9 @@ def test_impala_loss(self):
policy = algo.get_policy()

if fw == "tf2":
Copy link
Contributor

Choose a reason for hiding this comment

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

wait, is this necessary? why did this test work before when SampleBatch was in numpy fmt?

train_batch = tf.nest.map_structure(
train_batch = SampleBatch(tree.map_structure(
lambda x: tf.convert_to_tensor(x), FAKE_BATCH
)
))
elif fw == "torch":
train_batch = convert_to_torch_tensor(SampleBatch(FAKE_BATCH))

Expand Down
21 changes: 10 additions & 11 deletions rllib/algorithms/ppo/tests/test_ppo_with_rl_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,14 @@ def test_ppo_exploration_setup(self):
config, frameworks=("torch", "tf2"), with_eager_tracing=True
):
# Default Agent should be setup with StochasticSampling.
trainer = config.build()
algo = config.build()
# explore=False, always expect the same (deterministic) action.
a_ = trainer.compute_single_action(
a_ = algo.compute_single_action(
obs, explore=False, prev_action=np.array(2), prev_reward=np.array(1.0)
)

for _ in range(50):
a = trainer.compute_single_action(
a = algo.compute_single_action(
obs,
explore=False,
prev_action=np.array(2),
Expand All @@ -186,12 +186,12 @@ def test_ppo_exploration_setup(self):
actions = []
for _ in range(300):
actions.append(
trainer.compute_single_action(
algo.compute_single_action(
obs, prev_action=np.array(2), prev_reward=np.array(1.0)
)
)
check(np.mean(actions), 1.5, atol=0.2)
trainer.stop()
algo.stop()

def test_ppo_free_log_std_with_rl_modules(self):
"""Tests the free log std option works."""
Expand All @@ -217,8 +217,8 @@ def test_ppo_free_log_std_with_rl_modules(self):
)

for fw in framework_iterator(config, frameworks=("torch", "tf2")):
trainer = config.build()
policy = trainer.get_policy()
algo = config.build()
policy = algo.get_policy()

# Check the free log std var is created.
if fw == "torch":
Expand All @@ -245,14 +245,13 @@ def get_value(fw=fw, policy=policy, log_std_var=log_std_var):
init_std = get_value()
assert init_std == 0.0, init_std
batch = compute_gae_for_sample_batch(policy, PENDULUM_FAKE_BATCH.copy())
if fw == "torch":
batch = policy._lazy_tensor_dict(batch)
policy.learn_on_batch(batch)
batch = policy._lazy_tensor_dict(batch)
algo.learner_group.update(batch)

# Check the variable is updated.
post_std = get_value()
assert post_std != 0.0, post_std
trainer.stop()
algo.stop()


if __name__ == "__main__":
Expand Down
15 changes: 9 additions & 6 deletions rllib/models/tests/test_preprocessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def tearDownClass(cls) -> None:
def test_rlms_and_preprocessing(self):
config = (
ppo.PPOConfig()
.framework("tf2")
.environment(
env="ray.rllib.examples.env.random_env.RandomEnv",
env_config={
Expand All @@ -48,16 +49,18 @@ def test_rlms_and_preprocessing(self):
},
)
# Run this very quickly locally.
.rollouts(rollout_fragment_length=10)
.rollouts(num_rollout_workers=0)
.training(train_batch_size=10, sgd_minibatch_size=1, num_sgd_iter=1)
.rollouts(num_rollout_workers=0, rollout_fragment_length=10)
.training(
train_batch_size=10,
sgd_minibatch_size=1,
num_sgd_iter=1,
_enable_learner_api=True,
)
.rl_module(_enable_rl_module_api=True)
# Set this to True to enforce no preprocessors being used.
.experimental(_disable_preprocessor_api=True)
.framework("tf2")
)

config.rl_module(_enable_rl_module_api=True).training(_enable_learner_api=True)

for _ in framework_iterator(config, frameworks=("torch", "tf2")):
algo = config.build()
results = algo.train()
Expand Down