Search in sources :

Example 1 with PredictorSpec

use of io.seldon.protos.DeploymentProtos.PredictorSpec in project seldon-core by SeldonIO.

the class SeldonDeploymentOperatorImpl method defaulting.

@Override
public SeldonDeployment defaulting(SeldonDeployment mlDep) {
    SeldonDeployment.Builder mlBuilder = SeldonDeployment.newBuilder(mlDep);
    int idx = 0;
    String serviceName = mlDep.getSpec().getName();
    String deploymentName = mlDep.getMetadata().getName();
    for (PredictorSpec p : mlDep.getSpec().getPredictorsList()) {
        ObjectMeta.Builder metaBuilder = ObjectMeta.newBuilder(p.getComponentSpec().getMetadata()).putLabels(LABEL_SELDON_APP, serviceName);
        mlBuilder.getSpecBuilder().getPredictorsBuilder(idx).getComponentSpecBuilder().setMetadata(metaBuilder);
        int cIdx = 0;
        mlBuilder.getSpecBuilder().getPredictorsBuilder(idx).getComponentSpecBuilder().getSpecBuilder().clearContainers();
        String predictorName = p.getName();
        for (V1.Container c : p.getComponentSpec().getSpec().getContainersList()) {
            V1.Container c2 = this.updateContainer(c, findPredictiveUnitForContainer(mlDep.getSpec().getPredictors(idx).getGraph(), c.getName()), cIdx, deploymentName, predictorName);
            mlBuilder.getSpecBuilder().getPredictorsBuilder(idx).getComponentSpecBuilder().getSpecBuilder().addContainers(cIdx, c2);
            updatePredictiveUnitBuilderByName(mlBuilder.getSpecBuilder().getPredictorsBuilder(idx).getGraphBuilder(), c2);
            cIdx++;
        }
        idx++;
    }
    return mlBuilder.build();
}
Also used : ObjectMeta(io.kubernetes.client.proto.Meta.ObjectMeta) IntOrString(io.kubernetes.client.proto.IntStr.IntOrString) V1(io.kubernetes.client.proto.V1) SeldonDeployment(io.seldon.protos.DeploymentProtos.SeldonDeployment) Endpoint(io.seldon.protos.DeploymentProtos.Endpoint) PredictorSpec(io.seldon.protos.DeploymentProtos.PredictorSpec)

Example 2 with PredictorSpec

use of io.seldon.protos.DeploymentProtos.PredictorSpec in project seldon-core by SeldonIO.

the class SimpleModelUnitTest method simpleTest.

@Test
public void simpleTest() throws InterruptedException, ExecutionException, InvalidProtocolBufferException {
    PredictorSpec.Builder PredictorSpecBuilder = PredictorSpec.newBuilder();
    // PredictorSpecBuilder.setEnabled(true);
    PredictorSpecBuilder.setName("p1");
    // PredictorSpecBuilder.setRoot("1");
    PredictorSpecBuilder.setReplicas(1);
    PredictorSpecBuilder.setComponentSpec(PodTemplateSpec.newBuilder());
    PredictiveUnit.Builder PredictiveUnitBuilder = PredictiveUnit.newBuilder();
    PredictiveUnitBuilder.setName("1");
    PredictiveUnitBuilder.setType(PredictiveUnit.PredictiveUnitType.MODEL);
    PredictiveUnitBuilder.setImplementation(PredictiveUnit.PredictiveUnitImplementation.SIMPLE_MODEL);
    PredictorSpecBuilder.setGraph(PredictiveUnitBuilder.build());
    PredictorSpec predictor = PredictorSpecBuilder.build();
    PredictorState predictorState = predictorBean.predictorStateFromPredictorSpec(predictor);
    SeldonMessage p = SeldonMessage.newBuilder().build();
    SeldonMessage predictorReturn = predictorBean.predict(p, predictorState);
    Assert.assertEquals((double) SimpleModelUnit.values[0], predictorReturn.getData().getTensor().getValues(0), 0);
    Assert.assertEquals((double) SimpleModelUnit.values[1], predictorReturn.getData().getTensor().getValues(1), 0);
    Assert.assertEquals((double) SimpleModelUnit.values[2], predictorReturn.getData().getTensor().getValues(2), 0);
}
Also used : SeldonMessage(io.seldon.protos.PredictionProtos.SeldonMessage) PredictiveUnit(io.seldon.protos.DeploymentProtos.PredictiveUnit) PredictorSpec(io.seldon.protos.DeploymentProtos.PredictorSpec) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with PredictorSpec

use of io.seldon.protos.DeploymentProtos.PredictorSpec in project seldon-core by SeldonIO.

the class RandomABTestUnitTest method simpleTest.

