Esempio n. 1
0
def inference_handler(model_dir):
    if not os.path.exists(model_dir):
        raise ValueError(
            "Model directory [{}] does not exist".format(model_dir))
    try:
        from sagemaker_inference.default_handler_service import DefaultHandlerService
    except ImportError:
        raise click.UsageError(
            "Install sagemaker-inference to use local inference")

    sys.path.insert(0, os.path.join(model_dir, 'code'))
    handler = DefaultHandlerService()
    try:
        from mms.context import Context
    except ImportError:
        raise click.UsageError(
            "Install multi-model-server to use local inference")
    context = Context(
        model_name='local-model',
        model_dir=model_dir,
        manifest=None,
        batch_size=None,
        gpu=None,
        mms_version=None
    )
    handler.initialize(context)
    return handler, context
Esempio n. 2
0
def my_ctx():
    model_dir = os.path.join(os.path.dirname(__file__), 'resources')
    return Context(model_name='test',
                   model_dir=model_dir,
                   manifest='manifest',
                   batch_size=1,
                   gpu=0,
                   mms_version='1.0.3')
Esempio n. 3
0
 def __init__(self, model_name, model_dir, manifest, entry_point, gpu, batch_size):
     self._context = Context(model_name, model_dir, manifest, batch_size, gpu, mms.__version__)
     self._entry_point = entry_point
 def service(self, mocker):
     service = object.__new__(Service)
     service._entry_point = mocker.MagicMock(return_value=['prediction'])
     service._context = Context(self.model_name, self.model_dir,
                                self.manifest, 1, 0, '1.0')
     return service