mirror of
https://github.com/gryf/coach.git
synced 2025-12-18 03:30:19 +01:00
Adding initial interface for backend and redis pubsub (#19)
* Adding initial interface for backend and redis pubsub * Addressing comments, adding super in all memories * Removing distributed experience replay
This commit is contained in:
committed by
zach dwiel
parent
a54ef2757f
commit
6b2de6ba6d
@@ -2,42 +2,17 @@
|
||||
"""
|
||||
import argparse
|
||||
import time
|
||||
import json
|
||||
|
||||
from rl_coach.base_parameters import TaskParameters
|
||||
from rl_coach.coach import expand_preset
|
||||
from rl_coach import core_types
|
||||
from rl_coach.utils import short_dynamic_import
|
||||
from rl_coach.memories.non_episodic.distributed_experience_replay import DistributedExperienceReplay
|
||||
from rl_coach.memories.memory import MemoryGranularity
|
||||
from rl_coach.memories.backend.memory_impl import construct_memory_params
|
||||
|
||||
# Q: specify alternative distributed memory, or should this go in the preset?
|
||||
# A: preset must define distributed memory to be used. we aren't going to take a non-distributed preset and automatically distribute it.
|
||||
|
||||
def heatup(graph_manager):
|
||||
memory = DistributedExperienceReplay(max_size=(MemoryGranularity.Transitions, 1000000),
|
||||
redis_ip=graph_manager.agent_params.memory.redis_ip,
|
||||
redis_port=graph_manager.agent_params.memory.redis_port)
|
||||
|
||||
while(memory.num_transitions() < graph_manager.heatup_steps.num_steps):
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
class StepsLoop(object):
|
||||
"""StepsLoop facilitates a simple while loop"""
|
||||
def __init__(self, steps_counters, phase, steps):
|
||||
super(StepsLoop, self).__init__()
|
||||
self.steps_counters = steps_counters
|
||||
self.phase = phase
|
||||
self.steps = steps
|
||||
|
||||
self.step_end = self._step_count() + steps.num_steps
|
||||
|
||||
def _step_count(self):
|
||||
return self.steps_counters[self.phase][self.steps.__class__]
|
||||
|
||||
def continue(self):
|
||||
return self._step_count() < count_end:
|
||||
|
||||
|
||||
def training_worker(graph_manager, checkpoint_dir):
|
||||
"""
|
||||
@@ -51,12 +26,8 @@ def training_worker(graph_manager, checkpoint_dir):
|
||||
# save randomly initialized graph
|
||||
graph_manager.save_checkpoint()
|
||||
|
||||
# optionally wait for a specific number of transitions to be in memory before training
|
||||
heatup(graph_manager)
|
||||
|
||||
# training loop
|
||||
stepper = StepsLoop(graph_manager.total_steps_counters, RunPhase.TRAIN, graph_manager.improve_steps)
|
||||
while stepper.continue():
|
||||
while True:
|
||||
graph_manager.phase = core_types.RunPhase.TRAIN
|
||||
graph_manager.train(core_types.TrainingSteps(1))
|
||||
graph_manager.phase = core_types.RunPhase.UNDEFINED
|
||||
@@ -65,7 +36,6 @@ def training_worker(graph_manager, checkpoint_dir):
|
||||
|
||||
graph_manager.save_checkpoint()
|
||||
|
||||
# TODO: signal to workers that training is done
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
@@ -85,12 +55,18 @@ def main():
|
||||
help="(int) Port of the redis server",
|
||||
default=6379,
|
||||
type=int)
|
||||
parser.add_argument('--memory_backend_params',
|
||||
help="(string) JSON string of the memory backend params",
|
||||
type=str)
|
||||
args = parser.parse_args()
|
||||
|
||||
graph_manager = short_dynamic_import(expand_preset(args.preset), ignore_module_case=True)
|
||||
|
||||
graph_manager.agent_params.memory.redis_ip = args.redis_ip
|
||||
graph_manager.agent_params.memory.redis_port = args.redis_port
|
||||
if args.memory_backend_params:
|
||||
args.memory_backend_params = json.loads(args.memory_backend_params)
|
||||
if 'run_type' not in args.memory_backend_params:
|
||||
args.memory_backend_params['run_type'] = 'trainer'
|
||||
graph_manager.agent_params.memory.register_var('memory_backend_params', construct_memory_params(args.memory_backend_params))
|
||||
|
||||
training_worker(
|
||||
graph_manager=graph_manager,
|
||||
|
||||
Reference in New Issue
Block a user