Search in sources :

Example 16 with SeldonMessage

use of io.seldon.protos.PredictionProtos.SeldonMessage in project seldon-core by SeldonIO.

the class AverageCombinerTest method testSimpleTensorCase.

@Test
public void testSimpleTensorCase() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException {
    List<SeldonMessage> predictorReturns = new ArrayList<>();
    String[] names = { "c", "d" };
    Double[] values1 = { 1.0, 1.0 };
    predictorReturns.add(SeldonMessage.newBuilder().setStatus(Status.newBuilder().setStatus(Status.StatusFlag.SUCCESS).build()).setData(DefaultData.newBuilder().addAllNames(Arrays.asList(names)).setTensor(Tensor.newBuilder().addShape(1).addShape(2).addAllValues(Arrays.asList(values1)).build()).build()).build());
    Double[] values2 = { 1.0, 0.5 };
    predictorReturns.add(SeldonMessage.newBuilder().setStatus(Status.newBuilder().setStatus(Status.StatusFlag.SUCCESS).build()).setData(DefaultData.newBuilder().addAllNames(Arrays.asList(names)).setTensor(Tensor.newBuilder().addShape(1).addShape(2).addAllValues(Arrays.asList(values2)).build()).build()).build());
    Double[] values3 = { 2.2, 0.9 };
    predictorReturns.add(SeldonMessage.newBuilder().setStatus(Status.newBuilder().setStatus(Status.StatusFlag.SUCCESS).build()).setData(DefaultData.newBuilder().addAllNames(Arrays.asList(names)).setTensor(Tensor.newBuilder().addShape(1).addShape(2).addAllValues(Arrays.asList(values3)).build()).build()).build());
    AverageCombinerUnit averageCombinerUnit = new AverageCombinerUnit();
    SeldonMessage average = averageCombinerUnit.aggregate(predictorReturns, null);
    Assert.assertThat(average.getData().getNamesList().get(0), is(names[0]));
    Double[][] expected_values = { { (1.0 + 1.0 + 2.2) / 3, (1.0 + 0.5 + 0.9) / 3 } };
    Assert.assertEquals(expected_values[0][0], average.getData().getTensor().getValuesList().get(0), 1e-7);
}
Also used : SeldonMessage(io.seldon.protos.PredictionProtos.SeldonMessage) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 17 with SeldonMessage

use of io.seldon.protos.PredictionProtos.SeldonMessage in project seldon-core by SeldonIO.

the class AverageCombinerTest method testGetOutputNoChildren.

@Test
public void testGetOutputNoChildren() throws InterruptedException, ExecutionException, InvalidProtocolBufferException {
    SeldonMessage p = SeldonMessage.newBuilder().build();
    PredictiveUnitState state = new PredictiveUnitState("Cool_name", null, new ArrayList<PredictiveUnitState>(), null, null, null, null, PredictiveUnitImplementation.AVERAGE_COMBINER);
    PredictiveUnitBean predictiveUnit = new PredictiveUnitBean();
    SimpleModelUnit simpleModel = new SimpleModelUnit();
    SimpleRouterUnit simpleRouterUnit = new SimpleRouterUnit();
    AverageCombinerUnit averageCombiner = new AverageCombinerUnit();
    RandomABTestUnit randomABTest = new RandomABTestUnit();
    PredictorConfigBean predictorConfig = new PredictorConfigBean(simpleModel, simpleRouterUnit, averageCombiner, randomABTest);
    predictiveUnit.predictorConfig = predictorConfig;
    predictiveUnit.getOutput(p, state);
}
Also used : SeldonMessage(io.seldon.protos.PredictionProtos.SeldonMessage) Test(org.junit.Test)

Example 18 with SeldonMessage

use of io.seldon.protos.PredictionProtos.SeldonMessage in project seldon-core by SeldonIO.

the class AverageCombinerTest method testUniqueValue.

@Test
public void testUniqueValue() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException {
    List<SeldonMessage> predictorReturns = new ArrayList<>();
    String[] names = { "c" };
    Double[] values1 = { 1.0 };
    predictorReturns.add(SeldonMessage.newBuilder().setStatus(Status.newBuilder().setStatus(Status.StatusFlag.SUCCESS).build()).setData(DefaultData.newBuilder().addAllNames(Arrays.asList(names)).setTensor(Tensor.newBuilder().addShape(1).addShape(1).addAllValues(Arrays.asList(values1)).build()).build()).build());
    Double[] values2 = { 1.0 };
    predictorReturns.add(SeldonMessage.newBuilder().setStatus(Status.newBuilder().setStatus(Status.StatusFlag.SUCCESS).build()).setData(DefaultData.newBuilder().addAllNames(Arrays.asList(names)).setTensor(Tensor.newBuilder().addShape(1).addShape(1).addAllValues(Arrays.asList(values2)).build()).build()).build());
    AverageCombinerUnit averageCombinerUnit = new AverageCombinerUnit();
    SeldonMessage average = averageCombinerUnit.aggregate(predictorReturns, null);
    Assert.assertThat(average.getData().getNamesList().get(0), is(names[0]));
    Double[][] expected_values = { { 2.0 / 2 } };
    Assert.assertThat(average.getData().getTensor().getValuesList().get(0), is(expected_values[0][0]));
}
Also used : SeldonMessage(io.seldon.protos.PredictionProtos.SeldonMessage) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 19 with SeldonMessage

