Ejemplo n.º 1
0
 def test_list_models(self):
     model_loader = ModelLoaderFactory.get_model_loader("mms")
     sys.path.append(os.path.abspath('mms/tests/unit_tests/test_utils/'))
     module = importlib.import_module('dummy_class_model_service')
     classes = model_loader.list_model_services(module)
     assert len(classes) == 1
     assert classes[0].__name__ == 'CustomService'
Ejemplo n.º 2
0
    def load_model(load_model_request):
        """
        Expected command
        {
            "command" : "load", string
            "modelPath" : "/path/to/model/file", string
            "modelName" : "name", string
            "gpu" : None if CPU else gpu_id, int
            "handler" : service handler entry point if provided, string
            "batchSize" : batch size, int
        }

        :param load_model_request:
        :return:
        """
        model_dir = load_model_request["modelPath"].decode("utf-8")
        model_name = load_model_request["modelName"].decode("utf-8")
        handler = load_model_request["handler"].decode("utf-8")
        batch_size = None
        if "batchSize" in load_model_request:
            batch_size = int(load_model_request["batchSize"])

        gpu = None
        if "gpu" in load_model_request:
            gpu = int(load_model_request["gpu"])

        model_loader = ModelLoaderFactory.get_model_loader(model_dir)
        service = model_loader.load(model_name, model_dir, handler, gpu, batch_size)
        return service, "loaded model {}".format(model_name), 200
 def test_list_models_legacy(self):
     model_loader = ModelLoaderFactory.get_model_loader("legacy_mms")
     sys.path.append(os.path.abspath('mms/tests/unit_tests/model_service/dummy_model'))
     module = importlib.import_module('dummy_model_service')
     classes = model_loader.list_model_services(module, SingleNodeService)
     assert len(classes) == 1
     assert issubclass(classes[0], SingleNodeService)
 def test_load_func_model_with_error(self, patches):
     patches.mock_open.side_effect = [mock.mock_open(read_data=self.mock_manifest).return_value]
     sys.path.append(os.path.abspath('mms/tests/unit_tests/test_utils/'))
     patches.os_path.return_value = True
     handler = 'dummy_func_model_service:wrong'
     model_loader = ModelLoaderFactory.get_model_loader(os.path.abspath('mms/unit_tests/test_utils/'))
     with pytest.raises(ValueError, match=r"Expected only one class .*"):
         model_loader.load(self.model_name, self.model_dir, handler, 0, 1)
    def test_load_class_model(self, patches):
        patches.mock_open.side_effect = [mock.mock_open(read_data=self.mock_manifest).return_value]
        sys.path.append(os.path.abspath('mms/tests/unit_tests/test_utils/'))
        patches.os_path.return_value = True
        handler = 'dummy_class_model_service'
        model_loader = ModelLoaderFactory.get_model_loader(os.path.abspath('mms/unit_tests/test_utils/'))
        service = model_loader.load(self.model_name, self.model_dir, handler, 0, 1)

        assert inspect.ismethod(service._entry_point)
    def test_load_func_model(self, patches):
        patches.mock_open.side_effect = [mock.mock_open(read_data=self.mock_manifest).return_value]
        sys.path.append(os.path.abspath('mms/tests/unit_tests/test_utils/'))
        patches.os_path.return_value = True
        handler = 'dummy_func_model_service:infer'
        model_loader = ModelLoaderFactory.get_model_loader(os.path.abspath('mms/unit_tests/test_utils/'))
        service = model_loader.load(self.model_name, self.model_dir, handler, 0, 1)

        assert isinstance(service._entry_point, types.FunctionType)
        assert service._entry_point.__name__ == 'infer'
    def test_load_model_legacy(self, patches):
        patches.mock_open.side_effect = [mock.mock_open(read_data=self.mock_manifest).return_value]
        patches.open_signature.side_effect = [mock.mock_open(read_data='{}').return_value]
        patches.is_file.return_value = True
        patches.os_path.return_value = False
        sys.path.append(self.model_dir)
        handler = 'dummy_model_service'
        model_loader = ModelLoaderFactory.get_model_loader(self.model_dir)
        service = model_loader.load(self.model_name, self.model_dir, handler, 0, 1)

        assert inspect.ismethod(service._entry_point)
Ejemplo n.º 8
0
    def load_model(self, load_model_request=None):
        """
        Expected command
        {
            "command" : "load", string
            "modelPath" : "/path/to/model/file", string
            "modelName" : "name", string
            "gpu" : None if CPU else gpu_id, int
            "handler" : service handler entry point if provided, string
            "batchSize" : batch size, int
        }

        :param load_model_request:
        :return:
        """
        try:
            model_dir = load_model_request["modelPath"].decode("utf-8")
            model_name = load_model_request["modelName"].decode("utf-8")
            handler = load_model_request["handler"].decode("utf-8")
            batch_size = 1
            if "batchSize" in load_model_request:
                batch_size = int(load_model_request["batchSize"])

            gpu = None
            if "gpu" in load_model_request:
                gpu = int(load_model_request["gpu"])
            io_fd = None
            if "ioFileDescriptor" in load_model_request:
                io_fd = load_model_request.get("ioFileDescriptor").decode(
                    "utf-8")
                self._create_io_files(self.tmp_dir, io_fd)
            if self.service is None or self.preload is False:
                self.model_loader = ModelLoaderFactory.get_model_loader(
                    model_dir)
                self.service = self.model_loader.load(model_name, model_dir,
                                                      handler, gpu, batch_size)
                logging.info("Model %s loaded io_fd=%s", model_name,
                             str(io_fd))
            return "loaded model {}. [PID]:{}".format(model_name,
                                                      os.getpid()), 200

        except MemoryError:
            return "System out of memory", 507
Ejemplo n.º 9
0
    def test_model_loader_factory(self):
        model_loader = ModelLoaderFactory.get_model_loader(
            os.path.abspath('mms/tests/unit_tests/test_utils/'))

        assert isinstance(model_loader, MmsModelLoader)
Ejemplo n.º 10
0
    def test_model_loader_factory_legacy(self):
        model_loader = ModelLoaderFactory.get_model_loader(
            os.path.abspath('mms/tests/unit_tests/model_service/dummy_model'))

        assert isinstance(model_loader, LegacyModelLoader)