From abb1eefdc23f197b7ea7a0e54363a56408a86c61 Mon Sep 17 00:00:00 2001 From: Sven Mika Date: Fri, 11 Dec 2020 22:43:30 +0100 Subject: [PATCH] [RLlib] Issue 12483: Discrete observation space error: "ValueError: ('Observation ({}) outside given space ..." when doing Trainer.compute_action. (#12787) --- rllib/evaluation/worker_set.py | 14 +++++++------- rllib/models/preprocessors.py | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/rllib/evaluation/worker_set.py b/rllib/evaluation/worker_set.py index b6a4131ff..80cf617bb 100644 --- a/rllib/evaluation/worker_set.py +++ b/rllib/evaluation/worker_set.py @@ -74,7 +74,7 @@ class WorkerSet: self.add_workers(num_workers) # If num_workers > 0, get the action_spaces and observation_spaces - # to not be forced to create an Env on the driver. + # to not be forced to create an Env on the local worker. if self._remote_workers: remote_spaces = ray.get(self.remote_workers( )[0].foreach_policy.remote( @@ -263,13 +263,13 @@ class WorkerSet: elif config["input"] == "sampler": input_creator = (lambda ioctx: ioctx.default_sampler_input()) elif isinstance(config["input"], dict): - input_creator = (lambda ioctx: ShuffledInput( - MixedInput(config["input"], ioctx), config[ - "shuffle_buffer_size"])) + input_creator = ( + lambda ioctx: ShuffledInput(MixedInput(config["input"], ioctx), + config["shuffle_buffer_size"])) else: - input_creator = (lambda ioctx: ShuffledInput( - JsonReader(config["input"], ioctx), config[ - "shuffle_buffer_size"])) + input_creator = ( + lambda ioctx: ShuffledInput(JsonReader(config["input"], ioctx), + config["shuffle_buffer_size"])) if isinstance(config["output"], FunctionType): output_creator = config["output"] diff --git a/rllib/models/preprocessors.py b/rllib/models/preprocessors.py index 51a6f5442..c1b7803c4 100644 --- a/rllib/models/preprocessors.py +++ b/rllib/models/preprocessors.py @@ -80,9 +80,9 @@ class Preprocessor: obs_space = gym.spaces.Box(-1., 1., self.shape, dtype=np.float32) # Stash the unwrapped space so that we can unwrap dict and tuple spaces # automatically in model.py - if (isinstance(self, TupleFlatteningPreprocessor) - or isinstance(self, DictFlatteningPreprocessor) - or isinstance(self, RepeatedValuesPreprocessor)): + classes = (DictFlatteningPreprocessor, OneHotPreprocessor, + RepeatedValuesPreprocessor, TupleFlatteningPreprocessor) + if isinstance(self, classes): obs_space.original_space = self._obs_space return obs_space