mirror of
https://github.com/wassname/ray.git
synced 2026-07-16 11:21:10 +08:00
Enforce quoting style in Travis. (#4589)
This commit is contained in:
committed by
Robert Nishihara
parent
6697407ec4
commit
e88e706fcc
@@ -84,11 +84,11 @@ class AutoMLSearcher(SearchAlgorithm):
|
||||
|
||||
for exp in self.experiment_list:
|
||||
for param_config, extra_arg in zip(raw_param_list, extra_arg_list):
|
||||
tag = ''
|
||||
tag = ""
|
||||
new_spec = copy.deepcopy(exp.spec)
|
||||
for path, value in param_config.items():
|
||||
tag += '%s=%s-' % (path.split('.')[-1], value)
|
||||
deep_insert(path.split('.'), value, new_spec['config'])
|
||||
tag += "%s=%s-" % (path.split(".")[-1], value)
|
||||
deep_insert(path.split("."), value, new_spec["config"])
|
||||
|
||||
trial = create_trial_from_spec(
|
||||
new_spec, exp.name, self._parser, experiment_tag=tag)
|
||||
|
||||
@@ -67,7 +67,7 @@ class ContinuousSpace(ParameterSpace):
|
||||
certain distribution such as linear.
|
||||
"""
|
||||
|
||||
LINEAR = 'linear'
|
||||
LINEAR = "linear"
|
||||
|
||||
# TODO: logspace
|
||||
|
||||
|
||||
@@ -63,9 +63,9 @@ class CollectorService(object):
|
||||
"""Initialize logger settings."""
|
||||
logger = logging.getLogger("AutoMLBoard")
|
||||
handler = logging.StreamHandler()
|
||||
formatter = logging.Formatter('[%(levelname)s %(asctime)s] '
|
||||
'%(filename)s: %(lineno)d '
|
||||
'%(message)s')
|
||||
formatter = logging.Formatter("[%(levelname)s %(asctime)s] "
|
||||
"%(filename)s: %(lineno)d "
|
||||
"%(message)s")
|
||||
handler.setFormatter(formatter)
|
||||
logger.setLevel(log_level)
|
||||
logger.addHandler(handler)
|
||||
@@ -294,7 +294,7 @@ class Collector(Thread):
|
||||
meta = parse_json(meta_file)
|
||||
|
||||
if not meta:
|
||||
job_name = job_dir.split('/')[-1]
|
||||
job_name = job_dir.split("/")[-1]
|
||||
user = os.environ.get("USER", None)
|
||||
meta = {
|
||||
"job_id": job_name,
|
||||
@@ -325,7 +325,7 @@ class Collector(Thread):
|
||||
meta = parse_json(meta_file)
|
||||
|
||||
if not meta:
|
||||
job_id = expr_dir.split('/')[-2]
|
||||
job_id = expr_dir.split("/")[-2]
|
||||
trial_id = expr_dir[-8:]
|
||||
params = parse_json(os.path.join(expr_dir, EXPR_PARARM_FILE))
|
||||
meta = {
|
||||
|
||||
@@ -19,9 +19,9 @@ def dump_json(json_info, json_file, overwrite=True):
|
||||
overwrite(boolean)
|
||||
"""
|
||||
if overwrite:
|
||||
mode = 'w'
|
||||
mode = "w"
|
||||
else:
|
||||
mode = 'w+'
|
||||
mode = "w+"
|
||||
|
||||
try:
|
||||
with open(json_file, mode) as f:
|
||||
@@ -45,7 +45,7 @@ def parse_json(json_file):
|
||||
return None
|
||||
|
||||
try:
|
||||
with open(json_file, 'r') as f:
|
||||
with open(json_file, "r") as f:
|
||||
info_str = f.readlines()
|
||||
info_str = "".join(info_str)
|
||||
json_info = json.loads(info_str)
|
||||
@@ -76,11 +76,11 @@ def parse_multiple_json(json_file, offset=None):
|
||||
return json_info_list
|
||||
|
||||
try:
|
||||
with open(json_file, 'r') as f:
|
||||
with open(json_file, "r") as f:
|
||||
if offset:
|
||||
f.seek(offset)
|
||||
for line in f:
|
||||
if line[-1] != '\n':
|
||||
if line[-1] != "\n":
|
||||
# Incomplete line
|
||||
break
|
||||
json_info = json.loads(line)
|
||||
@@ -94,7 +94,7 @@ def parse_multiple_json(json_file, offset=None):
|
||||
|
||||
def timestamp2date(timestamp):
|
||||
"""Convert a timestamp to date."""
|
||||
return time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(timestamp))
|
||||
return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(timestamp))
|
||||
|
||||
|
||||
def unicode2str(content):
|
||||
@@ -109,4 +109,4 @@ def unicode2str(content):
|
||||
elif isinstance(content, int) or isinstance(content, float):
|
||||
return content
|
||||
else:
|
||||
return content.encode('utf-8')
|
||||
return content.encode("utf-8")
|
||||
|
||||
@@ -36,7 +36,7 @@ def query_job(request):
|
||||
"success_trials": 4
|
||||
}
|
||||
"""
|
||||
job_id = request.GET.get('job_id')
|
||||
job_id = request.GET.get("job_id")
|
||||
jobs = JobRecord.objects.filter(job_id=job_id)
|
||||
trials = TrialRecord.objects.filter(job_id=job_id)
|
||||
|
||||
@@ -68,7 +68,7 @@ def query_job(request):
|
||||
"progress": progress
|
||||
}
|
||||
resp = json.dumps(result)
|
||||
return HttpResponse(resp, content_type='application/json;charset=utf-8')
|
||||
return HttpResponse(resp, content_type="application/json;charset=utf-8")
|
||||
|
||||
|
||||
def query_trial(request):
|
||||
@@ -90,10 +90,10 @@ def query_trial(request):
|
||||
"trial_id": "2067R2ZD",
|
||||
}
|
||||
"""
|
||||
trial_id = request.GET.get('trial_id')
|
||||
trial_id = request.GET.get("trial_id")
|
||||
trials = TrialRecord.objects \
|
||||
.filter(trial_id=trial_id) \
|
||||
.order_by('-start_time')
|
||||
.order_by("-start_time")
|
||||
if len(trials) == 0:
|
||||
resp = "Unkonwn trial id %s.\n" % trials
|
||||
else:
|
||||
@@ -107,4 +107,4 @@ def query_trial(request):
|
||||
"params": trial.params
|
||||
}
|
||||
resp = json.dumps(result)
|
||||
return HttpResponse(resp, content_type='application/json;charset=utf-8')
|
||||
return HttpResponse(resp, content_type="application/json;charset=utf-8")
|
||||
|
||||
@@ -29,10 +29,10 @@ import ray.tune.automlboard.frontend.view as view
|
||||
import ray.tune.automlboard.frontend.query as query
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^admin/', admin.site.urls),
|
||||
url(r'^$', view.index),
|
||||
url(r'^job$', view.job),
|
||||
url(r'^trial$', view.trial),
|
||||
url(r'^query_job', query.query_job),
|
||||
url(r'^query_trial', query.query_trial)
|
||||
url(r"^admin/", admin.site.urls),
|
||||
url(r"^$", view.index),
|
||||
url(r"^job$", view.job),
|
||||
url(r"^trial$", view.trial),
|
||||
url(r"^query_job", query.query_job),
|
||||
url(r"^query_trial", query.query_trial)
|
||||
]
|
||||
|
||||
@@ -16,8 +16,8 @@ import datetime
|
||||
|
||||
def index(request):
|
||||
"""View for the home page."""
|
||||
recent_jobs = JobRecord.objects.order_by('-start_time')[0:100]
|
||||
recent_trials = TrialRecord.objects.order_by('-start_time')[0:500]
|
||||
recent_jobs = JobRecord.objects.order_by("-start_time")[0:100]
|
||||
recent_trials = TrialRecord.objects.order_by("-start_time")[0:500]
|
||||
|
||||
total_num = len(recent_trials)
|
||||
running_num = sum(t.trial_status == Trial.RUNNING for t in recent_trials)
|
||||
@@ -29,31 +29,31 @@ def index(request):
|
||||
for recent_job in recent_jobs:
|
||||
job_records.append(get_job_info(recent_job))
|
||||
context = {
|
||||
'log_dir': AUTOMLBOARD_LOG_DIR,
|
||||
'reload_interval': AUTOMLBOARD_RELOAD_INTERVAL,
|
||||
'recent_jobs': job_records,
|
||||
'job_num': len(job_records),
|
||||
'trial_num': total_num,
|
||||
'running_num': running_num,
|
||||
'success_num': success_num,
|
||||
'failed_num': failed_num
|
||||
"log_dir": AUTOMLBOARD_LOG_DIR,
|
||||
"reload_interval": AUTOMLBOARD_RELOAD_INTERVAL,
|
||||
"recent_jobs": job_records,
|
||||
"job_num": len(job_records),
|
||||
"trial_num": total_num,
|
||||
"running_num": running_num,
|
||||
"success_num": success_num,
|
||||
"failed_num": failed_num
|
||||
}
|
||||
return render(request, 'index.html', context)
|
||||
return render(request, "index.html", context)
|
||||
|
||||
|
||||
def job(request):
|
||||
"""View for a single job."""
|
||||
job_id = request.GET.get('job_id')
|
||||
recent_jobs = JobRecord.objects.order_by('-start_time')[0:100]
|
||||
job_id = request.GET.get("job_id")
|
||||
recent_jobs = JobRecord.objects.order_by("-start_time")[0:100]
|
||||
recent_trials = TrialRecord.objects \
|
||||
.filter(job_id=job_id) \
|
||||
.order_by('-start_time')
|
||||
.order_by("-start_time")
|
||||
trial_records = []
|
||||
for recent_trial in recent_trials:
|
||||
trial_records.append(get_trial_info(recent_trial))
|
||||
current_job = JobRecord.objects \
|
||||
.filter(job_id=job_id) \
|
||||
.order_by('-start_time')[0]
|
||||
.order_by("-start_time")[0]
|
||||
|
||||
if len(trial_records) > 0:
|
||||
param_keys = trial_records[0]["params"].keys()
|
||||
@@ -63,38 +63,38 @@ def job(request):
|
||||
# TODO: support custom metrics here
|
||||
metric_keys = ["episode_reward", "accuracy", "loss"]
|
||||
context = {
|
||||
'current_job': get_job_info(current_job),
|
||||
'recent_jobs': recent_jobs,
|
||||
'recent_trials': trial_records,
|
||||
'param_keys': param_keys,
|
||||
'param_num': len(param_keys),
|
||||
'metric_keys': metric_keys,
|
||||
'metric_num': len(metric_keys)
|
||||
"current_job": get_job_info(current_job),
|
||||
"recent_jobs": recent_jobs,
|
||||
"recent_trials": trial_records,
|
||||
"param_keys": param_keys,
|
||||
"param_num": len(param_keys),
|
||||
"metric_keys": metric_keys,
|
||||
"metric_num": len(metric_keys)
|
||||
}
|
||||
return render(request, 'job.html', context)
|
||||
return render(request, "job.html", context)
|
||||
|
||||
|
||||
def trial(request):
|
||||
"""View for a single trial."""
|
||||
job_id = request.GET.get('job_id')
|
||||
trial_id = request.GET.get('trial_id')
|
||||
job_id = request.GET.get("job_id")
|
||||
trial_id = request.GET.get("trial_id")
|
||||
recent_trials = TrialRecord.objects \
|
||||
.filter(job_id=job_id) \
|
||||
.order_by('-start_time')
|
||||
.order_by("-start_time")
|
||||
recent_results = ResultRecord.objects \
|
||||
.filter(trial_id=trial_id) \
|
||||
.order_by('-date')[0:2000]
|
||||
.order_by("-date")[0:2000]
|
||||
current_trial = TrialRecord.objects \
|
||||
.filter(trial_id=trial_id) \
|
||||
.order_by('-start_time')[0]
|
||||
.order_by("-start_time")[0]
|
||||
context = {
|
||||
'job_id': job_id,
|
||||
'trial_id': trial_id,
|
||||
'current_trial': current_trial,
|
||||
'recent_results': recent_results,
|
||||
'recent_trials': recent_trials
|
||||
"job_id": job_id,
|
||||
"trial_id": trial_id,
|
||||
"current_trial": current_trial,
|
||||
"recent_results": recent_results,
|
||||
"recent_trials": recent_trials
|
||||
}
|
||||
return render(request, 'trial.html', context)
|
||||
return render(request, "trial.html", context)
|
||||
|
||||
|
||||
def get_job_info(current_job):
|
||||
@@ -133,7 +133,7 @@ def get_job_info(current_job):
|
||||
|
||||
def get_trial_info(current_trial):
|
||||
"""Get job information for current trial."""
|
||||
if current_trial.end_time and ('_' in current_trial.end_time):
|
||||
if current_trial.end_time and ("_" in current_trial.end_time):
|
||||
# end time is parsed from result.json and the format
|
||||
# is like: yyyy-mm-dd_hh-MM-ss, which will be converted
|
||||
# to yyyy-mm-dd hh:MM:ss here
|
||||
@@ -170,7 +170,7 @@ def get_winner(trials):
|
||||
first_metrics = get_trial_info(trials[0])["metrics"]
|
||||
if first_metrics and not first_metrics.get("accuracy", None):
|
||||
sort_key = "episode_reward"
|
||||
max_metric = float('-Inf')
|
||||
max_metric = float("-Inf")
|
||||
for t in trials:
|
||||
metrics = get_trial_info(t).get("metrics", None)
|
||||
if metrics and metrics.get(sort_key, None):
|
||||
|
||||
@@ -9,4 +9,4 @@ from django.apps import AppConfig
|
||||
class ModelConfig(AppConfig):
|
||||
"""Model Congig for models."""
|
||||
|
||||
name = 'ray.tune.automlboard.models'
|
||||
name = "ray.tune.automlboard.models"
|
||||
|
||||
@@ -37,8 +37,8 @@ def run_board(args):
|
||||
# frontend service
|
||||
logger.info("Try to start automlboard on port %s\n" % args.port)
|
||||
command = [
|
||||
os.path.join(root_path, 'manage.py'), 'runserver',
|
||||
'0.0.0.0:%s' % args.port, '--noreload'
|
||||
os.path.join(root_path, "manage.py"), "runserver",
|
||||
"0.0.0.0:%s" % args.port, "--noreload"
|
||||
]
|
||||
execute_from_command_line(command)
|
||||
|
||||
@@ -76,7 +76,7 @@ def init_config(args):
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE",
|
||||
"ray.tune.automlboard.settings")
|
||||
django.setup()
|
||||
command = [os.path.join(root_path, 'manage.py'), 'migrate', '--run-syncdb']
|
||||
command = [os.path.join(root_path, "manage.py"), "migrate", "--run-syncdb"]
|
||||
execute_from_command_line(command)
|
||||
|
||||
|
||||
|
||||
@@ -21,54 +21,54 @@ import os
|
||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
# You can specify your own secret key, here we just pick one randomly.
|
||||
SECRET_KEY = 'tktks103=$7a#5axn)52&b87!#w_qm(%*72^@hsq!nur%dtk4b'
|
||||
SECRET_KEY = "tktks103=$7a#5axn)52&b87!#w_qm(%*72^@hsq!nur%dtk4b"
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = ['*']
|
||||
ALLOWED_HOSTS = ["*"]
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'ray.tune.automlboard.models',
|
||||
"django.contrib.admin",
|
||||
"django.contrib.auth",
|
||||
"django.contrib.contenttypes",
|
||||
"django.contrib.sessions",
|
||||
"django.contrib.messages",
|
||||
"django.contrib.staticfiles",
|
||||
"ray.tune.automlboard.models",
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
"django.middleware.security.SecurityMiddleware",
|
||||
"django.contrib.sessions.middleware.SessionMiddleware",
|
||||
"django.middleware.common.CommonMiddleware",
|
||||
"django.middleware.csrf.CsrfViewMiddleware",
|
||||
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
||||
"django.contrib.messages.middleware.MessageMiddleware",
|
||||
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'ray.tune.automlboard.frontend.urls'
|
||||
ROOT_URLCONF = "ray.tune.automlboard.frontend.urls"
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [BASE_DIR + "/templates"],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.debug',
|
||||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
||||
"DIRS": [BASE_DIR + "/templates"],
|
||||
"APP_DIRS": True,
|
||||
"OPTIONS": {
|
||||
"context_processors": [
|
||||
"django.template.context_processors.debug",
|
||||
"django.template.context_processors.request",
|
||||
"django.contrib.auth.context_processors.auth",
|
||||
"django.contrib.messages.context_processors.messages",
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = 'ray.tune.automlboard.frontend.wsgi.application'
|
||||
WSGI_APPLICATION = "ray.tune.automlboard.frontend.wsgi.application"
|
||||
|
||||
DB_ENGINE_NAME_MAP = {
|
||||
"mysql": "django.db.backends.mysql",
|
||||
@@ -85,17 +85,17 @@ def lookup_db_engine(name):
|
||||
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
|
||||
if not os.environ.get("AUTOMLBOARD_DB_ENGINE", None):
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': 'automlboard.db',
|
||||
"default": {
|
||||
"ENGINE": "django.db.backends.sqlite3",
|
||||
"NAME": "automlboard.db",
|
||||
}
|
||||
}
|
||||
else:
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': lookup_db_engine(os.environ["AUTOMLBOARD_DB_ENGINE"]),
|
||||
'NAME': os.environ["AUTOMLBOARD_DB_NAME"],
|
||||
'USER': os.environ["AUTOMLBOARD_DB_USER"],
|
||||
"default": {
|
||||
"ENGINE": lookup_db_engine(os.environ["AUTOMLBOARD_DB_ENGINE"]),
|
||||
"NAME": os.environ["AUTOMLBOARD_DB_NAME"],
|
||||
"USER": os.environ["AUTOMLBOARD_DB_USER"],
|
||||
"PASSWORD": os.environ["AUTOMLBOARD_DB_PASSWORD"],
|
||||
"HOST": os.environ["AUTOMLBOARD_DB_HOST"],
|
||||
"PORT": os.environ["AUTOMLBOARD_DB_PORT"]
|
||||
@@ -109,25 +109,25 @@ VALIDATION_PREFIX = "django.contrib.auth.password_validation."
|
||||
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
'NAME': VALIDATION_PREFIX + "UserAttributeSimilarityValidator",
|
||||
"NAME": VALIDATION_PREFIX + "UserAttributeSimilarityValidator",
|
||||
},
|
||||
{
|
||||
'NAME': VALIDATION_PREFIX + "MinimumLengthValidator",
|
||||
"NAME": VALIDATION_PREFIX + "MinimumLengthValidator",
|
||||
},
|
||||
{
|
||||
'NAME': VALIDATION_PREFIX + "CommonPasswordValidator",
|
||||
"NAME": VALIDATION_PREFIX + "CommonPasswordValidator",
|
||||
},
|
||||
{
|
||||
'NAME': VALIDATION_PREFIX + "NumericPasswordValidator",
|
||||
"NAME": VALIDATION_PREFIX + "NumericPasswordValidator",
|
||||
},
|
||||
]
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/1.11/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
LANGUAGE_CODE = "en-us"
|
||||
|
||||
TIME_ZONE = 'Asia/Shanghai'
|
||||
TIME_ZONE = "Asia/Shanghai"
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
@@ -138,8 +138,8 @@ USE_TZ = False
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/1.11/howto/static-files/
|
||||
|
||||
STATIC_URL = '/static/'
|
||||
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static').replace('\\', '/'), )
|
||||
STATIC_URL = "/static/"
|
||||
STATICFILES_DIRS = (os.path.join(BASE_DIR, "static").replace("\\", "/"), )
|
||||
|
||||
# automlboard settings
|
||||
AUTOMLBOARD_LOG_DIR = os.environ.get("AUTOMLBOARD_LOGDIR", None)
|
||||
|
||||
+14
-14
@@ -53,12 +53,12 @@ except subprocess.CalledProcessError:
|
||||
TERM_HEIGHT, TERM_WIDTH = 100, 100
|
||||
|
||||
OPERATORS = {
|
||||
'<': operator.lt,
|
||||
'<=': operator.le,
|
||||
'==': operator.eq,
|
||||
'!=': operator.ne,
|
||||
'>=': operator.ge,
|
||||
'>': operator.gt,
|
||||
"<": operator.lt,
|
||||
"<=": operator.le,
|
||||
"==": operator.eq,
|
||||
"!=": operator.ne,
|
||||
">=": operator.ge,
|
||||
">": operator.gt,
|
||||
}
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ def print_format_output(dataframe):
|
||||
|
||||
print_df[col] = dataframe[col]
|
||||
test_table = tabulate(print_df, headers="keys", tablefmt="psql")
|
||||
if str(test_table).index('\n') > TERM_WIDTH:
|
||||
if str(test_table).index("\n") > TERM_WIDTH:
|
||||
# Drop all columns beyond terminal width
|
||||
print_df.drop(col, axis=1, inplace=True)
|
||||
dropped_cols += list(dataframe.columns)[i:]
|
||||
@@ -172,10 +172,10 @@ def list_trials(experiment_path,
|
||||
if "logdir" in checkpoints_df:
|
||||
# logdir often too verbose to view in table, so drop experiment_path
|
||||
checkpoints_df["logdir"] = checkpoints_df["logdir"].str.replace(
|
||||
experiment_path, '')
|
||||
experiment_path, "")
|
||||
|
||||
if filter_op:
|
||||
col, op, val = filter_op.split(' ')
|
||||
col, op, val = filter_op.split(" ")
|
||||
col_type = checkpoints_df[col].dtype
|
||||
if is_numeric_dtype(col_type):
|
||||
val = float(val)
|
||||
@@ -183,7 +183,7 @@ def list_trials(experiment_path,
|
||||
val = str(val)
|
||||
# TODO(Andrew): add support for datetime and boolean
|
||||
else:
|
||||
raise ValueError("Unsupported dtype for '{}': {}".format(
|
||||
raise ValueError("Unsupported dtype for \"{}\": {}".format(
|
||||
val, col_type))
|
||||
op = OPERATORS[op]
|
||||
filtered_index = op(checkpoints_df[col], val)
|
||||
@@ -191,7 +191,7 @@ def list_trials(experiment_path,
|
||||
|
||||
if sort:
|
||||
if sort not in checkpoints_df:
|
||||
raise KeyError("Sort Index '{}' not in: {}".format(
|
||||
raise KeyError("Sort Index \"{}\" not in: {}".format(
|
||||
sort, list(checkpoints_df)))
|
||||
checkpoints_df = checkpoints_df.sort_values(by=sort)
|
||||
|
||||
@@ -276,7 +276,7 @@ def list_experiments(project_path,
|
||||
info_df = info_df[col_keys]
|
||||
|
||||
if filter_op:
|
||||
col, op, val = filter_op.split(' ')
|
||||
col, op, val = filter_op.split(" ")
|
||||
col_type = info_df[col].dtype
|
||||
if is_numeric_dtype(col_type):
|
||||
val = float(val)
|
||||
@@ -284,7 +284,7 @@ def list_experiments(project_path,
|
||||
val = str(val)
|
||||
# TODO(Andrew): add support for datetime and boolean
|
||||
else:
|
||||
raise ValueError("Unsupported dtype for '{}': {}".format(
|
||||
raise ValueError("Unsupported dtype for \"{}\": {}".format(
|
||||
val, col_type))
|
||||
op = OPERATORS[op]
|
||||
filtered_index = op(info_df[col], val)
|
||||
@@ -292,7 +292,7 @@ def list_experiments(project_path,
|
||||
|
||||
if sort:
|
||||
if sort not in info_df:
|
||||
raise KeyError("Sort Index '{}' not in: {}".format(
|
||||
raise KeyError("Sort Index \"{}\" not in: {}".format(
|
||||
sort, list(info_df)))
|
||||
info_df = info_df.sort_values(by=sort)
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ if __name__ == "__main__":
|
||||
args, _ = parser.parse_known_args()
|
||||
ray.init()
|
||||
|
||||
space = {'width': (0, 20), 'height': (-100, 100)}
|
||||
space = {"width": (0, 20), "height": (-100, 100)}
|
||||
|
||||
config = {
|
||||
"num_samples": 10 if args.smoke_test else 1000,
|
||||
|
||||
@@ -17,7 +17,7 @@ def michalewicz_function(config, reporter):
|
||||
"""f(x) = -sum{sin(xi) * [sin(i*xi^2 / pi)]^(2m)}"""
|
||||
import numpy as np
|
||||
x = np.array(
|
||||
[config['x1'], config['x2'], config['x3'], config['x4'], config['x5']])
|
||||
[config["x1"], config["x2"], config["x3"], config["x4"], config["x5"]])
|
||||
sin_x = np.sin(x)
|
||||
z = (np.arange(1, 6) / np.pi * (x * x))
|
||||
sin_z = np.power(np.sin(z), 20) # let m = 20
|
||||
@@ -37,11 +37,11 @@ if __name__ == "__main__":
|
||||
ray.init()
|
||||
|
||||
space = SearchSpace({
|
||||
ContinuousSpace('x1', 0, 4, 100),
|
||||
ContinuousSpace('x2', -2, 2, 100),
|
||||
ContinuousSpace('x3', 1, 5, 100),
|
||||
ContinuousSpace('x4', -3, 3, 100),
|
||||
DiscreteSpace('x5', [-1, 0, 1, 2, 3]),
|
||||
ContinuousSpace("x1", 0, 4, 100),
|
||||
ContinuousSpace("x2", -2, 2, 100),
|
||||
ContinuousSpace("x3", 1, 5, 100),
|
||||
ContinuousSpace("x4", -3, 3, 100),
|
||||
DiscreteSpace("x5", [-1, 0, 1, 2, 3]),
|
||||
})
|
||||
|
||||
config = {"stop": {"training_iteration": 100}}
|
||||
|
||||
@@ -36,9 +36,9 @@ if __name__ == "__main__":
|
||||
ray.init()
|
||||
|
||||
space = {
|
||||
'width': hp.uniform('width', 0, 20),
|
||||
'height': hp.uniform('height', -100, 100),
|
||||
'activation': hp.choice("activation", ["relu", "tanh"])
|
||||
"width": hp.uniform("width", 0, 20),
|
||||
"height": hp.uniform("height", -100, 100),
|
||||
"activation": hp.choice("activation", ["relu", "tanh"])
|
||||
}
|
||||
|
||||
current_best_params = [
|
||||
|
||||
@@ -10,50 +10,50 @@ import torch.optim as optim
|
||||
from torchvision import datasets, transforms
|
||||
|
||||
# Training settings
|
||||
parser = argparse.ArgumentParser(description='PyTorch MNIST Example')
|
||||
parser = argparse.ArgumentParser(description="PyTorch MNIST Example")
|
||||
parser.add_argument(
|
||||
'--batch-size',
|
||||
"--batch-size",
|
||||
type=int,
|
||||
default=64,
|
||||
metavar='N',
|
||||
help='input batch size for training (default: 64)')
|
||||
metavar="N",
|
||||
help="input batch size for training (default: 64)")
|
||||
parser.add_argument(
|
||||
'--test-batch-size',
|
||||
"--test-batch-size",
|
||||
type=int,
|
||||
default=1000,
|
||||
metavar='N',
|
||||
help='input batch size for testing (default: 1000)')
|
||||
metavar="N",
|
||||
help="input batch size for testing (default: 1000)")
|
||||
parser.add_argument(
|
||||
'--epochs',
|
||||
"--epochs",
|
||||
type=int,
|
||||
default=1,
|
||||
metavar='N',
|
||||
help='number of epochs to train (default: 1)')
|
||||
metavar="N",
|
||||
help="number of epochs to train (default: 1)")
|
||||
parser.add_argument(
|
||||
'--lr',
|
||||
"--lr",
|
||||
type=float,
|
||||
default=0.01,
|
||||
metavar='LR',
|
||||
help='learning rate (default: 0.01)')
|
||||
metavar="LR",
|
||||
help="learning rate (default: 0.01)")
|
||||
parser.add_argument(
|
||||
'--momentum',
|
||||
"--momentum",
|
||||
type=float,
|
||||
default=0.5,
|
||||
metavar='M',
|
||||
help='SGD momentum (default: 0.5)')
|
||||
metavar="M",
|
||||
help="SGD momentum (default: 0.5)")
|
||||
parser.add_argument(
|
||||
'--no-cuda',
|
||||
action='store_true',
|
||||
"--no-cuda",
|
||||
action="store_true",
|
||||
default=False,
|
||||
help='disables CUDA training')
|
||||
help="disables CUDA training")
|
||||
parser.add_argument(
|
||||
'--seed',
|
||||
"--seed",
|
||||
type=int,
|
||||
default=1,
|
||||
metavar='S',
|
||||
help='random seed (default: 1)')
|
||||
metavar="S",
|
||||
help="random seed (default: 1)")
|
||||
parser.add_argument(
|
||||
'--smoke-test', action="store_true", help="Finish quickly for testing")
|
||||
"--smoke-test", action="store_true", help="Finish quickly for testing")
|
||||
|
||||
|
||||
def train_mnist(args, config, reporter):
|
||||
@@ -64,10 +64,10 @@ def train_mnist(args, config, reporter):
|
||||
if args.cuda:
|
||||
torch.cuda.manual_seed(args.seed)
|
||||
|
||||
kwargs = {'num_workers': 1, 'pin_memory': True} if args.cuda else {}
|
||||
kwargs = {"num_workers": 1, "pin_memory": True} if args.cuda else {}
|
||||
train_loader = torch.utils.data.DataLoader(
|
||||
datasets.MNIST(
|
||||
'~/data',
|
||||
"~/data",
|
||||
train=True,
|
||||
download=False,
|
||||
transform=transforms.Compose([
|
||||
@@ -79,7 +79,7 @@ def train_mnist(args, config, reporter):
|
||||
**kwargs)
|
||||
test_loader = torch.utils.data.DataLoader(
|
||||
datasets.MNIST(
|
||||
'~/data',
|
||||
"~/data",
|
||||
train=False,
|
||||
transform=transforms.Compose([
|
||||
transforms.ToTensor(),
|
||||
@@ -135,7 +135,7 @@ def train_mnist(args, config, reporter):
|
||||
data, target = data.cuda(), target.cuda()
|
||||
output = model(data)
|
||||
# sum up batch loss
|
||||
test_loss += F.nll_loss(output, target, reduction='sum').item()
|
||||
test_loss += F.nll_loss(output, target, reduction="sum").item()
|
||||
# get the index of the max log-probability
|
||||
pred = output.argmax(dim=1, keepdim=True)
|
||||
correct += pred.eq(
|
||||
@@ -151,7 +151,7 @@ def train_mnist(args, config, reporter):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
datasets.MNIST('~/data', train=True, download=True)
|
||||
datasets.MNIST("~/data", train=True, download=True)
|
||||
args = parser.parse_args()
|
||||
|
||||
import numpy as np
|
||||
|
||||
@@ -13,50 +13,50 @@ from torchvision import datasets, transforms
|
||||
from ray.tune import Trainable
|
||||
|
||||
# Training settings
|
||||
parser = argparse.ArgumentParser(description='PyTorch MNIST Example')
|
||||
parser = argparse.ArgumentParser(description="PyTorch MNIST Example")
|
||||
parser.add_argument(
|
||||
'--batch-size',
|
||||
"--batch-size",
|
||||
type=int,
|
||||
default=64,
|
||||
metavar='N',
|
||||
help='input batch size for training (default: 64)')
|
||||
metavar="N",
|
||||
help="input batch size for training (default: 64)")
|
||||
parser.add_argument(
|
||||
'--test-batch-size',
|
||||
"--test-batch-size",
|
||||
type=int,
|
||||
default=1000,
|
||||
metavar='N',
|
||||
help='input batch size for testing (default: 1000)')
|
||||
metavar="N",
|
||||
help="input batch size for testing (default: 1000)")
|
||||
parser.add_argument(
|
||||
'--epochs',
|
||||
"--epochs",
|
||||
type=int,
|
||||
default=1,
|
||||
metavar='N',
|
||||
help='number of epochs to train (default: 1)')
|
||||
metavar="N",
|
||||
help="number of epochs to train (default: 1)")
|
||||
parser.add_argument(
|
||||
'--lr',
|
||||
"--lr",
|
||||
type=float,
|
||||
default=0.01,
|
||||
metavar='LR',
|
||||
help='learning rate (default: 0.01)')
|
||||
metavar="LR",
|
||||
help="learning rate (default: 0.01)")
|
||||
parser.add_argument(
|
||||
'--momentum',
|
||||
"--momentum",
|
||||
type=float,
|
||||
default=0.5,
|
||||
metavar='M',
|
||||
help='SGD momentum (default: 0.5)')
|
||||
metavar="M",
|
||||
help="SGD momentum (default: 0.5)")
|
||||
parser.add_argument(
|
||||
'--no-cuda',
|
||||
action='store_true',
|
||||
"--no-cuda",
|
||||
action="store_true",
|
||||
default=False,
|
||||
help='disables CUDA training')
|
||||
help="disables CUDA training")
|
||||
parser.add_argument(
|
||||
'--seed',
|
||||
"--seed",
|
||||
type=int,
|
||||
default=1,
|
||||
metavar='S',
|
||||
help='random seed (default: 1)')
|
||||
metavar="S",
|
||||
help="random seed (default: 1)")
|
||||
parser.add_argument(
|
||||
'--smoke-test', action="store_true", help="Finish quickly for testing")
|
||||
"--smoke-test", action="store_true", help="Finish quickly for testing")
|
||||
|
||||
|
||||
class Net(nn.Module):
|
||||
@@ -88,10 +88,10 @@ class TrainMNIST(Trainable):
|
||||
if args.cuda:
|
||||
torch.cuda.manual_seed(args.seed)
|
||||
|
||||
kwargs = {'num_workers': 1, 'pin_memory': True} if args.cuda else {}
|
||||
kwargs = {"num_workers": 1, "pin_memory": True} if args.cuda else {}
|
||||
self.train_loader = torch.utils.data.DataLoader(
|
||||
datasets.MNIST(
|
||||
'~/data',
|
||||
"~/data",
|
||||
train=True,
|
||||
download=False,
|
||||
transform=transforms.Compose([
|
||||
@@ -103,7 +103,7 @@ class TrainMNIST(Trainable):
|
||||
**kwargs)
|
||||
self.test_loader = torch.utils.data.DataLoader(
|
||||
datasets.MNIST(
|
||||
'~/data',
|
||||
"~/data",
|
||||
train=False,
|
||||
transform=transforms.Compose([
|
||||
transforms.ToTensor(),
|
||||
@@ -142,7 +142,7 @@ class TrainMNIST(Trainable):
|
||||
data, target = data.cuda(), target.cuda()
|
||||
output = self.model(data)
|
||||
# sum up batch loss
|
||||
test_loss += F.nll_loss(output, target, reduction='sum').item()
|
||||
test_loss += F.nll_loss(output, target, reduction="sum").item()
|
||||
# get the index of the max log-probability
|
||||
pred = output.argmax(dim=1, keepdim=True)
|
||||
correct += pred.eq(
|
||||
@@ -166,7 +166,7 @@ class TrainMNIST(Trainable):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
datasets.MNIST('~/data', train=True, download=True)
|
||||
datasets.MNIST("~/data", train=True, download=True)
|
||||
args = parser.parse_args()
|
||||
|
||||
import numpy as np
|
||||
|
||||
@@ -38,19 +38,19 @@ if __name__ == "__main__":
|
||||
|
||||
space = [
|
||||
{
|
||||
'name': 'width',
|
||||
'type': 'int',
|
||||
'bounds': {
|
||||
'min': 0,
|
||||
'max': 20
|
||||
"name": "width",
|
||||
"type": "int",
|
||||
"bounds": {
|
||||
"min": 0,
|
||||
"max": 20
|
||||
},
|
||||
},
|
||||
{
|
||||
'name': 'height',
|
||||
'type': 'int',
|
||||
'bounds': {
|
||||
'min': -100,
|
||||
'max': 100
|
||||
"name": "height",
|
||||
"type": "int",
|
||||
"bounds": {
|
||||
"min": -100,
|
||||
"max": 100
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
@@ -60,32 +60,32 @@ def deepnn(x):
|
||||
# Reshape to use within a convolutional neural net.
|
||||
# Last dimension is for "features" - there is only one here, since images
|
||||
# are grayscale -- it would be 3 for an RGB image, 4 for RGBA, etc.
|
||||
with tf.name_scope('reshape'):
|
||||
with tf.name_scope("reshape"):
|
||||
x_image = tf.reshape(x, [-1, 28, 28, 1])
|
||||
|
||||
# First convolutional layer - maps one grayscale image to 32 feature maps.
|
||||
with tf.name_scope('conv1'):
|
||||
with tf.name_scope("conv1"):
|
||||
W_conv1 = weight_variable([5, 5, 1, 32])
|
||||
b_conv1 = bias_variable([32])
|
||||
h_conv1 = activation_fn(conv2d(x_image, W_conv1) + b_conv1)
|
||||
|
||||
# Pooling layer - downsamples by 2X.
|
||||
with tf.name_scope('pool1'):
|
||||
with tf.name_scope("pool1"):
|
||||
h_pool1 = max_pool_2x2(h_conv1)
|
||||
|
||||
# Second convolutional layer -- maps 32 feature maps to 64.
|
||||
with tf.name_scope('conv2'):
|
||||
with tf.name_scope("conv2"):
|
||||
W_conv2 = weight_variable([5, 5, 32, 64])
|
||||
b_conv2 = bias_variable([64])
|
||||
h_conv2 = activation_fn(conv2d(h_pool1, W_conv2) + b_conv2)
|
||||
|
||||
# Second pooling layer.
|
||||
with tf.name_scope('pool2'):
|
||||
with tf.name_scope("pool2"):
|
||||
h_pool2 = max_pool_2x2(h_conv2)
|
||||
|
||||
# Fully connected layer 1 -- after 2 round of downsampling, our 28x28 image
|
||||
# is down to 7x7x64 feature maps -- maps this to 1024 features.
|
||||
with tf.name_scope('fc1'):
|
||||
with tf.name_scope("fc1"):
|
||||
W_fc1 = weight_variable([7 * 7 * 64, 1024])
|
||||
b_fc1 = bias_variable([1024])
|
||||
|
||||
@@ -94,12 +94,12 @@ def deepnn(x):
|
||||
|
||||
# Dropout - controls the complexity of the model, prevents co-adaptation of
|
||||
# features.
|
||||
with tf.name_scope('dropout'):
|
||||
with tf.name_scope("dropout"):
|
||||
keep_prob = tf.placeholder(tf.float32)
|
||||
h_fc1_drop = tf.nn.dropout(h_fc1, keep_prob)
|
||||
|
||||
# Map the 1024 features to 10 classes, one for each digit
|
||||
with tf.name_scope('fc2'):
|
||||
with tf.name_scope("fc2"):
|
||||
W_fc2 = weight_variable([1024, 10])
|
||||
b_fc2 = bias_variable([10])
|
||||
|
||||
@@ -109,13 +109,13 @@ def deepnn(x):
|
||||
|
||||
def conv2d(x, W):
|
||||
"""conv2d returns a 2d convolution layer with full stride."""
|
||||
return tf.nn.conv2d(x, W, strides=[1, 1, 1, 1], padding='SAME')
|
||||
return tf.nn.conv2d(x, W, strides=[1, 1, 1, 1], padding="SAME")
|
||||
|
||||
|
||||
def max_pool_2x2(x):
|
||||
"""max_pool_2x2 downsamples a feature map by 2X."""
|
||||
return tf.nn.max_pool(
|
||||
x, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding='SAME')
|
||||
x, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding="SAME")
|
||||
|
||||
|
||||
def weight_variable(shape):
|
||||
@@ -148,21 +148,21 @@ def main(_):
|
||||
# Build the graph for the deep net
|
||||
y_conv, keep_prob = deepnn(x)
|
||||
|
||||
with tf.name_scope('loss'):
|
||||
with tf.name_scope("loss"):
|
||||
cross_entropy = tf.nn.softmax_cross_entropy_with_logits(
|
||||
labels=y_, logits=y_conv)
|
||||
cross_entropy = tf.reduce_mean(cross_entropy)
|
||||
|
||||
with tf.name_scope('adam_optimizer'):
|
||||
with tf.name_scope("adam_optimizer"):
|
||||
train_step = tf.train.AdamOptimizer(1e-4).minimize(cross_entropy)
|
||||
|
||||
with tf.name_scope('accuracy'):
|
||||
with tf.name_scope("accuracy"):
|
||||
correct_prediction = tf.equal(tf.argmax(y_conv, 1), tf.argmax(y_, 1))
|
||||
correct_prediction = tf.cast(correct_prediction, tf.float32)
|
||||
accuracy = tf.reduce_mean(correct_prediction)
|
||||
|
||||
graph_location = tempfile.mkdtemp()
|
||||
print('Saving graph to: %s' % graph_location)
|
||||
print("Saving graph to: %s" % graph_location)
|
||||
train_writer = tf.summary.FileWriter(graph_location)
|
||||
train_writer.add_graph(tf.get_default_graph())
|
||||
|
||||
@@ -182,14 +182,14 @@ def main(_):
|
||||
status_reporter(
|
||||
timesteps_total=i, mean_accuracy=train_accuracy)
|
||||
|
||||
print('step %d, training accuracy %g' % (i, train_accuracy))
|
||||
print("step %d, training accuracy %g" % (i, train_accuracy))
|
||||
train_step.run(feed_dict={
|
||||
x: batch[0],
|
||||
y_: batch[1],
|
||||
keep_prob: 0.5
|
||||
})
|
||||
|
||||
print('test accuracy %g' % accuracy.eval(feed_dict={
|
||||
print("test accuracy %g" % accuracy.eval(feed_dict={
|
||||
x: mnist.test.images,
|
||||
y_: mnist.test.labels,
|
||||
keep_prob: 1.0
|
||||
@@ -197,16 +197,16 @@ def main(_):
|
||||
|
||||
|
||||
# !!! Entrypoint for ray.tune !!!
|
||||
def train(config={'activation': 'relu'}, reporter=None):
|
||||
def train(config={"activation": "relu"}, reporter=None):
|
||||
global FLAGS, status_reporter, activation_fn
|
||||
status_reporter = reporter
|
||||
activation_fn = getattr(tf.nn, config['activation'])
|
||||
activation_fn = getattr(tf.nn, config["activation"])
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
'--data_dir',
|
||||
"--data_dir",
|
||||
type=str,
|
||||
default='/tmp/tensorflow/mnist/input_data',
|
||||
help='Directory for storing input data')
|
||||
default="/tmp/tensorflow/mnist/input_data",
|
||||
help="Directory for storing input data")
|
||||
FLAGS, unparsed = parser.parse_known_args()
|
||||
tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
|
||||
|
||||
@@ -215,29 +215,29 @@ def train(config={'activation': 'relu'}, reporter=None):
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
'--smoke-test', action='store_true', help='Finish quickly for testing')
|
||||
"--smoke-test", action="store_true", help="Finish quickly for testing")
|
||||
args, _ = parser.parse_known_args()
|
||||
|
||||
mnist_spec = {
|
||||
'num_samples': 10,
|
||||
'stop': {
|
||||
'mean_accuracy': 0.99,
|
||||
'timesteps_total': 600,
|
||||
"num_samples": 10,
|
||||
"stop": {
|
||||
"mean_accuracy": 0.99,
|
||||
"timesteps_total": 600,
|
||||
},
|
||||
'config': {
|
||||
'activation': grid_search(['relu', 'elu', 'tanh']),
|
||||
"config": {
|
||||
"activation": grid_search(["relu", "elu", "tanh"]),
|
||||
},
|
||||
}
|
||||
|
||||
if args.smoke_test:
|
||||
mnist_spec['stop']['training_iteration'] = 2
|
||||
mnist_spec['num_samples'] = 1
|
||||
mnist_spec["stop"]["training_iteration"] = 2
|
||||
mnist_spec["num_samples"] = 1
|
||||
|
||||
ray.init()
|
||||
|
||||
from ray.tune.schedulers import AsyncHyperBandScheduler
|
||||
run(train,
|
||||
name='tune_mnist_test',
|
||||
name="tune_mnist_test",
|
||||
scheduler=AsyncHyperBandScheduler(
|
||||
time_attr="timesteps_total",
|
||||
reward_attr="mean_accuracy",
|
||||
|
||||
@@ -50,7 +50,7 @@ def train_mnist(args, cfg, reporter):
|
||||
# the data, split between train and test sets
|
||||
(x_train, y_train), (x_test, y_test) = mnist.load_data()
|
||||
|
||||
if K.image_data_format() == 'channels_first':
|
||||
if K.image_data_format() == "channels_first":
|
||||
x_train = x_train.reshape(x_train.shape[0], 1, img_rows, img_cols)
|
||||
x_test = x_test.reshape(x_test.shape[0], 1, img_rows, img_cols)
|
||||
input_shape = (1, img_rows, img_cols)
|
||||
@@ -59,13 +59,13 @@ def train_mnist(args, cfg, reporter):
|
||||
x_test = x_test.reshape(x_test.shape[0], img_rows, img_cols, 1)
|
||||
input_shape = (img_rows, img_cols, 1)
|
||||
|
||||
x_train = x_train.astype('float32')
|
||||
x_test = x_test.astype('float32')
|
||||
x_train = x_train.astype("float32")
|
||||
x_test = x_test.astype("float32")
|
||||
x_train /= 255
|
||||
x_test /= 255
|
||||
print('x_train shape:', x_train.shape)
|
||||
print(x_train.shape[0], 'train samples')
|
||||
print(x_test.shape[0], 'test samples')
|
||||
print("x_train shape:", x_train.shape)
|
||||
print(x_train.shape[0], "train samples")
|
||||
print(x_test.shape[0], "test samples")
|
||||
|
||||
# convert class vectors to binary class matrices
|
||||
y_train = keras.utils.to_categorical(y_train, num_classes)
|
||||
@@ -76,20 +76,20 @@ def train_mnist(args, cfg, reporter):
|
||||
Conv2D(
|
||||
32,
|
||||
kernel_size=(args.kernel1, args.kernel1),
|
||||
activation='relu',
|
||||
activation="relu",
|
||||
input_shape=input_shape))
|
||||
model.add(Conv2D(64, (args.kernel2, args.kernel2), activation='relu'))
|
||||
model.add(Conv2D(64, (args.kernel2, args.kernel2), activation="relu"))
|
||||
model.add(MaxPooling2D(pool_size=(args.poolsize, args.poolsize)))
|
||||
model.add(Dropout(args.dropout1))
|
||||
model.add(Flatten())
|
||||
model.add(Dense(args.hidden, activation='relu'))
|
||||
model.add(Dense(args.hidden, activation="relu"))
|
||||
model.add(Dropout(args.dropout2))
|
||||
model.add(Dense(num_classes, activation='softmax'))
|
||||
model.add(Dense(num_classes, activation="softmax"))
|
||||
|
||||
model.compile(
|
||||
loss=keras.losses.categorical_crossentropy,
|
||||
optimizer=keras.optimizers.SGD(lr=args.lr, momentum=args.momentum),
|
||||
metrics=['accuracy'])
|
||||
metrics=["accuracy"])
|
||||
|
||||
model.fit(
|
||||
x_train,
|
||||
@@ -102,66 +102,66 @@ def train_mnist(args, cfg, reporter):
|
||||
|
||||
|
||||
def create_parser():
|
||||
parser = argparse.ArgumentParser(description='Keras MNIST Example')
|
||||
parser = argparse.ArgumentParser(description="Keras MNIST Example")
|
||||
parser.add_argument(
|
||||
"--smoke-test", action="store_true", help="Finish quickly for testing")
|
||||
parser.add_argument(
|
||||
"--use-gpu", action="store_true", help="Use GPU in training.")
|
||||
parser.add_argument(
|
||||
'--jobs',
|
||||
"--jobs",
|
||||
type=int,
|
||||
default=1,
|
||||
help='number of jobs to run concurrently (default: 1)')
|
||||
help="number of jobs to run concurrently (default: 1)")
|
||||
parser.add_argument(
|
||||
'--threads',
|
||||
"--threads",
|
||||
type=int,
|
||||
default=2,
|
||||
help='threads used in operations (default: 2)')
|
||||
help="threads used in operations (default: 2)")
|
||||
parser.add_argument(
|
||||
'--steps',
|
||||
"--steps",
|
||||
type=float,
|
||||
default=0.01,
|
||||
metavar='LR',
|
||||
help='learning rate (default: 0.01)')
|
||||
metavar="LR",
|
||||
help="learning rate (default: 0.01)")
|
||||
parser.add_argument(
|
||||
'--lr',
|
||||
"--lr",
|
||||
type=float,
|
||||
default=0.01,
|
||||
metavar='LR',
|
||||
help='learning rate (default: 0.01)')
|
||||
metavar="LR",
|
||||
help="learning rate (default: 0.01)")
|
||||
parser.add_argument(
|
||||
'--momentum',
|
||||
"--momentum",
|
||||
type=float,
|
||||
default=0.5,
|
||||
metavar='M',
|
||||
help='SGD momentum (default: 0.5)')
|
||||
metavar="M",
|
||||
help="SGD momentum (default: 0.5)")
|
||||
parser.add_argument(
|
||||
'--kernel1',
|
||||
"--kernel1",
|
||||
type=int,
|
||||
default=3,
|
||||
help='Size of first kernel (default: 3)')
|
||||
help="Size of first kernel (default: 3)")
|
||||
parser.add_argument(
|
||||
'--kernel2',
|
||||
"--kernel2",
|
||||
type=int,
|
||||
default=3,
|
||||
help='Size of second kernel (default: 3)')
|
||||
help="Size of second kernel (default: 3)")
|
||||
parser.add_argument(
|
||||
'--poolsize', type=int, default=2, help='Size of Pooling (default: 2)')
|
||||
"--poolsize", type=int, default=2, help="Size of Pooling (default: 2)")
|
||||
parser.add_argument(
|
||||
'--dropout1',
|
||||
"--dropout1",
|
||||
type=float,
|
||||
default=0.25,
|
||||
help='Size of first kernel (default: 0.25)')
|
||||
help="Size of first kernel (default: 0.25)")
|
||||
parser.add_argument(
|
||||
'--hidden',
|
||||
"--hidden",
|
||||
type=int,
|
||||
default=128,
|
||||
help='Size of Hidden Layer (default: 128)')
|
||||
help="Size of Hidden Layer (default: 128)")
|
||||
parser.add_argument(
|
||||
'--dropout2',
|
||||
"--dropout2",
|
||||
type=float,
|
||||
default=0.5,
|
||||
help='Size of first kernel (default: 0.5)')
|
||||
help="Size of first kernel (default: 0.5)")
|
||||
return parser
|
||||
|
||||
|
||||
|
||||
@@ -62,32 +62,32 @@ def deepnn(x):
|
||||
# Reshape to use within a convolutional neural net.
|
||||
# Last dimension is for "features" - there is only one here, since images
|
||||
# are grayscale -- it would be 3 for an RGB image, 4 for RGBA, etc.
|
||||
with tf.name_scope('reshape'):
|
||||
with tf.name_scope("reshape"):
|
||||
x_image = tf.reshape(x, [-1, 28, 28, 1])
|
||||
|
||||
# First convolutional layer - maps one grayscale image to 32 feature maps.
|
||||
with tf.name_scope('conv1'):
|
||||
with tf.name_scope("conv1"):
|
||||
W_conv1 = weight_variable([5, 5, 1, 32])
|
||||
b_conv1 = bias_variable([32])
|
||||
h_conv1 = activation_fn(conv2d(x_image, W_conv1) + b_conv1)
|
||||
|
||||
# Pooling layer - downsamples by 2X.
|
||||
with tf.name_scope('pool1'):
|
||||
with tf.name_scope("pool1"):
|
||||
h_pool1 = max_pool_2x2(h_conv1)
|
||||
|
||||
# Second convolutional layer -- maps 32 feature maps to 64.
|
||||
with tf.name_scope('conv2'):
|
||||
with tf.name_scope("conv2"):
|
||||
W_conv2 = weight_variable([5, 5, 32, 64])
|
||||
b_conv2 = bias_variable([64])
|
||||
h_conv2 = activation_fn(conv2d(h_pool1, W_conv2) + b_conv2)
|
||||
|
||||
# Second pooling layer.
|
||||
with tf.name_scope('pool2'):
|
||||
with tf.name_scope("pool2"):
|
||||
h_pool2 = max_pool_2x2(h_conv2)
|
||||
|
||||
# Fully connected layer 1 -- after 2 round of downsampling, our 28x28 image
|
||||
# is down to 7x7x64 feature maps -- maps this to 1024 features.
|
||||
with tf.name_scope('fc1'):
|
||||
with tf.name_scope("fc1"):
|
||||
W_fc1 = weight_variable([7 * 7 * 64, 1024])
|
||||
b_fc1 = bias_variable([1024])
|
||||
|
||||
@@ -96,12 +96,12 @@ def deepnn(x):
|
||||
|
||||
# Dropout - controls the complexity of the model, prevents co-adaptation of
|
||||
# features.
|
||||
with tf.name_scope('dropout'):
|
||||
with tf.name_scope("dropout"):
|
||||
keep_prob = tf.placeholder(tf.float32)
|
||||
h_fc1_drop = tf.nn.dropout(h_fc1, keep_prob)
|
||||
|
||||
# Map the 1024 features to 10 classes, one for each digit
|
||||
with tf.name_scope('fc2'):
|
||||
with tf.name_scope("fc2"):
|
||||
W_fc2 = weight_variable([1024, 10])
|
||||
b_fc2 = bias_variable([10])
|
||||
|
||||
@@ -111,13 +111,13 @@ def deepnn(x):
|
||||
|
||||
def conv2d(x, W):
|
||||
"""conv2d returns a 2d convolution layer with full stride."""
|
||||
return tf.nn.conv2d(x, W, strides=[1, 1, 1, 1], padding='SAME')
|
||||
return tf.nn.conv2d(x, W, strides=[1, 1, 1, 1], padding="SAME")
|
||||
|
||||
|
||||
def max_pool_2x2(x):
|
||||
"""max_pool_2x2 downsamples a feature map by 2X."""
|
||||
return tf.nn.max_pool(
|
||||
x, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding='SAME')
|
||||
x, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding="SAME")
|
||||
|
||||
|
||||
def weight_variable(shape):
|
||||
@@ -150,21 +150,21 @@ def main(_):
|
||||
# Build the graph for the deep net
|
||||
y_conv, keep_prob = deepnn(x)
|
||||
|
||||
with tf.name_scope('loss'):
|
||||
with tf.name_scope("loss"):
|
||||
cross_entropy = tf.nn.softmax_cross_entropy_with_logits(
|
||||
labels=y_, logits=y_conv)
|
||||
cross_entropy = tf.reduce_mean(cross_entropy)
|
||||
|
||||
with tf.name_scope('adam_optimizer'):
|
||||
with tf.name_scope("adam_optimizer"):
|
||||
train_step = tf.train.AdamOptimizer(1e-4).minimize(cross_entropy)
|
||||
|
||||
with tf.name_scope('accuracy'):
|
||||
with tf.name_scope("accuracy"):
|
||||
correct_prediction = tf.equal(tf.argmax(y_conv, 1), tf.argmax(y_, 1))
|
||||
correct_prediction = tf.cast(correct_prediction, tf.float32)
|
||||
accuracy = tf.reduce_mean(correct_prediction)
|
||||
|
||||
graph_location = tempfile.mkdtemp()
|
||||
print('Saving graph to: %s' % graph_location)
|
||||
print("Saving graph to: %s" % graph_location)
|
||||
train_writer = tf.summary.FileWriter(graph_location)
|
||||
train_writer.add_graph(tf.get_default_graph())
|
||||
|
||||
@@ -184,14 +184,14 @@ def main(_):
|
||||
status_reporter(
|
||||
timesteps_total=i, mean_accuracy=train_accuracy)
|
||||
|
||||
print('step %d, training accuracy %g' % (i, train_accuracy))
|
||||
print("step %d, training accuracy %g" % (i, train_accuracy))
|
||||
train_step.run(feed_dict={
|
||||
x: batch[0],
|
||||
y_: batch[1],
|
||||
keep_prob: 0.5
|
||||
})
|
||||
|
||||
print('test accuracy %g' % accuracy.eval(feed_dict={
|
||||
print("test accuracy %g" % accuracy.eval(feed_dict={
|
||||
x: mnist.test.images,
|
||||
y_: mnist.test.labels,
|
||||
keep_prob: 1.0
|
||||
@@ -199,16 +199,16 @@ def main(_):
|
||||
|
||||
|
||||
# !!! Entrypoint for ray.tune !!!
|
||||
def train(config={'activation': 'relu'}, reporter=None):
|
||||
def train(config={"activation": "relu"}, reporter=None):
|
||||
global FLAGS, status_reporter, activation_fn
|
||||
status_reporter = reporter
|
||||
activation_fn = getattr(tf.nn, config['activation'])
|
||||
activation_fn = getattr(tf.nn, config["activation"])
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
'--data_dir',
|
||||
"--data_dir",
|
||||
type=str,
|
||||
default='/tmp/tensorflow/mnist/input_data',
|
||||
help='Directory for storing input data')
|
||||
default="/tmp/tensorflow/mnist/input_data",
|
||||
help="Directory for storing input data")
|
||||
FLAGS, unparsed = parser.parse_known_args()
|
||||
tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
|
||||
|
||||
@@ -217,25 +217,25 @@ def train(config={'activation': 'relu'}, reporter=None):
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
'--smoke-test', action='store_true', help='Finish quickly for testing')
|
||||
"--smoke-test", action="store_true", help="Finish quickly for testing")
|
||||
args, _ = parser.parse_known_args()
|
||||
|
||||
register_trainable('train_mnist', train)
|
||||
register_trainable("train_mnist", train)
|
||||
mnist_spec = {
|
||||
'stop': {
|
||||
'mean_accuracy': 0.99,
|
||||
'time_total_s': 600,
|
||||
"stop": {
|
||||
"mean_accuracy": 0.99,
|
||||
"time_total_s": 600,
|
||||
},
|
||||
'config': {
|
||||
'activation': grid_search(['relu', 'elu', 'tanh']),
|
||||
"config": {
|
||||
"activation": grid_search(["relu", "elu", "tanh"]),
|
||||
# You can pass any serializable object as well
|
||||
'foo': grid_search([np.array([1, 2]),
|
||||
"foo": grid_search([np.array([1, 2]),
|
||||
np.array([2, 3])]),
|
||||
},
|
||||
}
|
||||
|
||||
if args.smoke_test:
|
||||
mnist_spec['stop']['training_iteration'] = 2
|
||||
mnist_spec["stop"]["training_iteration"] = 2
|
||||
|
||||
ray.init()
|
||||
tune.run('train_mnist', name='tune_mnist_test', **mnist_spec)
|
||||
tune.run("train_mnist", name="tune_mnist_test", **mnist_spec)
|
||||
|
||||
@@ -55,32 +55,32 @@ def setupCNN(x):
|
||||
# Reshape to use within a convolutional neural net.
|
||||
# Last dimension is for "features" - there is only one here, since images
|
||||
# are grayscale -- it would be 3 for an RGB image, 4 for RGBA, etc.
|
||||
with tf.name_scope('reshape'):
|
||||
with tf.name_scope("reshape"):
|
||||
x_image = tf.reshape(x, [-1, 28, 28, 1])
|
||||
|
||||
# First convolutional layer - maps one grayscale image to 32 feature maps.
|
||||
with tf.name_scope('conv1'):
|
||||
with tf.name_scope("conv1"):
|
||||
W_conv1 = weight_variable([5, 5, 1, 32])
|
||||
b_conv1 = bias_variable([32])
|
||||
h_conv1 = activation_fn(conv2d(x_image, W_conv1) + b_conv1)
|
||||
|
||||
# Pooling layer - downsamples by 2X.
|
||||
with tf.name_scope('pool1'):
|
||||
with tf.name_scope("pool1"):
|
||||
h_pool1 = max_pool_2x2(h_conv1)
|
||||
|
||||
# Second convolutional layer -- maps 32 feature maps to 64.
|
||||
with tf.name_scope('conv2'):
|
||||
with tf.name_scope("conv2"):
|
||||
W_conv2 = weight_variable([5, 5, 32, 64])
|
||||
b_conv2 = bias_variable([64])
|
||||
h_conv2 = activation_fn(conv2d(h_pool1, W_conv2) + b_conv2)
|
||||
|
||||
# Second pooling layer.
|
||||
with tf.name_scope('pool2'):
|
||||
with tf.name_scope("pool2"):
|
||||
h_pool2 = max_pool_2x2(h_conv2)
|
||||
|
||||
# Fully connected layer 1 -- after 2 round of downsampling, our 28x28 image
|
||||
# is down to 7x7x64 feature maps -- maps this to 1024 features.
|
||||
with tf.name_scope('fc1'):
|
||||
with tf.name_scope("fc1"):
|
||||
W_fc1 = weight_variable([7 * 7 * 64, 1024])
|
||||
b_fc1 = bias_variable([1024])
|
||||
|
||||
@@ -89,12 +89,12 @@ def setupCNN(x):
|
||||
|
||||
# Dropout - controls the complexity of the model, prevents co-adaptation of
|
||||
# features.
|
||||
with tf.name_scope('dropout'):
|
||||
with tf.name_scope("dropout"):
|
||||
keep_prob = tf.placeholder(tf.float32)
|
||||
h_fc1_drop = tf.nn.dropout(h_fc1, keep_prob)
|
||||
|
||||
# Map the 1024 features to 10 classes, one for each digit
|
||||
with tf.name_scope('fc2'):
|
||||
with tf.name_scope("fc2"):
|
||||
W_fc2 = weight_variable([1024, 10])
|
||||
b_fc2 = bias_variable([10])
|
||||
|
||||
@@ -104,13 +104,13 @@ def setupCNN(x):
|
||||
|
||||
def conv2d(x, W):
|
||||
"""conv2d returns a 2d convolution layer with full stride."""
|
||||
return tf.nn.conv2d(x, W, strides=[1, 1, 1, 1], padding='SAME')
|
||||
return tf.nn.conv2d(x, W, strides=[1, 1, 1, 1], padding="SAME")
|
||||
|
||||
|
||||
def max_pool_2x2(x):
|
||||
"""max_pool_2x2 downsamples a feature map by 2X."""
|
||||
return tf.nn.max_pool(
|
||||
x, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding='SAME')
|
||||
x, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding="SAME")
|
||||
|
||||
|
||||
def weight_variable(shape):
|
||||
@@ -148,23 +148,23 @@ class TrainMNIST(Trainable):
|
||||
self.x = tf.placeholder(tf.float32, [None, 784])
|
||||
self.y_ = tf.placeholder(tf.float32, [None, 10])
|
||||
|
||||
activation_fn = getattr(tf.nn, config['activation'])
|
||||
activation_fn = getattr(tf.nn, config["activation"])
|
||||
|
||||
# Build the graph for the deep net
|
||||
y_conv, self.keep_prob = setupCNN(self.x)
|
||||
|
||||
with tf.name_scope('loss'):
|
||||
with tf.name_scope("loss"):
|
||||
cross_entropy = tf.nn.softmax_cross_entropy_with_logits(
|
||||
labels=self.y_, logits=y_conv)
|
||||
cross_entropy = tf.reduce_mean(cross_entropy)
|
||||
|
||||
with tf.name_scope('adam_optimizer'):
|
||||
with tf.name_scope("adam_optimizer"):
|
||||
train_step = tf.train.AdamOptimizer(
|
||||
config['learning_rate']).minimize(cross_entropy)
|
||||
config["learning_rate"]).minimize(cross_entropy)
|
||||
|
||||
self.train_step = train_step
|
||||
|
||||
with tf.name_scope('accuracy'):
|
||||
with tf.name_scope("accuracy"):
|
||||
correct_prediction = tf.equal(
|
||||
tf.argmax(y_conv, 1), tf.argmax(self.y_, 1))
|
||||
correct_prediction = tf.cast(correct_prediction, tf.float32)
|
||||
@@ -212,24 +212,24 @@ class TrainMNIST(Trainable):
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
'--smoke-test', action='store_true', help='Finish quickly for testing')
|
||||
"--smoke-test", action="store_true", help="Finish quickly for testing")
|
||||
args, _ = parser.parse_known_args()
|
||||
mnist_spec = {
|
||||
'stop': {
|
||||
'mean_accuracy': 0.99,
|
||||
'time_total_s': 600,
|
||||
"stop": {
|
||||
"mean_accuracy": 0.99,
|
||||
"time_total_s": 600,
|
||||
},
|
||||
'config': {
|
||||
'learning_rate': sample_from(
|
||||
"config": {
|
||||
"learning_rate": sample_from(
|
||||
lambda spec: 10**np.random.uniform(-5, -3)),
|
||||
'activation': grid_search(['relu', 'elu', 'tanh']),
|
||||
"activation": grid_search(["relu", "elu", "tanh"]),
|
||||
},
|
||||
"num_samples": 10,
|
||||
}
|
||||
|
||||
if args.smoke_test:
|
||||
mnist_spec['stop']['training_iteration'] = 20
|
||||
mnist_spec['num_samples'] = 2
|
||||
mnist_spec["stop"]["training_iteration"] = 20
|
||||
mnist_spec["num_samples"] = 2
|
||||
|
||||
ray.init()
|
||||
hyperband = HyperBandScheduler(
|
||||
@@ -237,6 +237,6 @@ if __name__ == "__main__":
|
||||
|
||||
tune.run(
|
||||
TrainMNIST,
|
||||
name='mnist_hyperband_test',
|
||||
name="mnist_hyperband_test",
|
||||
scheduler=hyperband,
|
||||
**mnist_spec)
|
||||
|
||||
@@ -148,8 +148,8 @@ class _LogSyncer(object):
|
||||
if not distutils.spawn.find_executable("rsync"):
|
||||
logger.error("Log sync requires rsync to be installed.")
|
||||
return
|
||||
source = '{}/'.format(self.local_dir)
|
||||
target = '{}@{}:{}/'.format(ssh_user, self.worker_ip, self.local_dir)
|
||||
source = "{}/".format(self.local_dir)
|
||||
target = "{}@{}:{}/".format(ssh_user, self.worker_ip, self.local_dir)
|
||||
final_cmd = (("""rsync -savz -e "ssh -i {} -o ConnectTimeout=120s """
|
||||
"""-o StrictHostKeyChecking=no" {} {}""").format(
|
||||
quote(ssh_key), quote(source), quote(target)))
|
||||
@@ -180,9 +180,9 @@ class _LogSyncer(object):
|
||||
if not distutils.spawn.find_executable("rsync"):
|
||||
logger.error("Log sync requires rsync to be installed.")
|
||||
return
|
||||
source = '{}@{}:{}/'.format(ssh_user, self.worker_ip,
|
||||
source = "{}@{}:{}/".format(ssh_user, self.worker_ip,
|
||||
self.local_dir)
|
||||
target = '{}/'.format(self.local_dir)
|
||||
target = "{}/".format(self.local_dir)
|
||||
worker_to_local_sync_cmd = ((
|
||||
"""rsync -savz -e "ssh -i {} -o ConnectTimeout=120s """
|
||||
"""-o StrictHostKeyChecking=no" {} {}""").format(
|
||||
|
||||
@@ -166,7 +166,7 @@ class RayTrialExecutor(TrialExecutor):
|
||||
|
||||
try:
|
||||
trial.write_error_log(error_msg)
|
||||
if hasattr(trial, 'runner') and trial.runner:
|
||||
if hasattr(trial, "runner") and trial.runner:
|
||||
if (not error and self._reuse_actors
|
||||
and self._cached_actor is None):
|
||||
logger.debug("Reusing actor for {}".format(trial.runner))
|
||||
|
||||
@@ -39,8 +39,8 @@ class AsyncHyperBandScheduler(FIFOScheduler):
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
time_attr='training_iteration',
|
||||
reward_attr='episode_reward_mean',
|
||||
time_attr="training_iteration",
|
||||
reward_attr="episode_reward_mean",
|
||||
max_t=100,
|
||||
grace_period=10,
|
||||
reduction_factor=3,
|
||||
|
||||
@@ -73,8 +73,8 @@ class HyperBandScheduler(FIFOScheduler):
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
time_attr='training_iteration',
|
||||
reward_attr='episode_reward_mean',
|
||||
time_attr="training_iteration",
|
||||
reward_attr="episode_reward_mean",
|
||||
max_t=81):
|
||||
assert max_t > 0, "Max (time_attr) not valid!"
|
||||
FIFOScheduler.__init__(self)
|
||||
|
||||
@@ -104,9 +104,9 @@ class MedianStoppingRule(FIFOScheduler):
|
||||
if len(scores) >= self._min_samples_required:
|
||||
return np.median(scores)
|
||||
else:
|
||||
return float('-inf')
|
||||
return float("-inf")
|
||||
|
||||
def _running_result(self, trial, t_max=float('inf')):
|
||||
def _running_result(self, trial, t_max=float("inf")):
|
||||
results = self._results[trial]
|
||||
# TODO(ekl) we could do interpolation to be more precise, but for now
|
||||
# assume len(results) is large and the time diffs are roughly equal
|
||||
|
||||
@@ -43,9 +43,9 @@ def list_trials(experiment_path, sort, output, filter_op, columns,
|
||||
result_columns):
|
||||
"""Lists trials in the directory subtree starting at the given path."""
|
||||
if columns:
|
||||
columns = columns.split(',')
|
||||
columns = columns.split(",")
|
||||
if result_columns:
|
||||
result_columns = result_columns.split(',')
|
||||
result_columns = result_columns.split(",")
|
||||
commands.list_trials(experiment_path, sort, output, filter_op, columns,
|
||||
result_columns)
|
||||
|
||||
@@ -75,7 +75,7 @@ def list_trials(experiment_path, sort, output, filter_op, columns,
|
||||
def list_experiments(project_path, sort, output, filter_op, columns):
|
||||
"""Lists experiments in the directory subtree."""
|
||||
if columns:
|
||||
columns = columns.split(',')
|
||||
columns = columns.split(",")
|
||||
commands.list_experiments(project_path, sort, output, filter_op, columns)
|
||||
|
||||
|
||||
|
||||
@@ -120,8 +120,8 @@ class HyperOptSearch(SuggestionAlgorithm):
|
||||
if ho_trial is None:
|
||||
return
|
||||
now = hpo.utils.coarse_utcnow()
|
||||
ho_trial['book_time'] = now
|
||||
ho_trial['refresh_time'] = now
|
||||
ho_trial["book_time"] = now
|
||||
ho_trial["refresh_time"] = now
|
||||
|
||||
def on_trial_complete(self,
|
||||
trial_id,
|
||||
@@ -136,17 +136,17 @@ class HyperOptSearch(SuggestionAlgorithm):
|
||||
ho_trial = self._get_hyperopt_trial(trial_id)
|
||||
if ho_trial is None:
|
||||
return
|
||||
ho_trial['refresh_time'] = hpo.utils.coarse_utcnow()
|
||||
ho_trial["refresh_time"] = hpo.utils.coarse_utcnow()
|
||||
if error:
|
||||
ho_trial['state'] = hpo.base.JOB_STATE_ERROR
|
||||
ho_trial['misc']['error'] = (str(TuneError), "Tune Error")
|
||||
ho_trial["state"] = hpo.base.JOB_STATE_ERROR
|
||||
ho_trial["misc"]["error"] = (str(TuneError), "Tune Error")
|
||||
elif early_terminated:
|
||||
ho_trial['state'] = hpo.base.JOB_STATE_ERROR
|
||||
ho_trial['misc']['error'] = (str(TuneError), "Tune Removed")
|
||||
ho_trial["state"] = hpo.base.JOB_STATE_ERROR
|
||||
ho_trial["misc"]["error"] = (str(TuneError), "Tune Removed")
|
||||
else:
|
||||
ho_trial['state'] = hpo.base.JOB_STATE_DONE
|
||||
ho_trial["state"] = hpo.base.JOB_STATE_DONE
|
||||
hp_result = self._to_hyperopt_result(result)
|
||||
ho_trial['result'] = hp_result
|
||||
ho_trial["result"] = hp_result
|
||||
self._hpopt_trials.refresh()
|
||||
del self._live_trial_mapping[trial_id]
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ class SigOptSearch(SuggestionAlgorithm):
|
||||
self._live_trial_mapping = {}
|
||||
|
||||
# Create a connection with SigOpt API, requires API key
|
||||
self.conn = sgo.Connection(client_token=os.environ['SIGOPT_KEY'])
|
||||
self.conn = sgo.Connection(client_token=os.environ["SIGOPT_KEY"])
|
||||
|
||||
self.experiment = self.conn.experiments().create(
|
||||
name=name,
|
||||
|
||||
@@ -17,26 +17,26 @@ class AutoMLSearcherTest(unittest.TestCase):
|
||||
register_trainable("f1", dummy_train)
|
||||
|
||||
def testExpandSearchSpace(self):
|
||||
exp = {"test-exp": {"run": "f1", "config": {"a": {'d': 'dummy'}}}}
|
||||
exp = {"test-exp": {"run": "f1", "config": {"a": {"d": "dummy"}}}}
|
||||
space = SearchSpace([
|
||||
DiscreteSpace('a.b.c', [1, 2]),
|
||||
DiscreteSpace('a.d', ['a', 'b']),
|
||||
DiscreteSpace("a.b.c", [1, 2]),
|
||||
DiscreteSpace("a.d", ["a", "b"]),
|
||||
])
|
||||
searcher = GridSearch(space, 'reward')
|
||||
searcher = GridSearch(space, "reward")
|
||||
searcher.add_configurations(exp)
|
||||
trials = searcher.next_trials()
|
||||
|
||||
self.assertEqual(len(trials), 4)
|
||||
self.assertTrue(trials[0].config['a']['b']['c'] in [1, 2])
|
||||
self.assertTrue(trials[1].config['a']['d'] in ['a', 'b'])
|
||||
self.assertTrue(trials[0].config["a"]["b"]["c"] in [1, 2])
|
||||
self.assertTrue(trials[1].config["a"]["d"] in ["a", "b"])
|
||||
|
||||
def testSearchRound(self):
|
||||
exp = {"test-exp": {"run": "f1", "config": {"a": {'d': 'dummy'}}}}
|
||||
exp = {"test-exp": {"run": "f1", "config": {"a": {"d": "dummy"}}}}
|
||||
space = SearchSpace([
|
||||
DiscreteSpace('a.b.c', [1, 2]),
|
||||
DiscreteSpace('a.d', ['a', 'b']),
|
||||
DiscreteSpace("a.b.c", [1, 2]),
|
||||
DiscreteSpace("a.d", ["a", "b"]),
|
||||
])
|
||||
searcher = GridSearch(space, 'reward')
|
||||
searcher = GridSearch(space, "reward")
|
||||
searcher.add_configurations(exp)
|
||||
trials = searcher.next_trials()
|
||||
|
||||
@@ -48,12 +48,12 @@ class AutoMLSearcherTest(unittest.TestCase):
|
||||
self.assertTrue(searcher.is_finished())
|
||||
|
||||
def testBestTrial(self):
|
||||
exp = {"test-exp": {"run": "f1", "config": {"a": {'d': 'dummy'}}}}
|
||||
exp = {"test-exp": {"run": "f1", "config": {"a": {"d": "dummy"}}}}
|
||||
space = SearchSpace([
|
||||
DiscreteSpace('a.b.c', [1, 2]),
|
||||
DiscreteSpace('a.d', ['a', 'b']),
|
||||
DiscreteSpace("a.b.c", [1, 2]),
|
||||
DiscreteSpace("a.d", ["a", "b"]),
|
||||
])
|
||||
searcher = GridSearch(space, 'reward')
|
||||
searcher = GridSearch(space, "reward")
|
||||
searcher.add_configurations(exp)
|
||||
trials = searcher.next_trials()
|
||||
|
||||
@@ -66,4 +66,4 @@ class AutoMLSearcherTest(unittest.TestCase):
|
||||
|
||||
best_trial = searcher.get_best_trial()
|
||||
self.assertEqual(best_trial, trials[-1])
|
||||
self.assertEqual(best_trial.best_result['reward'], 3 + 10 - 1)
|
||||
self.assertEqual(best_trial.best_result["reward"], 3 + 10 - 1)
|
||||
|
||||
@@ -90,7 +90,7 @@ def test_ls(start_ray, tmpdir):
|
||||
assert sum("TERMINATED" in line for line in lines) == num_samples
|
||||
columns = ["status", "episode_reward_mean", "training_iteration"]
|
||||
assert all(col in lines[1] for col in columns)
|
||||
assert lines[1].count('|') == 4
|
||||
assert lines[1].count("|") == 4
|
||||
|
||||
with Capturing() as output:
|
||||
commands.list_trials(
|
||||
@@ -123,7 +123,7 @@ def test_lsx(start_ray, tmpdir):
|
||||
lines = output.captured
|
||||
assert sum("1" in line for line in lines) >= num_experiments
|
||||
assert "total_trials" in lines[1]
|
||||
assert lines[1].count('|') == 2
|
||||
assert lines[1].count("|") == 2
|
||||
|
||||
with Capturing() as output:
|
||||
commands.list_experiments(
|
||||
|
||||
@@ -25,4 +25,4 @@ if __name__ == "__main__":
|
||||
}
|
||||
}
|
||||
})
|
||||
assert 'ray.rllib' not in sys.modules, "RLlib should not be imported"
|
||||
assert "ray.rllib" not in sys.modules, "RLlib should not be imported"
|
||||
|
||||
@@ -331,21 +331,21 @@ class TrainableFunctionApiTest(unittest.TestCase):
|
||||
self.assertFalse(trial.upload_dir)
|
||||
|
||||
def testLogdirStartingWithTilde(self):
|
||||
local_dir = '~/ray_results/local_dir'
|
||||
local_dir = "~/ray_results/local_dir"
|
||||
|
||||
def train(config, reporter):
|
||||
cwd = os.getcwd()
|
||||
assert cwd.startswith(os.path.expanduser(local_dir)), cwd
|
||||
assert not cwd.startswith('~'), cwd
|
||||
assert not cwd.startswith("~"), cwd
|
||||
reporter(timesteps_total=1)
|
||||
|
||||
register_trainable('f1', train)
|
||||
register_trainable("f1", train)
|
||||
run_experiments({
|
||||
'foo': {
|
||||
'run': 'f1',
|
||||
'local_dir': local_dir,
|
||||
'config': {
|
||||
'a': 'b'
|
||||
"foo": {
|
||||
"run": "f1",
|
||||
"local_dir": local_dir,
|
||||
"config": {
|
||||
"a": "b"
|
||||
},
|
||||
}
|
||||
})
|
||||
@@ -501,7 +501,7 @@ class TrainableFunctionApiTest(unittest.TestCase):
|
||||
def testReportInfinity(self):
|
||||
def train(config, reporter):
|
||||
for i in range(100):
|
||||
reporter(mean_accuracy=float('inf'))
|
||||
reporter(mean_accuracy=float("inf"))
|
||||
|
||||
register_trainable("f1", train)
|
||||
[trial] = run_experiments({
|
||||
@@ -510,7 +510,7 @@ class TrainableFunctionApiTest(unittest.TestCase):
|
||||
}
|
||||
})
|
||||
self.assertEqual(trial.status, Trial.TERMINATED)
|
||||
self.assertEqual(trial.last_result['mean_accuracy'], float('inf'))
|
||||
self.assertEqual(trial.last_result["mean_accuracy"], float("inf"))
|
||||
|
||||
def testReportTimeStep(self):
|
||||
# Test that no timestep count are logged if never the Trainable never
|
||||
@@ -1532,7 +1532,7 @@ class TrialRunnerTest(unittest.TestCase):
|
||||
runner.add_trial(Trial("__fake", **kwargs))
|
||||
trials = runner.get_trials()
|
||||
|
||||
with patch('ray.global_state.cluster_resources') as resource_mock:
|
||||
with patch("ray.global_state.cluster_resources") as resource_mock:
|
||||
resource_mock.return_value = {"CPU": 1, "GPU": 1}
|
||||
runner.step()
|
||||
self.assertEqual(trials[0].status, Trial.RUNNING)
|
||||
@@ -1717,12 +1717,12 @@ class TrialRunnerTest(unittest.TestCase):
|
||||
|
||||
def on_step_begin(self):
|
||||
self._update_avail_resources()
|
||||
cnt = self.pre_step if hasattr(self, 'pre_step') else 0
|
||||
setattr(self, 'pre_step', cnt + 1)
|
||||
cnt = self.pre_step if hasattr(self, "pre_step") else 0
|
||||
setattr(self, "pre_step", cnt + 1)
|
||||
|
||||
def on_step_end(self):
|
||||
cnt = self.pre_step if hasattr(self, 'post_step') else 0
|
||||
setattr(self, 'post_step', 1 + cnt)
|
||||
cnt = self.pre_step if hasattr(self, "post_step") else 0
|
||||
setattr(self, "post_step", 1 + cnt)
|
||||
|
||||
import types
|
||||
runner.trial_executor.on_step_begin = types.MethodType(
|
||||
|
||||
@@ -135,8 +135,8 @@ class EarlyStoppingSuite(unittest.TestCase):
|
||||
rule = MedianStoppingRule(
|
||||
grace_period=0,
|
||||
min_samples_required=1,
|
||||
time_attr='training_iteration',
|
||||
reward_attr='neg_mean_loss')
|
||||
time_attr="training_iteration",
|
||||
reward_attr="neg_mean_loss")
|
||||
t1 = Trial("PPO") # mean is 450, max 900, t_max=10
|
||||
t2 = Trial("PPO") # mean is 450, max 450, t_max=5
|
||||
for i in range(10):
|
||||
@@ -495,7 +495,7 @@ class HyperbandSuite(unittest.TestCase):
|
||||
return dict(time_total_s=t, neg_mean_loss=rew)
|
||||
|
||||
sched = HyperBandScheduler(
|
||||
time_attr='time_total_s', reward_attr='neg_mean_loss')
|
||||
time_attr="time_total_s", reward_attr="neg_mean_loss")
|
||||
stats = self.default_statistics()
|
||||
|
||||
for i in range(stats["max_trials"]):
|
||||
@@ -987,8 +987,8 @@ class AsyncHyperBandSuite(unittest.TestCase):
|
||||
|
||||
scheduler = AsyncHyperBandScheduler(
|
||||
grace_period=1,
|
||||
time_attr='training_iteration',
|
||||
reward_attr='neg_mean_loss',
|
||||
time_attr="training_iteration",
|
||||
reward_attr="neg_mean_loss",
|
||||
brackets=1)
|
||||
t1 = Trial("PPO") # mean is 450, max 900, t_max=10
|
||||
t2 = Trial("PPO") # mean is 450, max 450, t_max=5
|
||||
|
||||
@@ -69,8 +69,8 @@ class TuneServerSuite(unittest.TestCase):
|
||||
"training_iteration": 3
|
||||
},
|
||||
"resources_per_trial": {
|
||||
'cpu': 1,
|
||||
'gpu': 1
|
||||
"cpu": 1,
|
||||
"gpu": 1
|
||||
},
|
||||
}
|
||||
client.add_trial("test", spec)
|
||||
@@ -134,8 +134,8 @@ class TuneServerSuite(unittest.TestCase):
|
||||
for i in range(2):
|
||||
runner.step()
|
||||
stdout = subprocess.check_output(
|
||||
'curl "http://{}:{}/trials"'.format(client.server_address,
|
||||
client.server_port),
|
||||
"curl \"http://{}:{}/trials\"".format(client.server_address,
|
||||
client.server_port),
|
||||
shell=True)
|
||||
self.assertNotEqual(stdout, None)
|
||||
curl_trials = json.loads(stdout.decode())["trials"]
|
||||
|
||||
+14
-14
@@ -437,39 +437,39 @@ class Trial(object):
|
||||
|
||||
def location_string(hostname, pid):
|
||||
if hostname == os.uname()[1]:
|
||||
return 'pid={}'.format(pid)
|
||||
return "pid={}".format(pid)
|
||||
else:
|
||||
return '{} pid={}'.format(hostname, pid)
|
||||
return "{} pid={}".format(hostname, pid)
|
||||
|
||||
pieces = [
|
||||
'{}'.format(self._status_string()), '[{}]'.format(
|
||||
self.resources.summary_string()), '[{}]'.format(
|
||||
"{}".format(self._status_string()), "[{}]".format(
|
||||
self.resources.summary_string()), "[{}]".format(
|
||||
location_string(
|
||||
self.last_result.get(HOSTNAME),
|
||||
self.last_result.get(PID))), '{} s'.format(
|
||||
self.last_result.get(PID))), "{} s".format(
|
||||
int(self.last_result.get(TIME_TOTAL_S)))
|
||||
]
|
||||
|
||||
if self.last_result.get(TRAINING_ITERATION) is not None:
|
||||
pieces.append('{} iter'.format(
|
||||
pieces.append("{} iter".format(
|
||||
self.last_result[TRAINING_ITERATION]))
|
||||
|
||||
if self.last_result.get(TIMESTEPS_TOTAL) is not None:
|
||||
pieces.append('{} ts'.format(self.last_result[TIMESTEPS_TOTAL]))
|
||||
pieces.append("{} ts".format(self.last_result[TIMESTEPS_TOTAL]))
|
||||
|
||||
if self.last_result.get(EPISODE_REWARD_MEAN) is not None:
|
||||
pieces.append('{} rew'.format(
|
||||
format(self.last_result[EPISODE_REWARD_MEAN], '.3g')))
|
||||
pieces.append("{} rew".format(
|
||||
format(self.last_result[EPISODE_REWARD_MEAN], ".3g")))
|
||||
|
||||
if self.last_result.get(MEAN_LOSS) is not None:
|
||||
pieces.append('{} loss'.format(
|
||||
format(self.last_result[MEAN_LOSS], '.3g')))
|
||||
pieces.append("{} loss".format(
|
||||
format(self.last_result[MEAN_LOSS], ".3g")))
|
||||
|
||||
if self.last_result.get(MEAN_ACCURACY) is not None:
|
||||
pieces.append('{} acc'.format(
|
||||
format(self.last_result[MEAN_ACCURACY], '.3g')))
|
||||
pieces.append("{} acc".format(
|
||||
format(self.last_result[MEAN_ACCURACY], ".3g")))
|
||||
|
||||
return ', '.join(pieces)
|
||||
return ", ".join(pieces)
|
||||
|
||||
def _status_string(self):
|
||||
return "{}{}".format(
|
||||
|
||||
@@ -127,7 +127,7 @@ class TrialRunner(object):
|
||||
# For debugging, it may be useful to halt trials after some time has
|
||||
# elapsed. TODO(ekl) consider exposing this in the API.
|
||||
self._global_time_limit = float(
|
||||
os.environ.get("TRIALRUNNER_WALLTIME_LIMIT", float('inf')))
|
||||
os.environ.get("TRIALRUNNER_WALLTIME_LIMIT", float("inf")))
|
||||
self._total_time = 0
|
||||
self._iteration = 0
|
||||
self._verbose = verbose
|
||||
|
||||
@@ -110,7 +110,7 @@ def RunnerHandler(runner):
|
||||
headers (list[tuples]): Standard HTTP response headers
|
||||
"""
|
||||
if headers is None:
|
||||
headers = [('Content-type', 'application/json')]
|
||||
headers = [("Content-type", "application/json")]
|
||||
|
||||
self.send_response(response_code)
|
||||
for key, value in headers:
|
||||
@@ -170,14 +170,14 @@ def RunnerHandler(runner):
|
||||
"""HTTP POST handler method."""
|
||||
response_code = 201
|
||||
|
||||
content_len = int(self.headers.get('Content-Length'), 0)
|
||||
content_len = int(self.headers.get("Content-Length"), 0)
|
||||
raw_body = self.rfile.read(content_len)
|
||||
parsed_input = json.loads(raw_body.decode())
|
||||
resource = self._add_trials(parsed_input["name"],
|
||||
parsed_input["spec"])
|
||||
|
||||
headers = [('Content-type', 'application/json'), ('Location',
|
||||
'/trials/')]
|
||||
headers = [("Content-type", "application/json"), ("Location",
|
||||
"/trials/")]
|
||||
self._do_header(response_code=response_code, headers=headers)
|
||||
self.wfile.write(json.dumps(resource).encode())
|
||||
|
||||
@@ -237,7 +237,7 @@ class TuneServer(threading.Thread):
|
||||
"""Initialize HTTPServer and serve forever by invoking self.run()"""
|
||||
threading.Thread.__init__(self)
|
||||
self._port = port if port else self.DEFAULT_PORT
|
||||
address = ('localhost', self._port)
|
||||
address = ("localhost", self._port)
|
||||
logger.info("Starting Tune Server...")
|
||||
self._server = HTTPServer(address, RunnerHandler(runner))
|
||||
self.daemon = True
|
||||
|
||||
Reference in New Issue
Block a user