Search in sources :

Example 1 with PredictiveUnit

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

the class PredictorBean method predictorStateFromPredictorSpec.

// TODO
public PredictorState predictorStateFromPredictorSpec(PredictorSpec predictorSpec) {
    // Boolean enabled = PredictorSpec.getEnabled();
    Boolean enabled = true;
    PredictiveUnit rootUnit = predictorSpec.getGraph();
    Map<String, Container> containersMap = new HashMap<String, Container>();
    for (Container container : predictorSpec.getComponentSpec().getSpec().getContainersList()) {
        containersMap.put(container.getName(), container);
    }
    PredictiveUnitState rootState = new PredictiveUnitState(rootUnit, containersMap);
    return new PredictorState(rootUnit.getName(), rootState, enabled);
}
Also used : Container(io.kubernetes.client.proto.V1.Container) HashMap(java.util.HashMap) PredictiveUnit(io.seldon.protos.DeploymentProtos.PredictiveUnit)

Example 2 with PredictiveUnit

use of io.seldon.protos.DeploymentProtos.PredictiveUnit 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)

Aggregations

PredictiveUnit (io.seldon.protos.DeploymentProtos.PredictiveUnit)2 Container (io.kubernetes.client.proto.V1.Container)1 Parameter (io.seldon.protos.DeploymentProtos.Parameter)1 PredictorSpec (io.seldon.protos.DeploymentProtos.PredictorSpec)1 SeldonMessage (io.seldon.protos.PredictionProtos.SeldonMessage)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1