@Test
public void simpleTest() throws InterruptedException, ExecutionException, InvalidProtocolBufferException {
    PredictorSpec.Builder predictorSpecBuilder = PredictorSpec.newBuilder();
    predictorSpecBuilder.setName("p1");
    predictorSpecBuilder.setReplicas(1);
    predictorSpecBuilder.setComponentSpec(PodTemplateSpec.newBuilder());
    PredictiveUnit.Builder predictiveUnitBuilder = PredictiveUnit.newBuilder();
    predictiveUnitBuilder.setName("1");
    predictiveUnitBuilder.setType(PredictiveUnit.PredictiveUnitType.MODEL);
    predictiveUnitBuilder.setImplementation(PredictiveUnit.PredictiveUnitImplementation.SIMPLE_MODEL);
    PredictiveUnit pu1 = predictiveUnitBuilder.build();
    predictiveUnitBuilder = PredictiveUnit.newBuilder();
    predictiveUnitBuilder.setName("2");
    predictiveUnitBuilder.setType(PredictiveUnit.PredictiveUnitType.MODEL);
    predictiveUnitBuilder.setImplementation(PredictiveUnit.PredictiveUnitImplementation.SIMPLE_MODEL);
    PredictiveUnit pu2 = predictiveUnitBuilder.build();
    predictiveUnitBuilder = PredictiveUnit.newBuilder();
    predictiveUnitBuilder.setName("3");
    predictiveUnitBuilder.setType(PredictiveUnit.PredictiveUnitType.ROUTER);
    predictiveUnitBuilder.setImplementation(PredictiveUnit.PredictiveUnitImplementation.RANDOM_ABTEST);
    predictiveUnitBuilder.addChildren(pu1);
    predictiveUnitBuilder.addChildren(pu2);
    Parameter.Builder pBuilder = Parameter.newBuilder().setName("ratioA").setValue("0.5").setType(ParameterType.FLOAT);
    predictiveUnitBuilder.addParameters(pBuilder.build());
    PredictiveUnit pu3 = predictiveUnitBuilder.build();
    predictorSpecBuilder.setGraph(pu3);
    PredictorSpec predictor = predictorSpecBuilder.build();
    PredictorState predictorState = predictorBean.predictorStateFromPredictorSpec(predictor);
    SeldonMessage p = SeldonMessage.newBuilder().build();
    SeldonMessage predictorReturn = predictorBean.predict(p, predictorState);
    Assert.assertEquals((double) SimpleModelUnit.values[0], predictorReturn.getData().getTensor().getValues(0), 0);
    Assert.assertEquals((double) SimpleModelUnit.values[1], predictorReturn.getData().getTensor().getValues(1), 0);
    Assert.assertEquals((double) SimpleModelUnit.values[2], predictorReturn.getData().getTensor().getValues(2), 0);
}
Also used : SeldonMessage(io.seldon.protos.PredictionProtos.SeldonMessage) PredictiveUnit(io.seldon.protos.DeploymentProtos.PredictiveUnit) Parameter(io.seldon.protos.DeploymentProtos.Parameter) PredictorSpec(io.seldon.protos.DeploymentProtos.PredictorSpec) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with PredictorSpec

use of io.seldon.protos.DeploymentProtos.PredictorSpec in project seldon-core by SeldonIO.

the class SimpleModelUnitTest method simpleTestWithImageNoVersion.

@Test
public void simpleTestWithImageNoVersion() throws InterruptedException, ExecutionException, InvalidProtocolBufferException {
    PredictorSpec.Builder PredictorSpecBuilder = PredictorSpec.newBuilder();
    // PredictorSpecBuilder.setEnabled(true);
    PredictorSpecBuilder.setName("p1");
    // PredictorSpecBuilder.setRoot("1");
    PredictorSpecBuilder.setReplicas(1);
    final String imageName = "myimage";
    PodTemplateSpec.Builder ptsBuilder = PodTemplateSpec.newBuilder().setSpec(PodSpec.newBuilder().addContainers(Container.newBuilder().setImage(imageName).setName("1")));
    PredictorSpecBuilder.setComponentSpec(ptsBuilder);
    PredictiveUnit.Builder PredictiveUnitBuilder = PredictiveUnit.newBuilder();
    PredictiveUnitBuilder.setName("1");
    PredictiveUnitBuilder.setType(PredictiveUnit.PredictiveUnitType.MODEL);
    PredictiveUnitBuilder.setImplementation(PredictiveUnit.PredictiveUnitImplementation.SIMPLE_MODEL);
    PredictorSpecBuilder.setGraph(PredictiveUnitBuilder.build());
    PredictorSpec predictor = PredictorSpecBuilder.build();
    PredictorState predictorState = predictorBean.predictorStateFromPredictorSpec(predictor);
    Assert.assertEquals(imageName, predictorState.getRootState().imageName);
    Assert.assertEquals("", predictorState.getRootState().imageVersion);
    SeldonMessage p = SeldonMessage.newBuilder().build();
    SeldonMessage predictorReturn = predictorBean.predict(p, predictorState);
    Assert.assertEquals((double) SimpleModelUnit.values[0], predictorReturn.getData().getTensor().getValues(0), 0);
    Assert.assertEquals((double) SimpleModelUnit.values[1], predictorReturn.getData().getTensor().getValues(1), 0);
    Assert.assertEquals((double) SimpleModelUnit.values[2], predictorReturn.getData().getTensor().getValues(2), 0);
}
Also used : PodTemplateSpec(io.kubernetes.client.proto.V1.PodTemplateSpec) SeldonMessage(io.seldon.protos.PredictionProtos.SeldonMessage) PredictiveUnit(io.seldon.protos.DeploymentProtos.PredictiveUnit) PredictorSpec(io.seldon.protos.DeploymentProtos.PredictorSpec) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with PredictorSpec

