From 523546de5b6be5f0a4b02dc1fcb778cbb405d49a Mon Sep 17 00:00:00 2001 From: chenxuyi Date: Sun, 29 Sep 2019 11:02:57 +0800 Subject: [PATCH] auto mkdir in multicard finetune --- finetune_launch.py | 12 +++++++++--- pretrain_launch.py | 11 +++++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/finetune_launch.py b/finetune_launch.py index 8c396df..fdcf154 100644 --- a/finetune_launch.py +++ b/finetune_launch.py @@ -137,14 +137,20 @@ def start_procs(args): cmd = [sys.executable, "-u", args.training_script] + args.training_script_args cmds.append(cmd) - + if args.split_log_path: - fn = open("%s/%sjob.log.%d" % (args.split_log_path, args.log_prefix, trainer_id), "a") + logdir = "%s/%sjob.log.%d" % (args.split_log_path, args.log_prefix, trainer_id) + try: + os.mkdir(os.path.dirname(logdir)) + except OSError: + pass + fn = open(logdir, "a") log_fns.append(fn) process = subprocess.Popen(cmd, env=current_env, stdout=fn, stderr=fn) + log.info('subprocess launched, check log at %s' % logdir) else: process = subprocess.Popen(cmd, env=current_env) - log.info('subprocess launched') + log.info('subprocess launched') procs.append(process) try: diff --git a/pretrain_launch.py b/pretrain_launch.py index 94f3403..b3e2ee7 100644 --- a/pretrain_launch.py +++ b/pretrain_launch.py @@ -139,12 +139,19 @@ def start_procs(args): cmds.append(cmd) if args.split_log_path: - fn = open("%s/%sjob.log.%d" % (args.split_log_path, args.log_prefix, trainer_id), "a") + logdir = "%s/%sjob.log.%d" % (args.split_log_path, args.log_prefix, trainer_id) + try: + os.mkdir(os.path.dirname(logdir)) + except OSError: + pass + + fn = open(logdir, "a") log_fns.append(fn) process = subprocess.Popen(cmd, env=current_env, stdout=fn, stderr=fn) + log.info('subprocess launched, check log at %s' % logdir) else: process = subprocess.Popen(cmd, env=current_env) - log.info('subprocess launched') + log.info('subprocess launched') procs.append(process) try: -- GitLab