https://docs.ray.io/en/latest/rllib/rllib-training.html#rllib-config-evaluation
설명에 앞서서 RLLib evaluation에 사용되는 옵션들 중 테스트 해본 몇가지
- evaluation_config – Typical usage is to pass extra args to evaluation env creator and to disable exploration by computing deterministic actions. IMPORTANT NOTE: Policy gradient algorithms are able to find the optimal policy, even if this is a stochastic one. Setting “explore=False” here will result in the evaluation workers not using this optimal policy!
기본적인 부분, 아무것도 안넣으면 기본 Algorithm 옵션을 복붙한다.
만약 test와 다른 Env 설정을 하고 싶다면
config = config.evaluation(evaluation_config = {"env": eval_env , "env_config":eval_config})
이런식으로 사용가능
여기서 부턴 묶어서 설명
evaluation_interval – Evaluate with every evaluation_interval training iterations. The evaluation stats will be reported under the “evaluation” metric key. Note that for Ape-X metrics are already only reported for the lowest epsilon workers (least random workers). Set to None (or 0) for no evaluation.
evaluation_duration – Duration for which to run evaluation each evaluation_interval. The unit for the duration can be set via evaluation_duration_unit to either “episodes” (default) or “timesteps”. If using multiple evaluation workers (evaluation_num_workers > 1), the load to run will be split amongst these. If the value is “auto”: - For evaluation_parallel_to_training=True: Will run as many episodes/timesteps that fit into the (parallel) training step. - For evaluation_parallel_to_training=False: Error.
evaluation_duration_unit – The unit, with which to count the evaluation duration. Either “episodes” (default) or “timesteps”.
evaluation_num_workers – Number of parallel workers to use for evaluation. Note that this is set to zero by default, which means evaluation will be run in the algorithm process (only if evaluation_interval is not None). If you increase this, it will increase the Ray resource usage of the algorithm since evaluation workers are created separately from rollout workers (used to sample data for training).
Ray가 시작되고 알고리즘을 Build하면
-
evaluation_num_workers = 0 인경우 Driver에 num_envs_per_worker 갯수 만큼 Rollout+Env가 생성된다.
-
evaluation_num_workers > 0 이라면 evaluation_num_workers 갯수 만큼 rollouts 옵션의 num_envs_per_worker 갯수 만큼의 Rollout+Env가 생성된다.
config = AlgorithmConfig()
config = config.rollouts(num_envs_per_worker = 16)
config = config.evaluation(evaluation_num_workers = 8)
# 생각해보니까, 혹시 evaluation_config에서 num_envs_per_worker를 수정하면 Eval Worker마다 생성되는 Env수를 바꿀수 있나? 아직 테스트 안해봄
이라면 Ray에서 8개의 Eval Worker를 생성하고, 각각에 16개의 Env가 로드된다.
아무튼 이렇게 로드가 되고 나면 evaluation_interval 횟수마다 Evaluation이 돌아가게 된다.
evaluation_interval
episode step이 아니라 Algorithm.train()이 Call된 횟수이다.
어디서 설정이 되어 있는진 모르겠는데 tune의 num_agent_steps_trained 와는 다른 값이다.
무턱대고 1e6 (1 mil) 같은 값으로 설정하면 Evaluation이 돌아가는걸 못본다. 개인적으론 10정도가 적당하다고 생각한다.
자 이제 어떻게 Evaluation이 돌아가느냐,
evaluation_duration_unit=”episodes” 로 설정했다면 evaluation_duration 의 숫자만큼 Eval Worker들이 나눠서 돌리게 된다.
config = config.rollouts(num_envs_per_worker = 16)
config = config.evaluation(evaluation_interval= 10,
evaluation_duration = 1,
evaluation_duration_unit = "episodes"
evaluation_parallel_to_training = True,
evaluation_num_workers = 8)
위와 같은 경우엔 10회마다 돌아가고 Eval worker의 순서에 따른 큐가 있는것 같은데
train 10회 -> 큐의 첫번째 Worker의 첫번째 Env에서 Episode 1회 실행 -> train 10회 -> 큐의 다음 순서 Eval Worker 에서 Episode 1회 돌리고 reset
이런 식으로 돌아가게 된다. 즉 한번의 Evaluation에서 한 에피소드의 결과 밖에 얻을수 없다.
결과의 분산도 필요하다면
config = config.rollouts(num_envs_per_worker = 16)
config = config.evaluation(evaluation_interval= 10,
evaluation_duration = 56,
evaluation_duration_unit = "episodes"
evaluation_parallel_to_training = True,
evaluation_num_workers = 8)
이해 하기 쉽도록 56이라는 숫자를 사용했는데, 위의 경우엔
train 10회 -> 8개의 eval_worker가 7개씩 나누어 가지고 한번의 evaluation 마다 56개의 결과를 얻을 수 있다.
num_envs_per_worker = 16 이니까 각 Worker 마다
( 0 1 2 3 4 5 6 ) ( 7 8 9 10 11 12 13 ) ( 14 15 0 1 2 3 4 5 ) ( 6 7 …
이런식으로 돌아가게 되더라
- always_attach_evaluation_results – Make sure the latest available evaluation results are always attached to a step result dict. This may be useful if Tune or some other meta controller needs access to evaluation metrics all the time.
이 옵션 쓰니까 Tensorboard에서 timestamp가 이상하게 찍혀 나옴.
일단은 안쓰는중