22import logging
33import argparse
44
5- from multiprocessing import Process , Queue
65import os
76import glob
87import shutil
1413import mlagents_envs
1514from mlagents import tf_utils
1615from mlagents .trainers .trainer_controller import TrainerController
17- from mlagents .trainers .exception import TrainerError
1816from mlagents .trainers .meta_curriculum import MetaCurriculum
1917from mlagents .trainers .trainer_util import load_config , TrainerFactory
2018from mlagents .trainers .stats import TensorboardWriter , CSVWriter , StatsReporter
2927
3028class CommandLineOptions (NamedTuple ):
3129 debug : bool
32- num_runs : int
3330 seed : int
3431 env_path : str
3532 run_id : str
@@ -109,9 +106,6 @@ def parse_command_line(argv: Optional[List[str]] = None) -> CommandLineOptions:
109106 default = "ppo" ,
110107 help = "The directory name for model and summary statistics" ,
111108 )
112- parser .add_argument (
113- "--num-runs" , default = 1 , type = int , help = "Number of concurrent training sessions"
114- )
115109 parser .add_argument (
116110 "--save-freq" , default = 50000 , type = int , help = "Frequency at which to save model"
117111 )
@@ -209,13 +203,9 @@ def parse_command_line(argv: Optional[List[str]] = None) -> CommandLineOptions:
209203 return CommandLineOptions .from_argparse (args )
210204
211205
212- def run_training (
213- sub_id : int , run_seed : int , options : CommandLineOptions , process_queue : Queue
214- ) -> None :
206+ def run_training (run_seed : int , options : CommandLineOptions ) -> None :
215207 """
216208 Launches training session.
217- :param process_queue: Queue used to send signal back to main.
218- :param sub_id: Unique id for training session.
219209 :param options: parsed command line arguments
220210 :param run_seed: Random seed used for training.
221211 :param run_options: Command line arguments for training.
@@ -225,30 +215,16 @@ def run_training(
225215 curriculum_folder = options .curriculum_folder
226216 # Recognize and use docker volume if one is passed as an argument
227217 if not options .docker_target_name :
228- model_path = "./models/{run_id}-{sub_id}" .format (
229- run_id = options .run_id , sub_id = sub_id
230- )
218+ model_path = f"./models/{ options .run_id } "
231219 summaries_dir = "./summaries"
232220 else :
233- trainer_config_path = "/{docker_target_name}/{trainer_config_path}" .format (
234- docker_target_name = options .docker_target_name ,
235- trainer_config_path = trainer_config_path ,
236- )
221+ trainer_config_path = f"/{ options .docker_target_name } /{ trainer_config_path } "
237222 if curriculum_folder is not None :
238- curriculum_folder = "/{docker_target_name}/{curriculum_folder}" .format (
239- docker_target_name = options .docker_target_name ,
240- curriculum_folder = curriculum_folder ,
241- )
242- model_path = "/{docker_target_name}/models/{run_id}-{sub_id}" .format (
243- docker_target_name = options .docker_target_name ,
244- run_id = options .run_id ,
245- sub_id = sub_id ,
246- )
247- summaries_dir = "/{docker_target_name}/summaries" .format (
248- docker_target_name = options .docker_target_name
249- )
223+ curriculum_folder = f"/{ options .docker_target_name } /{ curriculum_folder } "
224+ model_path = f"/{ options .docker_target_name } /models/{ options .run_id } "
225+ summaries_dir = f"/{ options .docker_target_name } /summaries"
250226 trainer_config = load_config (trainer_config_path )
251- port = options .base_port + ( sub_id * options . num_envs )
227+ port = options .base_port
252228
253229 # Configure CSV, Tensorboard Writers and StatsReporter
254230 # We assume reward and episode length are needed in the CSV.
@@ -301,16 +277,14 @@ def run_training(
301277 trainer_factory ,
302278 model_path ,
303279 summaries_dir ,
304- options .run_id + "-" + str ( sub_id ) ,
280+ options .run_id ,
305281 options .save_freq ,
306282 maybe_meta_curriculum ,
307283 options .train_model ,
308284 run_seed ,
309285 sampler_manager ,
310286 resampling_interval ,
311287 )
312- # Signal that environment has been launched.
313- process_queue .put (True )
314288 # Begin training
315289 try :
316290 tc .start_learning (env_manager )
@@ -461,40 +435,14 @@ def main():
461435 else :
462436 # disable noisy warnings from tensorflow.
463437 tf_utils .set_warnings_enabled (False )
464- if options .env_path is None and options .num_runs > 1 :
465- raise TrainerError (
466- "It is not possible to launch more than one concurrent training session "
467- "when training from the editor."
468- )
469438
470- jobs = []
471439 run_seed = options .seed
472440 if options .cpu :
473441 os .environ ["CUDA_VISIBLE_DEVICES" ] = "-1"
474442
475- if options .num_runs == 1 :
476- if options .seed == - 1 :
477- run_seed = np .random .randint (0 , 10000 )
478- run_training (0 , run_seed , options , Queue ())
479- else :
480- for i in range (options .num_runs ):
481- if options .seed == - 1 :
482- run_seed = np .random .randint (0 , 10000 )
483- process_queue = Queue ()
484- p = Process (target = run_training , args = (i , run_seed , options , process_queue ))
485- jobs .append (p )
486- p .start ()
487- # Wait for signal that environment has successfully launched
488- while process_queue .get () is not True :
489- continue
490-
491- # Wait for jobs to complete. Otherwise we'll have an extra
492- # unhandled KeyboardInterrupt if we end early.
493- try :
494- for job in jobs :
495- job .join ()
496- except KeyboardInterrupt :
497- pass
443+ if options .seed == - 1 :
444+ run_seed = np .random .randint (0 , 10000 )
445+ run_training (run_seed , options )
498446
499447
500448# For python debugger to directly run this script
0 commit comments