Hello everyone
I am tryting to train a PPO trainer on a multi-agent environment.
I am new to RLlib and I tried to define the environment like the MultiAgentArena example.
This is my config:
policies= {
"policy_" + str(i): (None , game.observation_space , game.action_space["agent_" + str(i)] , {}) for i in range(0,game.num_agents)
}
def policy_mapping_fn (agent_id: str):
#assert agent_id in [str(i) for i in range(0,5)], f"ERROR: invalid agent id {agent_id}!!!"
return "policy_" + str(agent_id[len(agent_id)-1])
config={
"env": MultiUnitAuction, # "my_env" <- if we previously have registered the env with `tune.register_env("[name]", lambda config: [returns env object])`.
"create_env_on_driver": True,
"multiagent": {
"policies": policies,
"policy_mapping_fn": policy_mapping_fn,
},
}
But I constantly recieve the following error:
RayTaskError(AttributeError) Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_17784\1339345677.py in <module>
----> 1 results = rllib_trainer.train()
2
3 # Delete the config from the results for clarity.
4 # Only the stats will remain, then.
5 del results["config"]
~\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\tune\trainable.py in train(self)
312 """
313 start = time.time()
--> 314 result = self.step()
315 assert isinstance(result, dict), "step() needs to return a dict."
316
~\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\rllib\agents\trainer.py in step(self)
878 "continue training without the failed worker, set "
879 "`'ignore_worker_failures': True`.")
--> 880 raise e
881 # Any other exception.
882 except Exception as e:
~\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\rllib\agents\trainer.py in step(self)
865 # Try to train one step.
866 try:
--> 867 result = self.step_attempt()
868 # @ray.remote RolloutWorker failure -> Try to recover,
869 # if necessary.
~\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\rllib\agents\trainer.py in step_attempt(self)
918 # No evaluation necessary, just run the next training iteration.
919 if not evaluate_this_iter:
--> 920 step_results = next(self.train_exec_impl)
921 # We have to evaluate in this training iteration.
922 else:
~\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\util\iter.py in __next__(self)
754 def __next__(self):
755 self._build_once()
--> 756 return next(self.built_iterator)
757
758 def __str__(self):
~\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\util\iter.py in apply_foreach(it)
781
782 def apply_foreach(it):
--> 783 for item in it:
784 if isinstance(item, _NextValueNotReady):
785 yield item
~\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\util\iter.py in apply_foreach(it)
781
782 def apply_foreach(it):
--> 783 for item in it:
784 if isinstance(item, _NextValueNotReady):
785 yield item
~\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\util\iter.py in apply_filter(it)
841 def filter(self, fn: Callable[[T], bool]) -> "LocalIterator[T]":
842 def apply_filter(it):
--> 843 for item in it:
844 with self._metrics_context():
845 if isinstance(item, _NextValueNotReady) or fn(item):
~\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\util\iter.py in apply_filter(it)
841 def filter(self, fn: Callable[[T], bool]) -> "LocalIterator[T]":
842 def apply_filter(it):
--> 843 for item in it:
844 with self._metrics_context():
845 if isinstance(item, _NextValueNotReady) or fn(item):
~\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\util\iter.py in apply_foreach(it)
781
782 def apply_foreach(it):
--> 783 for item in it:
784 if isinstance(item, _NextValueNotReady):
785 yield item
~\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\util\iter.py in apply_foreach(it)
781
782 def apply_foreach(it):
--> 783 for item in it:
784 if isinstance(item, _NextValueNotReady):
785 yield item
~\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\util\iter.py in apply_foreach(it)
781
782 def apply_foreach(it):
--> 783 for item in it:
784 if isinstance(item, _NextValueNotReady):
785 yield item
~\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\util\iter.py in apply_foreach(it)
781
782 def apply_foreach(it):
--> 783 for item in it:
784 if isinstance(item, _NextValueNotReady):
785 yield item
~\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\util\iter.py in apply_flatten(it)
874 def flatten(self) -> "LocalIterator[T[0]]":
875 def apply_flatten(it):
--> 876 for item in it:
877 if isinstance(item, _NextValueNotReady):
878 yield item
~\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\util\iter.py in apply_foreach(it)
781
782 def apply_foreach(it):
--> 783 for item in it:
784 if isinstance(item, _NextValueNotReady):
785 yield item
~\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\util\iter.py in apply_foreach(it)
781
782 def apply_foreach(it):
--> 783 for item in it:
784 if isinstance(item, _NextValueNotReady):
785 yield item
~\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\util\iter.py in apply_foreach(it)
781
782 def apply_foreach(it):
--> 783 for item in it:
784 if isinstance(item, _NextValueNotReady):
785 yield item
~\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\util\iter.py in apply_foreach(it)
781
782 def apply_foreach(it):
--> 783 for item in it:
784 if isinstance(item, _NextValueNotReady):
785 yield item
~\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\util\iter.py in base_iterator(timeout)
469 while active:
470 try:
--> 471 yield ray.get(futures, timeout=timeout)
472 futures = [a.par_iter_next.remote() for a in active]
473 # Always yield after each round of gets with timeout.
~\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\_private\client_mode_hook.py in wrapper(*args, **kwargs)
103 if func.__name__ != "init" or is_client_mode_enabled_by_default:
104 return getattr(ray, func.__name__)(*args, **kwargs)
--> 105 return func(*args, **kwargs)
106
107 return wrapper
~\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\worker.py in get(object_refs, timeout)
1711 worker.core_worker.dump_object_store_memory_usage()
1712 if isinstance(value, RayTaskError):
-> 1713 raise value.as_instanceof_cause()
1714 else:
1715 raise value
RayTaskError(AttributeError): ray::RolloutWorker.par_iter_next() (pid=16836, ip=127.0.0.1, repr=<ray.rllib.evaluation.rollout_worker.RolloutWorker object at 0x000001CB6E90FCD0>)
File "python\ray\_raylet.pyx", line 625, in ray._raylet.execute_task
File "python\ray\_raylet.pyx", line 629, in ray._raylet.execute_task
File "python\ray\_raylet.pyx", line 578, in ray._raylet.execute_task.function_executor
File "C:\Users\mohazaa1\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\_private\function_manager.py", line 609, in actor_method_executor
return method(__ray_actor, *args, **kwargs)
File "C:\Users\mohazaa1\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\util\tracing\tracing_helper.py", line 451, in _resume_span
return method(self, *_args, **_kwargs)
File "C:\Users\mohazaa1\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\util\iter.py", line 1151, in par_iter_next
return next(self.local_it)
File "C:\Users\mohazaa1\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\rllib\evaluation\rollout_worker.py", line 381, in gen_rollouts
yield self.sample()
File "C:\Users\mohazaa1\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\util\tracing\tracing_helper.py", line 451, in _resume_span
return method(self, *_args, **_kwargs)
File "C:\Users\mohazaa1\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\rllib\evaluation\rollout_worker.py", line 757, in sample
batches = [self.input_reader.next()]
File "C:\Users\mohazaa1\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\rllib\evaluation\sampler.py", line 103, in next
batches = [self.get_data()]
File "C:\Users\mohazaa1\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\rllib\evaluation\sampler.py", line 265, in get_data
item = next(self._env_runner)
File "C:\Users\mohazaa1\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\rllib\evaluation\sampler.py", line 633, in _env_runner
_process_observations(
File "C:\Users\mohazaa1\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\rllib\evaluation\sampler.py", line 848, in _process_observations
prep_obs = preprocessor.transform(raw_obs)
File "C:\Users\mohazaa1\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\rllib\models\preprocessors.py", line 195, in transform
self.check_shape(observation)
File "C:\Users\mohazaa1\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\rllib\models\preprocessors.py", line 67, in check_shape
if not self._obs_space.contains(observation):
File "C:\Users\mohazaa1\AppData\Local\Programs\Python\Python39\lib\site-packages\gym\spaces\box.py", line 144, in contains
x.shape == self.shape and np.all(x >= self.low) and np.all(x <= self.high)
AttributeError: 'int' object has no attribute 'shape'
2022-02-19 12:35:19,509 ERROR worker.py:84 -- Unhandled error (suppress with RAY_IGNORE_UNHANDLED_ERRORS=1): ray::RolloutWorker.par_iter_next() (pid=11860, ip=127.0.0.1, repr=<ray.rllib.evaluation.rollout_worker.RolloutWorker object at 0x0000020A96C31CD0>)
File "python\ray\_raylet.pyx", line 625, in ray._raylet.execute_task
File "python\ray\_raylet.pyx", line 629, in ray._raylet.execute_task
File "python\ray\_raylet.pyx", line 578, in ray._raylet.execute_task.function_executor
File "C:\Users\mohazaa1\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\_private\function_manager.py", line 609, in actor_method_executor
return method(__ray_actor, *args, **kwargs)
File "C:\Users\mohazaa1\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\util\tracing\tracing_helper.py", line 451, in _resume_span
return method(self, *_args, **_kwargs)
File "C:\Users\mohazaa1\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\util\iter.py", line 1151, in par_iter_next
return next(self.local_it)
File "C:\Users\mohazaa1\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\rllib\evaluation\rollout_worker.py", line 381, in gen_rollouts
yield self.sample()
File "C:\Users\mohazaa1\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\util\tracing\tracing_helper.py", line 451, in _resume_span
return method(self, *_args, **_kwargs)
File "C:\Users\mohazaa1\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\rllib\evaluation\rollout_worker.py", line 757, in sample
batches = [self.input_reader.next()]
File "C:\Users\mohazaa1\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\rllib\evaluation\sampler.py", line 103, in next
batches = [self.get_data()]
File "C:\Users\mohazaa1\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\rllib\evaluation\sampler.py", line 265, in get_data
item = next(self._env_runner)
File "C:\Users\mohazaa1\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\rllib\evaluation\sampler.py", line 633, in _env_runner
_process_observations(
File "C:\Users\mohazaa1\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\rllib\evaluation\sampler.py", line 848, in _process_observations
prep_obs = preprocessor.transform(raw_obs)
File "C:\Users\mohazaa1\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\rllib\models\preprocessors.py", line 195, in transform
self.check_shape(observation)
File "C:\Users\mohazaa1\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\rllib\models\preprocessors.py", line 67, in check_shape
if not self._obs_space.contains(observation):
File "C:\Users\mohazaa1\AppData\Local\Programs\Python\Python39\lib\site-packages\gym\spaces\box.py", line 144, in contains
x.shape == self.shape and np.all(x >= self.low) and np.all(x <= self.high)
AttributeError: 'int' object has no attribute 'shape'
I tried to find the similar issues here but It didn’t work.
Has anyone had a similar problem before?
Thanks