def test_model_spec(): ms = ModelSpec( model_details=ModelDetails( name="test", local_folder="", uri="", platform=ModelFramework.XGBoost, inputs=ModelDataArgs(args=[ModelDataArg(ty=str)]), outputs=ModelDataArgs(args=[]), ), protocol=V2Protocol(), runtime_options=KFServingOptions().local_options, ) s = ms.json() j = json.loads(s) ms2 = ModelSpec(**j) assert isinstance(ms2.protocol, V2Protocol) assert ms2.model_details.inputs.args[0].ty == str
def test_tensorflow_spec(): md = ModelDetails( name="test", local_folder="", uri="", platform=ModelFramework.Tensorflow, inputs=ModelDataArgs(args=[]), outputs=ModelDataArgs(args=[]), ) protocol = SeldonProtocol() options = KubernetesOptions(namespace="production", replicas=1) runtime_options = RuntimeOptions(k8s_options=options) model_spec = ModelSpec(model_details=md, protocol=protocol, runtime_options=runtime_options) spec = get_container_spec(model_spec) assert "image" in spec assert "command" in spec
def deserialize(d: dict, client_details: ClientDetails = None) -> ClientModel: ms = ModelSpec(**d) return ClientModel(ms, client_details=client_details)
def _get_spec(self, model_spec: ModelSpec) -> dict: if model_spec.model_details.platform == ModelFramework.TempoPipeline: serviceAccountName = model_spec.runtime_options.k8s_options.serviceAccountName if serviceAccountName is None: serviceAccountName = DefaultServiceAccountName return { "apiVersion": "serving.kubeflow.org/v1beta1", "kind": "InferenceService", "metadata": { "name": model_spec.model_details.name, "namespace": model_spec.runtime_options.k8s_options.namespace, "labels": { TempoK8sLabel: "true", }, "annotations": { TempoK8sDescriptionAnnotation: model_spec.model_details.description, TempoK8sModelSpecAnnotation: model_spec.json(), }, }, "spec": { "predictor": { "serviceAccountName": serviceAccountName, "containers": [ { "image": MLSERVER_IMAGE, "name": "mlserver", "env": [ { "name": "STORAGE_URI", "value": model_spec.model_details.uri, }, { "name": "MLSERVER_HTTP_PORT", "value": DefaultHTTPPort, }, { "name": "MLSERVER_GRPC_PORT", "value": DefaultGRPCPort, }, { "name": "MLSERVER_MODEL_IMPLEMENTATION", "value": "tempo.mlserver.InferenceRuntime", }, { "name": "MLSERVER_MODEL_NAME", "value": model_spec.model_details.name, }, { "name": "MLSERVER_MODEL_URI", "value": DefaultModelsPath, }, { "name": ENV_TEMPO_RUNTIME_OPTIONS, "value": json.dumps(model_spec.runtime_options.dict()), }, ], }, ], }, }, } elif model_spec.model_details.platform in Implementations: model_implementation = Implementations[model_spec.model_details.platform] spec: Dict = { "apiVersion": "serving.kubeflow.org/v1beta1", "kind": "InferenceService", "metadata": { "name": model_spec.model_details.name, "namespace": model_spec.runtime_options.k8s_options.namespace, "labels": { TempoK8sLabel: "true", }, "annotations": { TempoK8sDescriptionAnnotation: model_spec.model_details.description, TempoK8sModelSpecAnnotation: model_spec.json(), }, }, "spec": { "predictor": { model_implementation: {"storageUri": model_spec.model_details.uri}, }, }, } if model_spec.runtime_options.k8s_options.serviceAccountName is not None: spec["spec"]["predictor"][ "serviceAccountName" ] = model_spec.runtime_options.k8s_options.serviceAccountName if isinstance(model_spec.protocol, KFServingV2Protocol): spec["spec"]["predictor"][model_implementation]["protocolVersion"] = "v2" return spec else: raise ValueError( "Can't create spec for implementation ", model_spec.model_details.platform, )
def deserialize(d: dict) -> DeployedModel: ms = ModelSpec(**d) return DeployedModel(ms)