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][Training iteration fn] APEX conversion #22937

Merged
merged 27 commits into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d70fd04
This is a working DQN with all non-blocking operations. There's still…
avnishn Mar 9, 2022
23d8e0a
Lint
avnishn Mar 9, 2022
9d1ec87
Fix tests
avnishn Mar 11, 2022
de26764
Modify Alpha Star to be able to process multiple inflight training re…
avnishn Mar 12, 2022
90d4a0d
Merge branch 'master' of https://github.com/ray-project/ray into apex…
avnishn Mar 15, 2022
6f084de
Address review comments. Remove dependence of num replay samples samp…
avnishn Mar 15, 2022
6390eb6
lint
avnishn Mar 15, 2022
f097acf
Address comments, lint
avnishn Mar 15, 2022
94a07ca
Delete docstring for lint
avnishn Mar 15, 2022
7bfcc34
wip
sven1977 Apr 5, 2022
280bbd2
wip
sven1977 Apr 5, 2022
131f2a6
wip
sven1977 Apr 5, 2022
1148bc1
Merge branch 'master' of https://github.com/ray-project/ray into apex…
avnishn Apr 7, 2022
fd07429
Merge branch 'apex_training_itr' of https://github.com/avnishn/ray in…
avnishn Apr 7, 2022
eb67e1e
Merge branch 'master' of https://github.com/ray-project/ray into apex…
avnishn Apr 7, 2022
6e53d2c
Change training intensity to be tied to the number of samples collected
avnishn Apr 7, 2022
5c5ac8e
Lint
avnishn Apr 7, 2022
6de2377
Temp
avnishn Apr 8, 2022
9b8c4b5
Make replay capacity more interpretable in APEX
avnishn Apr 11, 2022
278461a
Adding same setting for exec plan
avnishn Apr 11, 2022
1894703
Temp
avnishn Apr 14, 2022
6ab145f
Make training intensity asynchronous but a hard limit
avnishn Apr 18, 2022
eef2ab4
Lin
avnishn Apr 18, 2022
f4d51e4
Merge branch 'master' of https://github.com/ray-project/ray into apex…
sven1977 Apr 18, 2022
b4db638
Fix Lint and APEX tests
avnishn Apr 18, 2022
8cf3902
Merge branch 'master' of https://github.com/ray-project/ray into apex…
avnishn Apr 20, 2022
5e769ba
Increase timeout
avnishn Apr 20, 2022
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
31 changes: 18 additions & 13 deletions rllib/agents/a3c/a3c.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,24 @@ def sample_and_compute_grads(worker: RolloutWorker) -> Dict[str, Any]:
# update that particular worker's weights.
global_vars = None
learner_info_builder = LearnerInfoBuilder(num_devices=1)
for worker, result in async_results.items():
# Apply gradients to local worker.
with self._timers[APPLY_GRADS_TIMER]:
local_worker.apply_gradients(result["grads"])
self._timers[APPLY_GRADS_TIMER].push_units_processed(result["agent_steps"])

# Update all step counters.
self._counters[NUM_AGENT_STEPS_SAMPLED] += result["agent_steps"]
self._counters[NUM_ENV_STEPS_SAMPLED] += result["env_steps"]
self._counters[NUM_AGENT_STEPS_TRAINED] += result["agent_steps"]
self._counters[NUM_ENV_STEPS_TRAINED] += result["env_steps"]
for worker, results in async_results.items():
for result in results:
avnishn marked this conversation as resolved.
Show resolved Hide resolved
# Apply gradients to local worker.
with self._timers[APPLY_GRADS_TIMER]:
local_worker.apply_gradients(result["grads"])
self._timers[APPLY_GRADS_TIMER].push_units_processed(
result["agent_steps"]
)

# Update all step counters.
self._counters[NUM_AGENT_STEPS_SAMPLED] += result["agent_steps"]
self._counters[NUM_ENV_STEPS_SAMPLED] += result["env_steps"]
self._counters[NUM_AGENT_STEPS_TRAINED] += result["agent_steps"]
self._counters[NUM_ENV_STEPS_TRAINED] += result["env_steps"]

learner_info_builder.add_learn_on_batch_results_multi_agent(
result["infos"]
)

# Create current global vars.
global_vars = {
Expand All @@ -154,8 +161,6 @@ def sample_and_compute_grads(worker: RolloutWorker) -> Dict[str, Any]:
weights = local_worker.get_weights(local_worker.get_policies_to_train())
worker.set_weights.remote(weights, global_vars)

learner_info_builder.add_learn_on_batch_results_multi_agent(result["infos"])

# Update global vars of the local worker.
if global_vars:
local_worker.set_global_vars(global_vars)
Expand Down
27 changes: 18 additions & 9 deletions rllib/agents/alpha_star/alpha_star.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from collections import defaultdict
import gym
from typing import DefaultDict, Optional, Type
import tree

import ray
from ray.actor import ActorHandle
Expand Down Expand Up @@ -292,9 +293,10 @@ def training_iteration(self) -> ResultDict:
remote_fn=self._sample_and_send_to_buffer,
)
# Update sample counters.
for (env_steps, agent_steps) in sample_results.values():
self._counters[NUM_ENV_STEPS_SAMPLED] += env_steps
self._counters[NUM_AGENT_STEPS_SAMPLED] += agent_steps
for sample_result in sample_results.values():
for (env_steps, agent_steps) in sample_result:
self._counters[NUM_ENV_STEPS_SAMPLED] += env_steps
avnishn marked this conversation as resolved.
Show resolved Hide resolved
self._counters[NUM_AGENT_STEPS_SAMPLED] += agent_steps

# Trigger asynchronous training update requests on all learning
# policies.
Expand All @@ -314,11 +316,12 @@ def training_iteration(self) -> ResultDict:
)

# Update sample counters.
for result in train_results.values():
if NUM_AGENT_STEPS_TRAINED in result:
self._counters[NUM_AGENT_STEPS_TRAINED] += result[
NUM_AGENT_STEPS_TRAINED
]
for train_result in train_results.values():
for result in train_result:
if NUM_AGENT_STEPS_TRAINED in result:
self._counters[NUM_AGENT_STEPS_TRAINED] += result[
NUM_AGENT_STEPS_TRAINED
]

# For those policies that have been updated in this iteration
# (not all policies may have undergone an updated as we are
Expand All @@ -329,7 +332,13 @@ def training_iteration(self) -> ResultDict:
with self._timers[SYNCH_WORKER_WEIGHTS_TIMER]:
train_infos = {}
policy_weights = {}
for pol_actor, policy_result in train_results.items():
for pol_actor, policy_results in train_results.items():
if len(policy_results) > 1:
avnishn marked this conversation as resolved.
Show resolved Hide resolved
policy_result = tree.map_structure(
lambda *_args: sum(_args) / len(policy_results), *policy_results
)
else:
policy_result = policy_results[0]
if policy_result:
pid = self.distributed_learners.get_policy_id(pol_actor)
train_infos[pid] = policy_result
Expand Down
3 changes: 2 additions & 1 deletion rllib/agents/alpha_star/tests/test_alpha_star.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
class TestAlphaStar(unittest.TestCase):
@classmethod
def setUpClass(cls):
ray.init(num_cpus=20)
# ray.init(num_cpus=20)
avnishn marked this conversation as resolved.
Show resolved Hide resolved
ray.init(local_mode=True)
Copy link
Member

Choose a reason for hiding this comment

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

debug code?

Copy link
Member Author

Choose a reason for hiding this comment

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

whoops yeah I'll get rid of this my b.


@classmethod
def tearDownClass(cls):
Expand Down
Loading