diff options
9 files changed, 28 insertions, 56 deletions
diff --git a/config-model-fat/pom.xml b/config-model-fat/pom.xml index 7be7f8eee94..44880d052b6 100644 --- a/config-model-fat/pom.xml +++ b/config-model-fat/pom.xml @@ -37,6 +37,12 @@ </exclusion> </exclusions> </dependency> + <dependency> + <groupId>com.yahoo.vespa</groupId> + <artifactId>model-integration</artifactId> + <version>${project.version}</version> + <scope>provided</scope> + </dependency> </dependencies> <build> diff --git a/config-model/src/main/java/com/yahoo/vespa/model/VespaModelFactory.java b/config-model/src/main/java/com/yahoo/vespa/model/VespaModelFactory.java index 1ba8b470891..e676667ae89 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/VespaModelFactory.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/VespaModelFactory.java @@ -2,11 +2,6 @@ package com.yahoo.vespa.model; import ai.vespa.rankingexpression.importer.configmodelview.MlModelImporter; -import ai.vespa.rankingexpression.importer.lightgbm.LightGBMImporter; -import ai.vespa.rankingexpression.importer.onnx.OnnxImporter; -import ai.vespa.rankingexpression.importer.tensorflow.TensorFlowImporter; -import ai.vespa.rankingexpression.importer.vespa.VespaImporter; -import ai.vespa.rankingexpression.importer.xgboost.XGBoostImporter; import com.yahoo.component.annotation.Inject; import com.yahoo.component.Version; import com.yahoo.component.provider.ComponentRegistry; @@ -61,6 +56,7 @@ public class VespaModelFactory implements ModelFactory { /** Creates a factory for Vespa models for this version of the source */ @Inject public VespaModelFactory(ComponentRegistry<ConfigModelPlugin> pluginRegistry, + ComponentRegistry<MlModelImporter> modelImporters, ComponentRegistry<Validator> additionalValidators, Zone zone) { this.version = new Version(VespaVersion.major, VespaVersion.minor, VespaVersion.micro); @@ -71,12 +67,7 @@ public class VespaModelFactory implements ModelFactory { } } this.configModelRegistry = new MapConfigModelRegistry(modelBuilders); - this.modelImporters = List.of( - new VespaImporter(), - new OnnxImporter(), - new TensorFlowImporter(), - new XGBoostImporter(), - new LightGBMImporter()); + this.modelImporters = modelImporters.allComponents(); this.zone = zone; this.additionalValidators = List.copyOf(additionalValidators.allComponents()); diff --git a/config-model/src/main/java/com/yahoo/vespa/model/ml/ConvertedModel.java b/config-model/src/main/java/com/yahoo/vespa/model/ml/ConvertedModel.java index 96a6b39dc1a..9ba87fd24bf 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/ml/ConvertedModel.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/ml/ConvertedModel.java @@ -199,8 +199,8 @@ public class ConvertedModel { ModelStore store) { // Add constants Set<String> constantsReplacedByFunctions = new HashSet<>(); - model.smallConstantTensors().forEach((k, v) -> transformSmallConstant(store, profile, k, v)); - model.largeConstantTensors().forEach((k, v) -> transformLargeConstant(store, profile, queryProfiles, + model.smallConstants().forEach((k, v) -> transformSmallConstant(store, profile, k, v)); + model.largeConstants().forEach((k, v) -> transformLargeConstant(store, profile, queryProfiles, constantsReplacedByFunctions, k, v)); // Add functions @@ -294,7 +294,8 @@ public class ConvertedModel { } private static void transformSmallConstant(ModelStore store, RankProfile profile, String constantName, - Tensor constantValue) { + String constantValueString) { + Tensor constantValue = Tensor.from(constantValueString); store.writeSmallConstant(constantName, constantValue); Reference name = FeatureNames.asConstantFeature(constantName); profile.add(new RankProfile.Constant(name, constantValue)); @@ -305,7 +306,8 @@ public class ConvertedModel { QueryProfileRegistry queryProfiles, Set<String> constantsReplacedByFunctions, String constantName, - Tensor constantValue) { + String constantValueString) { + Tensor constantValue = Tensor.from(constantValueString); RankProfile.RankingExpressionFunction rankingExpressionFunctionOverridingConstant = profile.getFunctions().get(constantName); if (rankingExpressionFunctionOverridingConstant != null) { TensorType functionType = rankingExpressionFunctionOverridingConstant.function().getBody().type(profile.typeContext(queryProfiles)); diff --git a/fat-model-dependencies/pom.xml b/fat-model-dependencies/pom.xml index 9801098d5b6..f3312bd5d89 100644 --- a/fat-model-dependencies/pom.xml +++ b/fat-model-dependencies/pom.xml @@ -71,11 +71,6 @@ </dependency> <dependency> <groupId>com.yahoo.vespa</groupId> - <artifactId>model-integration</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>com.yahoo.vespa</groupId> <artifactId>metrics</artifactId> <version>${project.version}</version> </dependency> diff --git a/model-integration/src/main/java/ai/vespa/rankingexpression/importer/ImportedModel.java b/model-integration/src/main/java/ai/vespa/rankingexpression/importer/ImportedModel.java index 35c409a637c..4e7710aa449 100644 --- a/model-integration/src/main/java/ai/vespa/rankingexpression/importer/ImportedModel.java +++ b/model-integration/src/main/java/ai/vespa/rankingexpression/importer/ImportedModel.java @@ -81,19 +81,10 @@ public class ImportedModel implements ImportedMlModel { } /** - * Returns an immutable map of the small constants of this. - * These should have sizes up to a few kb at most, and correspond to constant values given in the source model. - */ - @Override - public Map<String, Tensor> smallConstantTensors() { return Map.copyOf(smallConstants); } - /** * Returns an immutable map of the small constants of this, represented as strings on the standard tensor form. * These should have sizes up to a few kb at most, and correspond to constant values given in the source model. - * @deprecated Use smallConstantTensors instead */ @Override - @SuppressWarnings("removal") - @Deprecated(forRemoval = true) public Map<String, String> smallConstants() { return asStrings(smallConstants); } boolean hasSmallConstant(String name) { return smallConstants.containsKey(name); } @@ -101,17 +92,9 @@ public class ImportedModel implements ImportedMlModel { /** * Returns an immutable map of the large constants of this. * These can have sizes in gigabytes and must be distributed to nodes separately from configuration. + * For TensorFlow this corresponds to Variable files stored separately. */ @Override - public Map<String, Tensor> largeConstantTensors() { return Map.copyOf(largeConstants); } - /** - * Returns an immutable map of the large constants of this, represented as strings on the standard tensor form. - * These can have sizes in gigabytes and must be distributed to nodes separately from configuration. - * @deprecated Use largeConstantTensors instead - */ - @Override - @SuppressWarnings("removal") - @Deprecated(forRemoval = true) public Map<String, String> largeConstants() { return asStrings(largeConstants); } boolean hasLargeConstant(String name) { return largeConstants.containsKey(name); } diff --git a/model-integration/src/main/java/ai/vespa/rankingexpression/importer/configmodelview/ImportedMlModel.java b/model-integration/src/main/java/ai/vespa/rankingexpression/importer/configmodelview/ImportedMlModel.java index 8c8fc5c4b11..a2626818f87 100644 --- a/model-integration/src/main/java/ai/vespa/rankingexpression/importer/configmodelview/ImportedMlModel.java +++ b/model-integration/src/main/java/ai/vespa/rankingexpression/importer/configmodelview/ImportedMlModel.java @@ -1,8 +1,6 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package ai.vespa.rankingexpression.importer.configmodelview; -import com.yahoo.tensor.Tensor; - import java.util.List; import java.util.Map; import java.util.Optional; @@ -23,12 +21,8 @@ public interface ImportedMlModel { ModelType modelType(); Optional<String> inputTypeSpec(String input); - @Deprecated(forRemoval = true) Map<String, String> smallConstants(); - @Deprecated(forRemoval = true) Map<String, String> largeConstants(); - Map<String, Tensor> smallConstantTensors(); - Map<String, Tensor> largeConstantTensors(); Map<String, String> functions(); List<ImportedMlFunction> outputExpressions(); diff --git a/model-integration/src/test/java/ai/vespa/rankingexpression/importer/onnx/OnnxMnistSoftmaxImportTestCase.java b/model-integration/src/test/java/ai/vespa/rankingexpression/importer/onnx/OnnxMnistSoftmaxImportTestCase.java index 7fb167ee6f1..b6b63912c52 100644 --- a/model-integration/src/test/java/ai/vespa/rankingexpression/importer/onnx/OnnxMnistSoftmaxImportTestCase.java +++ b/model-integration/src/test/java/ai/vespa/rankingexpression/importer/onnx/OnnxMnistSoftmaxImportTestCase.java @@ -21,15 +21,15 @@ public class OnnxMnistSoftmaxImportTestCase { ImportedModel model = new OnnxImporter().importModel("test", "src/test/models/onnx/mnist_softmax/mnist_softmax.onnx").asNative(); // Check constants - assertEquals(2, model.largeConstantTensors().size()); + assertEquals(2, model.largeConstants().size()); - Tensor constant0 = model.largeConstantTensors().get("test_Variable"); + Tensor constant0 = Tensor.from(model.largeConstants().get("test_Variable")); assertNotNull(constant0); assertEquals(new TensorType.Builder(TensorType.Value.FLOAT).indexed("d2", 784).indexed("d1", 10).build(), constant0.type()); assertEquals(7840, constant0.size()); - Tensor constant1 = model.largeConstantTensors().get("test_Variable_1"); + Tensor constant1 = Tensor.from(model.largeConstants().get("test_Variable_1")); assertNotNull(constant1); assertEquals(new TensorType.Builder(TensorType.Value.FLOAT).indexed("d1", 10).build(), constant1.type()); assertEquals(10, constant1.size()); diff --git a/model-integration/src/test/java/ai/vespa/rankingexpression/importer/onnx/TestableModel.java b/model-integration/src/test/java/ai/vespa/rankingexpression/importer/onnx/TestableModel.java index f78150d9875..5d13697df06 100644 --- a/model-integration/src/test/java/ai/vespa/rankingexpression/importer/onnx/TestableModel.java +++ b/model-integration/src/test/java/ai/vespa/rankingexpression/importer/onnx/TestableModel.java @@ -63,8 +63,8 @@ public class TestableModel { static Context contextFrom(ImportedModel result) { TestableModelContext context = new TestableModelContext(); - result.largeConstantTensors().forEach((name, tensor) -> context.put("constant(" + name + ")", new TensorValue(tensor))); - result.smallConstantTensors().forEach((name, tensor) -> context.put("constant(" + name + ")", new TensorValue(tensor))); + result.largeConstants().forEach((name, tensor) -> context.put("constant(" + name + ")", new TensorValue(Tensor.from(tensor)))); + result.smallConstants().forEach((name, tensor) -> context.put("constant(" + name + ")", new TensorValue(Tensor.from(tensor)))); return context; } diff --git a/model-integration/src/test/java/ai/vespa/rankingexpression/importer/vespa/VespaImportTestCase.java b/model-integration/src/test/java/ai/vespa/rankingexpression/importer/vespa/VespaImportTestCase.java index d9c7e67c946..25c51a75b0b 100644 --- a/model-integration/src/test/java/ai/vespa/rankingexpression/importer/vespa/VespaImportTestCase.java +++ b/model-integration/src/test/java/ai/vespa/rankingexpression/importer/vespa/VespaImportTestCase.java @@ -4,6 +4,7 @@ package ai.vespa.rankingexpression.importer.vespa; import ai.vespa.rankingexpression.importer.ImportedModel; import ai.vespa.rankingexpression.importer.configmodelview.ImportedMlFunction; import com.yahoo.searchlib.rankingexpression.RankingExpression; +import com.yahoo.searchlib.rankingexpression.evaluation.Context; import com.yahoo.searchlib.rankingexpression.evaluation.MapContext; import com.yahoo.searchlib.rankingexpression.evaluation.TensorValue; import com.yahoo.searchlib.rankingexpression.parser.ParseException; @@ -38,12 +39,12 @@ public class VespaImportTestCase { assertEquals("tensor(name{},x[3])", model.inputs().get("input1").toString()); assertEquals("tensor(x[3])", model.inputs().get("input2").toString()); - assertEquals(2, model.smallConstantTensors().size()); - assertEquals("tensor(x[3]):[0.5, 1.5, 2.5]", model.smallConstantTensors().get("constant1").toString()); - assertEquals("tensor():{3.0}", model.smallConstantTensors().get("constant2").toString()); + assertEquals(2, model.smallConstants().size()); + assertEquals("tensor(x[3]):[0.5, 1.5, 2.5]", model.smallConstants().get("constant1")); + assertEquals("tensor():{3.0}", model.smallConstants().get("constant2")); - assertEquals(1, model.largeConstantTensors().size()); - assertEquals("tensor(x[3]):[0.5, 1.5, 2.5]", model.largeConstantTensors().get("constant1asLarge").toString()); + assertEquals(1, model.largeConstants().size()); + assertEquals("tensor(x[3]):[0.5, 1.5, 2.5]", model.largeConstants().get("constant1asLarge")); assertEquals(2, model.expressions().size()); assertEquals("reduce(reduce(input1 * input2, sum, name) * constant1, max, x) * constant2", @@ -71,8 +72,8 @@ public class VespaImportTestCase { assertTrue(model.expressions().isEmpty()); assertTrue(model.functions().isEmpty()); assertTrue(model.inputs().isEmpty()); - assertTrue(model.largeConstantTensors().isEmpty()); - assertTrue(model.smallConstantTensors().isEmpty()); + assertTrue(model.largeConstants().isEmpty()); + assertTrue(model.smallConstants().isEmpty()); } @Test |