diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2022-11-09 22:30:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-09 22:30:05 +0100 |
commit | eebbd7db35d858a392160dbe5067b2f52b1640a8 (patch) | |
tree | 207c9dc61d3207e4630e73dc51ac5bdff1ac6d40 /model-integration | |
parent | ba3ac72d3146d9e64a4bf32c993fd4969b272c7d (diff) |
Revert "Revert "Revert "Revert "Balder/model importing code in config model [run-systemtest]""""
Diffstat (limited to 'model-integration')
5 files changed, 36 insertions, 14 deletions
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 4e7710aa449..35c409a637c 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,10 +81,19 @@ 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); } @@ -92,9 +101,17 @@ 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 a2626818f87..8c8fc5c4b11 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,6 +1,8 @@ // 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; @@ -21,8 +23,12 @@ 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 b6b63912c52..7fb167ee6f1 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.largeConstants().size()); + assertEquals(2, model.largeConstantTensors().size()); - Tensor constant0 = Tensor.from(model.largeConstants().get("test_Variable")); + Tensor constant0 = model.largeConstantTensors().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 = Tensor.from(model.largeConstants().get("test_Variable_1")); + Tensor constant1 = model.largeConstantTensors().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 5d13697df06..f78150d9875 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.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)))); + result.largeConstantTensors().forEach((name, tensor) -> context.put("constant(" + name + ")", new TensorValue(tensor))); + result.smallConstantTensors().forEach((name, tensor) -> context.put("constant(" + name + ")", new TensorValue(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 25c51a75b0b..d9c7e67c946 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,7 +4,6 @@ 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; @@ -39,12 +38,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.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(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(1, model.largeConstants().size()); - assertEquals("tensor(x[3]):[0.5, 1.5, 2.5]", model.largeConstants().get("constant1asLarge")); + assertEquals(1, model.largeConstantTensors().size()); + assertEquals("tensor(x[3]):[0.5, 1.5, 2.5]", model.largeConstantTensors().get("constant1asLarge").toString()); assertEquals(2, model.expressions().size()); assertEquals("reduce(reduce(input1 * input2, sum, name) * constant1, max, x) * constant2", @@ -72,8 +71,8 @@ public class VespaImportTestCase { assertTrue(model.expressions().isEmpty()); assertTrue(model.functions().isEmpty()); assertTrue(model.inputs().isEmpty()); - assertTrue(model.largeConstants().isEmpty()); - assertTrue(model.smallConstants().isEmpty()); + assertTrue(model.largeConstantTensors().isEmpty()); + assertTrue(model.smallConstantTensors().isEmpty()); } @Test |