mirror of
https://github.com/wassname/ray.git
synced 2026-07-19 11:27:32 +08:00
* re * wip * wip * a3c working * torch support * pg works * lint * rm v2 * consumer id * clean up pg * clean up more * fix python 2.7 * tf session management * docs * dqn wip * fix compile * dqn * apex runs * up * impotrs * ddpg * quotes * fix tests * fix last r * fix tests * lint * pass checkpoint restore * kwar * nits * policy graph * fix yapf * com * class * pyt * vectorization * update * test cpe * unit test * fix ddpg2 * changes * wip * args * faster test * common * fix * add alg option * batch mode and policy serving * multi serving test * todo * wip * serving test * doc async env * num envs * comments * thread * remove init hook * update * fix ppo * comments1 * fix * updates * add jenkins tests * fix * fix pytorch * fix * fixes * fix a3c policy * fix squeeze * fix trunc on apex * fix squeezing for real * update * remove horizon test for now * multiagent wip * update * fix race condition * fix ma * t * doc * st * wip * example * wip * working * cartpole * wip * batch wip * fix bug * make other_batches None default * working * debug * nit * warn * comments * fix ppo * fix obs filter * update * wip * tf * update * fix * cleanup * cleanup * spacing * model * fix * dqn * fix ddpg * doc * keep names * update * fix * com * docs * clarify model outputs * Update torch_policy_graph.py * fix obs filter * pass thru worker index * fix * rename * vlad torch comments * fix log action * debug name * fix lstm * remove unused ddpg net * remove conv net * revert lstm * wip * wip * cast * wip * works * fix a3c * works * lstm util test * doc * clean up * update * fix lstm check * move to end * fix sphinx * fix cmd * remove bad doc * envs * vec * doc prep * models * rl * alg * up * clarify * copy * async sa * fix * comments * fix a3c conf * tune lstm * fix reshape * fix * back to 16 * tuned a3c update * update * tuned * optional * merge * wip * fix up * move pg class * rename env * wip * update * tip * alg * readme * fix catalog * readme * doc * context * remove prep * comma * add env * link to paper * paper * update * rnn * update * wip * clean up ev creation * fix * fix * fix * fix lint * up * no comma * ma * Update run_multi_node_tests.sh * fix * sphinx is stupid * sphinx is stupid * clarify torch graph * no horizon * fix config * sb * Update test_optimizers.py
64 lines
1.9 KiB
Python
64 lines
1.9 KiB
Python
from __future__ import absolute_import
|
|
from __future__ import division
|
|
from __future__ import print_function
|
|
|
|
import pickle
|
|
from six.moves import queue
|
|
|
|
import ray
|
|
from ray.rllib.agents.bc.experience_dataset import ExperienceDataset
|
|
from ray.rllib.agents.bc.policy import BCPolicy
|
|
from ray.rllib.evaluation.interface import PolicyEvaluator
|
|
from ray.rllib.models import ModelCatalog
|
|
|
|
|
|
class BCEvaluator(PolicyEvaluator):
|
|
def __init__(self, env_creator, config, logdir):
|
|
env = ModelCatalog.get_preprocessor_as_wrapper(env_creator(
|
|
config["env_config"]), config["model"])
|
|
self.dataset = ExperienceDataset(config["dataset_path"])
|
|
self.policy = BCPolicy(env.observation_space, env.action_space, config)
|
|
self.config = config
|
|
self.logdir = logdir
|
|
self.metrics_queue = queue.Queue()
|
|
|
|
def sample(self):
|
|
return self.dataset.sample(self.config["batch_size"])
|
|
|
|
def compute_gradients(self, samples):
|
|
gradient, info = self.policy.compute_gradients(samples)
|
|
self.metrics_queue.put(
|
|
{"num_samples": info["num_samples"], "loss": info["loss"]})
|
|
return gradient, {}
|
|
|
|
def apply_gradients(self, grads):
|
|
self.policy.apply_gradients(grads)
|
|
|
|
def get_weights(self):
|
|
return self.policy.get_weights()
|
|
|
|
def set_weights(self, params):
|
|
self.policy.set_weights(params)
|
|
|
|
def save(self):
|
|
weights = self.get_weights()
|
|
return pickle.dumps({
|
|
"weights": weights})
|
|
|
|
def restore(self, objs):
|
|
objs = pickle.loads(objs)
|
|
self.set_weights(objs["weights"])
|
|
|
|
def get_metrics(self):
|
|
completed = []
|
|
while True:
|
|
try:
|
|
completed.append(self.metrics_queue.get_nowait())
|
|
except queue.Empty:
|
|
break
|
|
return completed
|
|
|
|
|
|
RemoteBCEvaluator = ray.remote(BCEvaluator)
|
|
GPURemoteBCEvaluator = ray.remote(num_gpus=1)(BCEvaluator)
|