use of io.seldon.protos.DeploymentProtos.PredictorSpec in project seldon-core by SeldonIO.

the class SimpleModelUnitTest method simpleTestWithImageVersion.

@Test
public void simpleTestWithImageVersion() throws InterruptedException, ExecutionException, InvalidProtocolBufferException {
    PredictorSpec.Builder PredictorSpecBuilder = PredictorSpec.newBuilder();
    // PredictorSpecBuilder.setEnabled(true);
    PredictorSpecBuilder.setName("p1");
    // PredictorSpecBuilder.setRoot("1");
    PredictorSpecBuilder.setReplicas(1);
    final String imageName = "myimage";
    final String imageVersion = "0.1";
    PodTemplateSpec.Builder ptsBuilder = PodTemplateSpec.newBuilder().setSpec(PodSpec.newBuilder().addContainers(Container.newBuilder().setImage(imageName + ":" + imageVersion).setName("1")));
    PredictorSpecBuilder.setComponentSpec(ptsBuilder);
    PredictiveUnit.Builder PredictiveUnitBuilder = PredictiveUnit.newBuilder();
    PredictiveUnitBuilder.setName("1");
    PredictiveUnitBuilder.setType(PredictiveUnit.PredictiveUnitType.MODEL);
    PredictiveUnitBuilder.setImplementation(PredictiveUnit.PredictiveUnitImplementation.SIMPLE_MODEL);
    PredictorSpecBuilder.setGraph(PredictiveUnitBuilder.build());
    PredictorSpec predictor = PredictorSpecBuilder.build();
    PredictorState predictorState = predictorBean.predictorStateFromPredictorSpec(predictor);
    Assert.assertEquals(imageName, predictorState.getRootState().imageName);
    Assert.assertEquals(imageVersion, predictorState.getRootState().imageVersion);
    SeldonMessage p = SeldonMessage.newBuilder().build();
    SeldonMessage predictorReturn = predictorBean.predict(p, predictorState);
    Assert.assertEquals((double) SimpleModelUnit.values[0], predictorReturn.getData().getTensor().getValues(0), 0);
    Assert.assertEquals((double) SimpleModelUnit.values[1], predictorReturn.getData().getTensor().getValues(1), 0);
    Assert.assertEquals((double) SimpleModelUnit.values[2], predictorReturn.getData().getTensor().getValues(2), 0);
}
Also used : PodTemplateSpec(io.kubernetes.client.proto.V1.PodTemplateSpec) SeldonMessage(io.seldon.protos.PredictionProtos.SeldonMessage) PredictiveUnit(io.seldon.protos.DeploymentProtos.PredictiveUnit) PredictorSpec(io.seldon.protos.DeploymentProtos.PredictorSpec) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

PredictorSpec (io.seldon.protos.DeploymentProtos.PredictorSpec)7 PredictiveUnit (io.seldon.protos.DeploymentProtos.PredictiveUnit)4 SeldonMessage (io.seldon.protos.PredictionProtos.SeldonMessage)4 Test (org.junit.Test)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 PodTemplateSpec (io.kubernetes.client.proto.V1.PodTemplateSpec)3 IntOrString (io.kubernetes.client.proto.IntStr.IntOrString)2 SeldonDeployment (io.seldon.protos.DeploymentProtos.SeldonDeployment)2 V1OwnerReference (io.kubernetes.client.models.V1OwnerReference)1 ObjectMeta (io.kubernetes.client.proto.Meta.ObjectMeta)1 OwnerReference (io.kubernetes.client.proto.Meta.OwnerReference)1 V1 (io.kubernetes.client.proto.V1)1 Service (io.kubernetes.client.proto.V1.Service)1 Deployment (io.kubernetes.client.proto.V1beta1Extensions.Deployment)1 RollingUpdateDeployment (io.kubernetes.client.proto.V1beta1Extensions.RollingUpdateDeployment)1 Endpoint (io.seldon.protos.DeploymentProtos.Endpoint)1 Parameter (io.seldon.protos.DeploymentProtos.Parameter)1 ArrayList (java.util.ArrayList)1