尝试执行 PPOConfig 时出现 RolloutWorker 问题:创建任务中引发的异常:参与者因其创建任务中引发的错误而死亡

问题描述 投票:0回答:1

我正在尝试按照“RLlib 入门”(https://docs.ray.io/en/latest/rllib/rllib-training.html) 中提到的步骤以及我的自定义环境进行操作。

但是我的运行在指南中的第一个代码块显示中不起作用。 这实际上是我要运行的脚本:

import ray
from ray.rllib.algorithms.ppo import PPOConfig
from ray.tune.logger import pretty_print
from gym_sw_env.envs.Examplev2 import Example_v2 #this is my custom env

ray.init(ignore_reinit_error=True)

algo = (
    PPOConfig()
    .rollouts(num_rollout_workers=1)
    .resources(num_gpus=0)
    .environment(env=Example_v2)
    .build()   
)

虽然这是我的错误:

(RolloutWorker pid=24420) 2022-12-17 11:36:34,235   ERROR worker.py:763 -- Exception raised in creation task: The actor died because of an error raised in its creation task, ray::RolloutWorker.__init__() (pid=24420, ip=127.0.0.1, repr=<ray.rllib.evaluation.rollout_worker.RolloutWorker object at 0x000001693BEB1C10>)
(RolloutWorker pid=24420)   File "python\ray\_raylet.pyx", line 859, in ray._raylet.execute_task
(RolloutWorker pid=24420)   File "python\ray\_raylet.pyx", line 863, in ray._raylet.execute_task
(RolloutWorker pid=24420)   File "python\ray\_raylet.pyx", line 810, in ray._raylet.execute_task.function_executor
(RolloutWorker pid=24420)   File "C:\Users\**MYUSER**\Anaconda3\lib\site-packages\ray\_private\function_manager.py", line 674, in actor_method_executor
(RolloutWorker pid=24420)     return method(__ray_actor, *args, **kwargs)
(RolloutWorker pid=24420)   File "C:\Users\**MYUSER**\Anaconda3\lib\site-packages\ray\util\tracing\tracing_helper.py", line 466, in _resume_span
(RolloutWorker pid=24420)     return method(self, *_args, **_kwargs)
(RolloutWorker pid=24420)   File "C:\Users\**MYUSER**\Anaconda3\lib\site-packages\ray\rllib\evaluation\rollout_worker.py", line 492, in __init__
(RolloutWorker pid=24420)     self.env = env_creator(copy.deepcopy(self.env_context))
(RolloutWorker pid=24420)   File "C:\Users\**MYUSER**\Anaconda3\lib\site-packages\ray\rllib\algorithms\algorithm.py", line 2139, in <lambda>
(RolloutWorker pid=24420)     return env_id, lambda cfg: env_specifier(cfg)
(RolloutWorker pid=24420) TypeError: __init__() takes 1 positional argument but 2 were given
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In [3], line 7
      2 from ray.tune.logger import pretty_print
      3 from gym_sw_env.envs.Examplev2 import Example_v2
      6 algo = (
----> 7     PPOConfig()
      8     .rollouts(num_rollout_workers=1)
      9     .resources(num_gpus=0)
     10     .environment(env=Example_v2)
     11     .build() 
     12 )

File ~\Anaconda3\lib\site-packages\ray\rllib\algorithms\algorithm_config.py:311, in AlgorithmConfig.build(self, env, logger_creator)
    308 if logger_creator is not None:
    309     self.logger_creator = logger_creator
--> 311 return self.algo_class(
    312     config=self.to_dict(),
    313     env=self.env,
    314     logger_creator=self.logger_creator,
    315 )

File ~\Anaconda3\lib\site-packages\ray\rllib\algorithms\algorithm.py:414, in Algorithm.__init__(self, config, env, logger_creator, **kwargs)
    402 # Initialize common evaluation_metrics to nan, before they become
    403 # available. We want to make sure the metrics are always present
    404 # (although their values may be nan), so that Tune does not complain
    405 # when we use these as stopping criteria.
    406 self.evaluation_metrics = {
    407     "evaluation": {
    408         "episode_reward_max": np.nan,
   (...)
    411     }
    412 }
--> 414 super().__init__(config=config, logger_creator=logger_creator, **kwargs)
    416 # Check, whether `training_iteration` is still a tune.Trainable property
    417 # and has not been overridden by the user in the attempt to implement the
    418 # algos logic (this should be done now inside `training_step`).
    419 try:

File ~\Anaconda3\lib\site-packages\ray\tune\trainable\trainable.py:161, in Trainable.__init__(self, config, logger_creator, remote_checkpoint_dir, custom_syncer, sync_timeout)
    159 start_time = time.time()
    160 self._local_ip = ray.util.get_node_ip_address()
--> 161 self.setup(copy.deepcopy(self.config))
    162 setup_time = time.time() - start_time
    163 if setup_time > SETUP_TIME_THRESHOLD:

File ~\Anaconda3\lib\site-packages\ray\rllib\algorithms\algorithm.py:549, in Algorithm.setup(self, config)
    536 except RayActorError as e:
    537     # In case of an actor (remote worker) init failure, the remote worker
    538     # may still exist and will be accessible, however, e.g. calling
    539     # its `sample.remote()` would result in strange "property not found"
    540     # errors.
    541     if e.actor_init_failed:
    542         # Raise the original error here that the RolloutWorker raised
    543         # during its construction process. This is to enforce transparency
   (...)
    547         # - e.args[0].args[2]: The original Exception (e.g. a ValueError due
    548         # to a config mismatch) thrown inside the actor.
--> 549         raise e.args[0].args[2]
    550     # In any other case, raise the RayActorError as-is.
    551     else:
    552         raise e

File python\ray\_raylet.pyx:852, in ray._raylet.execute_task()

File python\ray\_raylet.pyx:906, in ray._raylet.execute_task()

File python\ray\_raylet.pyx:859, in ray._raylet.execute_task()

File python\ray\_raylet.pyx:863, in ray._raylet.execute_task()

File python\ray\_raylet.pyx:810, in ray._raylet.execute_task.function_executor()

File ~\Anaconda3\lib\site-packages\ray\_private\function_manager.py:674, in actor_method_executor()
    672     return method(*args, **kwargs)
    673 else:
--> 674     return method(__ray_actor, *args, **kwargs)

File ~\Anaconda3\lib\site-packages\ray\util\tracing\tracing_helper.py:466, in _resume_span()
    464 # If tracing feature flag is not on, perform a no-op
    465 if not _is_tracing_enabled() or _ray_trace_ctx is None:
--> 466     return method(self, *_args, **_kwargs)
    468 tracer: _opentelemetry.trace.Tracer = _opentelemetry.trace.get_tracer(
    469     __name__
    470 )
    472 # Retrieves the context from the _ray_trace_ctx dictionary we
    473 # injected.

File ~\Anaconda3\lib\site-packages\ray\rllib\evaluation\rollout_worker.py:492, in __init__()
    485 # Create a (single) env for this worker.
    486 if not (
    487     worker_index == 0
    488     and num_workers > 0
    489     and not policy_config.get("create_env_on_driver")
    490 ):
    491     # Run the `env_creator` function passing the EnvContext.
--> 492     self.env = env_creator(copy.deepcopy(self.env_context))
    494 if self.env is not None:
    495     # Validate environment (general validation function).
    496     if not self._disable_env_checking:

File ~\Anaconda3\lib\site-packages\ray\rllib\algorithms\algorithm.py:2139, in Algorithm._get_env_id_and_creator.<locals>.<lambda>()
   2137         return env_id, lambda cfg: _wrapper.remote(cfg)
   2138     else:
-> 2139         return env_id, lambda cfg: env_specifier(cfg)
   2141 # No env -> Env creator always returns None.
   2142 elif env_specifier is None:

TypeError: __init__() takes 1 positional argument but 2 were given

有人知道怎么解决吗?我只是按照指南的第一步。

我只是尝试删除 PPOConfigure 的 build() 方法,所以我有:

algo = (
    PPOConfig()
    .rollouts(num_rollout_workers=1)
    .resources(num_gpus=0)
    .environment(env=Example_v2)
)

这不会产生任何错误。所以问题也可能是:build() 方法是否必要?

我正在尝试搜索类似这样的其他错误,但什么也没找到。

python reinforcement-learning openai-gym ray rllib
1个回答
-2
投票

你找到解决办法了吗?我也在为同样的事情而苦苦挣扎!

是否有与 .build() 不同的方法?我一直在用它出错。

(无法添加评论,所以不得不将其作为答案发布 - 对此非常陌生)

© www.soinside.com 2019 - 2024. All rights reserved.