use of io.seldon.protos.PredictionProtos.SeldonMessage in project seldon-core by SeldonIO.

the class RandomABTestUnitInternalTest method failureOneChild.

@Test(expected = APIException.class)
public void failureOneChild() throws Throwable {
    SeldonMessage request = SeldonMessage.newBuilder().build();
    PredictiveUnitParameter<Float> ratioParam = new PredictiveUnitParameter<Float>(0.5F);
    Map<String, PredictiveUnitParameterInterface> params = new HashMap<>();
    params.put("ratioA", ratioParam);
    PredictiveUnitState state = new PredictiveUnitState("Cool_name", null, new ArrayList<PredictiveUnitState>(), params, null, null, null, PredictiveUnitImplementation.RANDOM_ABTEST);
    PredictiveUnitState childA = new PredictiveUnitState("A", null, null, null, null, null, null, null);
    state.addChild(childA);
    PredictiveUnitImpl predictiveUnit = new RandomABTestUnit();
    predictiveUnit.route(request, state);
}
Also used : SeldonMessage(io.seldon.protos.PredictionProtos.SeldonMessage) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 20 with SeldonMessage

use of io.seldon.protos.PredictionProtos.SeldonMessage in project seldon-core by SeldonIO.

the class RandomABTestUnitInternalTest method simpleCase.

@Test
public void simpleCase() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvalidProtocolBufferException {
    SeldonMessage request = SeldonMessage.newBuilder().build();
    PredictiveUnitParameter<Float> ratioParam = new PredictiveUnitParameter<Float>(0.5F);
    Map<String, PredictiveUnitParameterInterface> params = new HashMap<>();
    params.put("ratioA", ratioParam);
    PredictiveUnitState state = new PredictiveUnitState("Cool_name", null, new ArrayList<PredictiveUnitState>(), params, null, null, null, PredictiveUnitImplementation.RANDOM_ABTEST);
    PredictiveUnitState childA = new PredictiveUnitState("A", null, null, null, null, null, null, null);
    PredictiveUnitState childB = new PredictiveUnitState("B", null, null, null, null, null, null, null);
    state.addChild(childA);
    state.addChild(childB);
    PredictiveUnitImpl predictiveUnit = new RandomABTestUnit();
    // The following values are from random seed 1337
    int routing1 = (int) predictiveUnit.route(request, state);
    Assert.assertEquals(1, routing1);
    int routing2 = (int) predictiveUnit.route(request, state);
    Assert.assertEquals(0, routing2);
    int routing3 = (int) predictiveUnit.route(request, state);
    Assert.assertEquals(1, routing3);
}
Also used : HashMap(java.util.HashMap) SeldonMessage(io.seldon.protos.PredictionProtos.SeldonMessage) Test(org.junit.Test)

Aggregations

SeldonMessage (io.seldon.protos.PredictionProtos.SeldonMessage)28 Test (org.junit.Test)18 ByteString (com.google.protobuf.ByteString)7 ArrayList (java.util.ArrayList)5 PredictiveUnit (io.seldon.protos.DeploymentProtos.PredictiveUnit)4 PredictorSpec (io.seldon.protos.DeploymentProtos.PredictorSpec)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)3 APIException (io.seldon.engine.exception.APIException)3 HashMap (java.util.HashMap)3 PodTemplateSpec (io.kubernetes.client.proto.V1.PodTemplateSpec)2 DefaultData (io.seldon.protos.PredictionProtos.DefaultData)2 HttpHeaders (org.springframework.http.HttpHeaders)2 ResponseEntity (org.springframework.http.ResponseEntity)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 Value (com.google.protobuf.Value)1 SeldonAPIException (io.seldon.apife.exception.SeldonAPIException)1 PredictorState (io.seldon.engine.predictors.PredictorState)1 Parameter (io.seldon.protos.DeploymentProtos.Parameter)1 IOException (java.io.IOException)1