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);
}
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);
}
Aggregations