提交 1f117410 编写于 作者: S Steffy-zxf 提交者: wuzewu

Fix path bug (#261)

* fix path bug

* fix environment variable autodl setting
上级 98e6c96d
...@@ -201,6 +201,7 @@ class BaseTuningStrategy(object): ...@@ -201,6 +201,7 @@ class BaseTuningStrategy(object):
self.feedback(solutions, solution_results) self.feedback(solutions, solution_results)
# remove the tmp.txt which records the eval results for trials # remove the tmp.txt which records the eval results for trials
tmp_file = os.path.join(TMP_HOME, "tmp.txt") tmp_file = os.path.join(TMP_HOME, "tmp.txt")
if os.path.exists(tmp_file):
os.remove(tmp_file) os.remove(tmp_file)
return solutions_modeldirs return solutions_modeldirs
......
...@@ -21,6 +21,7 @@ import hashlib ...@@ -21,6 +21,7 @@ import hashlib
import math import math
import os import os
import random import random
import string
import six import six
import yaml import yaml
...@@ -42,17 +43,12 @@ def report_final_result(result): ...@@ -42,17 +43,12 @@ def report_final_result(result):
# tmp.txt is to record the eval results for trials # tmp.txt is to record the eval results for trials
mkdir(TMP_HOME) mkdir(TMP_HOME)
tmp_file = os.path.join(TMP_HOME, "tmp.txt") tmp_file = os.path.join(TMP_HOME, "tmp.txt")
with open(tmp_file, 'a') as file: with open(tmp_file, 'a') as f:
file.write(trial_id + "\t" + str(float(result)) + "\n") f.write(trial_id + "\t" + str(float(result)) + "\n")
def unique_name(): def unique_name():
seed = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+=-" return ''.join(random.sample(string.ascii_letters + string.digits, 8))
x = []
for idx in range(4):
x.append(random.choice(seed))
rand_str = "".join(x)
return rand_str
class BaseEvaluator(object): class BaseEvaluator(object):
...@@ -146,18 +142,17 @@ class FullTrailEvaluator(BaseEvaluator): ...@@ -146,18 +142,17 @@ class FullTrailEvaluator(BaseEvaluator):
f = open(log_file, "w") f = open(log_file, "w")
f.close() f.close()
# set temp environment variable to record the eval results for trials
rand_str = unique_name()
if is_windows(): if is_windows():
run_cmd = "set FLAGS_eager_delete_tensor_gb=0.0&set CUDA_VISIBLE_DEVICES=%s&python -u %s --saved_params_dir=%s %s %s >%s 2>&1" % \ run_cmd = "set PaddleHub_AutoDL_Trial_ID=%s&set FLAGS_eager_delete_tensor_gb=0.0&set CUDA_VISIBLE_DEVICES=%s&python -u %s --saved_params_dir=%s %s %s >%s 2>&1" % \
(num_cuda, self.finetunee_script, saved_params_dir, param_str, self.options_str, log_file) (rand_str, num_cuda, self.finetunee_script, saved_params_dir, param_str, self.options_str, log_file)
else: else:
run_cmd = "export FLAGS_eager_delete_tensor_gb=0.0; export CUDA_VISIBLE_DEVICES=%s; python -u %s --saved_params_dir=%s %s %s >%s 2>&1" % \ run_cmd = "export PaddleHub_AutoDL_Trial_ID=%s; export FLAGS_eager_delete_tensor_gb=0.0; export CUDA_VISIBLE_DEVICES=%s; python -u %s --saved_params_dir=%s %s %s >%s 2>&1" % \
(num_cuda, self.finetunee_script, saved_params_dir, param_str, self.options_str, log_file) (rand_str, num_cuda, self.finetunee_script, saved_params_dir, param_str, self.options_str, log_file)
try: try:
# set temp environment variable to record the eval results for trials
rand_str = unique_name()
os.environ['PaddleHub_AutoDL_Trial_ID'] = rand_str
os.system(run_cmd) os.system(run_cmd)
eval_result = [] eval_result = []
...@@ -172,7 +167,7 @@ class FullTrailEvaluator(BaseEvaluator): ...@@ -172,7 +167,7 @@ class FullTrailEvaluator(BaseEvaluator):
"WARNING: Program which was ran with hyperparameters as %s was crashed!" "WARNING: Program which was ran with hyperparameters as %s was crashed!"
% param_str.replace("--", "")) % param_str.replace("--", ""))
eval_result = 0.0 eval_result = 0.0
except: except Exception as e:
print( print(
"WARNING: Program which was ran with hyperparameters as %s was crashed!" "WARNING: Program which was ran with hyperparameters as %s was crashed!"
% param_str.replace("--", "")) % param_str.replace("--", ""))
...@@ -203,37 +198,36 @@ class PopulationBasedEvaluator(BaseEvaluator): ...@@ -203,37 +198,36 @@ class PopulationBasedEvaluator(BaseEvaluator):
f = open(log_file, "w") f = open(log_file, "w")
f.close() f.close()
# set temp environment variable to record the eval results for trials
rand_str = unique_name()
if len(self.half_best_model_path) > 0: if len(self.half_best_model_path) > 0:
model_path = self.half_best_model_path[self.run_count % len( model_path = self.half_best_model_path[self.run_count % len(
self.half_best_model_path)] self.half_best_model_path)]
if is_windows(): if is_windows():
run_cmd = "set FLAGS_eager_delete_tensor_gb=0.0&set CUDA_VISIBLE_DEVICES=%s&python -u %s --epochs=1 --model_path %s --saved_params_dir=%s %s %s >%s 2>&1" % \ run_cmd = "set PaddleHub_AutoDL_Trial_ID=%s&set FLAGS_eager_delete_tensor_gb=0.0&set CUDA_VISIBLE_DEVICES=%s&python -u %s --epochs=1 --model_path %s --saved_params_dir=%s %s %s >%s 2>&1" % \
(num_cuda, self.finetunee_script, model_path, saved_params_dir, param_str, self.options_str, log_file) (rand_str, num_cuda, self.finetunee_script, model_path, saved_params_dir, param_str, self.options_str, log_file)
else: else:
run_cmd = "export FLAGS_eager_delete_tensor_gb=0.0; export CUDA_VISIBLE_DEVICES=%s; python -u %s --epochs=1 --model_path %s --saved_params_dir=%s %s %s >%s 2>&1" % \ run_cmd = "export PaddleHub_AutoDL_Trial_ID=%s; export FLAGS_eager_delete_tensor_gb=0.0; export CUDA_VISIBLE_DEVICES=%s; python -u %s --epochs=1 --model_path %s --saved_params_dir=%s %s %s >%s 2>&1" % \
(num_cuda, self.finetunee_script, model_path, saved_params_dir, param_str, self.options_str, log_file) (rand_str, num_cuda, self.finetunee_script, model_path, saved_params_dir, param_str, self.options_str, log_file)
else: else:
if is_windows(): if is_windows():
run_cmd = "set FLAGS_eager_delete_tensor_gb=0.0&set CUDA_VISIBLE_DEVICES=%s&python -u %s --saved_params_dir=%s %s %s >%s 2>&1" % \ run_cmd = "set PaddleHub_AutoDL_Trial_ID=%s&set FLAGS_eager_delete_tensor_gb=0.0&set CUDA_VISIBLE_DEVICES=%s&python -u %s --saved_params_dir=%s %s %s >%s 2>&1" % \
(num_cuda, self.finetunee_script, saved_params_dir, param_str, self.options_str, log_file) (rand_str, num_cuda, self.finetunee_script, saved_params_dir, param_str, self.options_str, log_file)
else: else:
run_cmd = "export FLAGS_eager_delete_tensor_gb=0.0; export CUDA_VISIBLE_DEVICES=%s; python -u %s --saved_params_dir=%s %s %s >%s 2>&1" % \ run_cmd = "export PaddleHub_AutoDL_Trial_ID=%s; export FLAGS_eager_delete_tensor_gb=0.0; export CUDA_VISIBLE_DEVICES=%s; python -u %s --saved_params_dir=%s %s %s >%s 2>&1" % \
(num_cuda, self.finetunee_script, saved_params_dir, param_str, self.options_str, log_file) (rand_str, num_cuda, self.finetunee_script, saved_params_dir, param_str, self.options_str, log_file)
self.run_count += 1 self.run_count += 1
try: try:
# set temp environment variable to record the eval results for trials
rand_str = unique_name()
os.environ['PaddleHub_AutoDL_Trial_ID'] = rand_str
os.system(run_cmd) os.system(run_cmd)
eval_result = [] eval_result = []
tmp_file = os.join.path(TMP_HOME, 'tmp.txt') tmp_file = os.path.join(TMP_HOME, 'tmp.txt')
with open(tmp_file, 'r') as file: with open(tmp_file, 'r') as f:
for line in file: for line in f:
data = line.strip().split("\t") data = line.strip().split("\t")
if rand_str == data[0]: if rand_str == data[0]:
eval_result = float(data[1]) eval_result = float(data[1])
...@@ -242,7 +236,8 @@ class PopulationBasedEvaluator(BaseEvaluator): ...@@ -242,7 +236,8 @@ class PopulationBasedEvaluator(BaseEvaluator):
"WARNING: Program which was ran with hyperparameters as %s was crashed!" "WARNING: Program which was ran with hyperparameters as %s was crashed!"
% param_str.replace("--", "")) % param_str.replace("--", ""))
eval_result = 0.0 eval_result = 0.0
except: except Exception as e:
print(e)
print( print(
"WARNING: Program which was ran with hyperparameters as %s was crashed!" "WARNING: Program which was ran with hyperparameters as %s was crashed!"
% param_str.replace("--", "")) % param_str.replace("--", ""))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册