def __init__(self, app_name='mms', args=None, models=None): """Initialize mxnet model server application. Parameters ---------- app_name : str App name to initialize mms service. args : List of str Arguments for starting service. By default it is None and commandline arguments will be used. It should follow the format recognized by python argparse parse_args method: https://docs.python.org/3/library/argparse.html#argparse.ArgumentParser.parse_args. An example for mms arguments: ['--models', 'resnet-18=path1', 'inception_v3=path2', '--gen-api', 'java', '--port', '8080'] """ # Initialize serving frontend and arg parser try: # Args passed as Namespace object self.args = args if args else ArgParser.extract_args() self.serving_frontend = ServingFrontend(app_name) self.gpu = self.args.gpu self.models = models # Setup root logger handler and level. log_file = self.args.log_file log_level = self.args.log_level or "INFO" log_rotation_time = self.args.log_rotation_time or "1 H" _set_root_logger(log_file, log_level, log_rotation_time) logger.info('Initialized model serving.') except Exception as e: # pylint: disable=broad-except print('Failed to initialize model serving: ' + str(e)) exit(1)
def start_serving(app_name='mms', args=None): """Start service routing. Parameters ---------- app_name : str App name to initialize mms service. args : List of str Arguments for starting service. By default it is None and commandline arguments will be used. It should follow the format recognized by python argparse parse_args method: https://docs.python.org/3/library/argparse.html#argparse.ArgumentParser.parse_args. An example for mms arguments: ['--models', 'resnet-18=path1', 'inception_v3=path2', '--gen-api', 'java', '--port', '8080'] """ # Parse the given arguments arguments = ArgParser.extract_args(args) # Download and/or Extract the given model files models = ModelLoader.load(arguments.models) # Instantiate an MMS object and prepare to start serving mms = MMS(app_name, args=arguments, models=models) mms.start_model_serving()
content = [line.rstrip() for line in content] for i, line in enumerate(content): line = line.lstrip() if line.startswith('#') or line.startswith('$'): continue if line.startswith('['): found_mms_args = 1 if mms_arg_header.lower() in line.lower() else 0 if found_mms_args is 1: if line.startswith('--') and content[i+1] != 'optional': args.append(line) if line.startswith('--model'): args += content[i + 1].split(' ') else: args.append(content[i + 1]) except Exception as e: sys.exit("ERROR: Cannot read the open file.") if is_gpu_image == 1: args.append('--gpu') args.append(int(os.environ['gpu_id'])) os.environ['gpu_id'] = str(int(os.environ['gpu_id']) + 1) # Extract the model's metadata from the file models = read_models_from_file() # Parse the arguments arguments = ArgParser.extract_args(args) # Instantiate the MMS object to start the MMS app server = mxnet_model_server.MMS(args=arguments, models=models) application = server.create_app()