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