Add check for dependent packages of tuners before starting restful server (#570)

* add module info for launcher check

* update launcher.py

Add packages check before start restful server.

* check sub-key

* modify mistype

* delete non-tuner in constants/ModuleName

* Delete ModuleName to prevent double maintain

* only catch ModuleNotFoundError
This commit is contained in:
Linjie Xu 2019-01-11 13:26:41 +08:00 коммит произвёл chicm-ms
Родитель c288a16e94
Коммит 0405a426cc
2 изменённых файлов: 15 добавлений и 2 удалений

Просмотреть файл

@ -81,4 +81,4 @@ COLOR_RED_FORMAT = '\033[1;31;31m%s\033[0m'
COLOR_GREEN_FORMAT = '\033[1;32;32m%s\033[0m'
COLOR_YELLOW_FORMAT = '\033[1;33;33m%s\033[0m'
COLOR_YELLOW_FORMAT = '\033[1;33;33m%s\033[0m'

Просмотреть файл

@ -21,10 +21,12 @@
import json
import os
import sys
import shutil
import string
from subprocess import Popen, PIPE, call, check_output
from subprocess import Popen, PIPE, call, check_output, check_call
import tempfile
from nni.constants import ModuleName
from nni_annotation import *
from .launcher_utils import validate_all_content
from .rest_utils import rest_put, rest_post, check_rest_server, check_rest_server_quick, check_response
@ -282,6 +284,17 @@ def set_experiment(experiment_config, mode, port, config_file_name):
def launch_experiment(args, experiment_config, mode, config_file_name, experiment_id=None):
'''follow steps to start rest server and start experiment'''
nni_config = Config(config_file_name)
# check packages for tuner
if experiment_config.get('tuner') and experiment_config['tuner'].get('builtinTunerName'):
tuner_name = experiment_config['tuner']['builtinTunerName']
module_name = ModuleName[tuner_name]
try:
check_call([sys.executable, '-c', 'import %s'%(module_name)])
except ModuleNotFoundError as e:
print_error('The tuner %s should be installed through nnictl'%(tuner_name))
exit(1)
# start rest server
rest_process, start_time = start_rest_server(args.port, experiment_config['trainingServicePlatform'], mode, config_file_name, experiment_id)
nni_config.set_config('restServerPid', rest_process.pid)