summaryrefslogtreecommitdiffstats
path: root/config-model/src/test
diff options
context:
space:
mode:
authorLester Solbakken <lesters@oath.com>2020-09-18 14:58:57 +0200
committerLester Solbakken <lesters@oath.com>2020-09-18 14:58:57 +0200
commitbe544696d4b70ee186dc80f250bda7d99cd0e20f (patch)
treee200be1130b49b2d626f00a681eec84b4686ab05 /config-model/src/test
parentbf3ca4359b94aff539fc79b80b4caac66225a028 (diff)
Add explicit config for onnx models
Diffstat (limited to 'config-model/src/test')
-rw-r--r--config-model/src/test/integration/onnx-file/files/simple.onnx23
-rw-r--r--config-model/src/test/integration/onnx-file/searchdefinitions/test.sd11
-rw-r--r--config-model/src/test/integration/onnx-model/files/constant.json6
-rw-r--r--config-model/src/test/integration/onnx-model/searchdefinitions/test.sd70
-rw-r--r--config-model/src/test/integration/onnx-model/services.xml (renamed from config-model/src/test/integration/onnx-file/services.xml)0
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithOnnxModelTestCase.java73
6 files changed, 129 insertions, 54 deletions
diff --git a/config-model/src/test/integration/onnx-file/files/simple.onnx b/config-model/src/test/integration/onnx-file/files/simple.onnx
deleted file mode 100644
index eaa66f533da..00000000000
--- a/config-model/src/test/integration/onnx-file/files/simple.onnx
+++ /dev/null
@@ -1,23 +0,0 @@
- simple.py:ß
-0
- query_tensor
-attribute_tensormatmul"MatMul
-"
-matmul
- bias_tensoroutput"Addsimple_scoringZ
- query_tensor
- 
-
-Z"
-attribute_tensor
- 
-
-Z
- bias_tensor
-
-
-b
-output
- 
-
-B \ No newline at end of file
diff --git a/config-model/src/test/integration/onnx-file/searchdefinitions/test.sd b/config-model/src/test/integration/onnx-file/searchdefinitions/test.sd
deleted file mode 100644
index 5ca0cd1b8bf..00000000000
--- a/config-model/src/test/integration/onnx-file/searchdefinitions/test.sd
+++ /dev/null
@@ -1,11 +0,0 @@
-# Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-search test {
- document test {}
-
- rank-profile my_profile inherits default {
- first-phase {
- expression: onnxModel("files/simple.onnx", "output")
- }
- }
-
-}
diff --git a/config-model/src/test/integration/onnx-model/files/constant.json b/config-model/src/test/integration/onnx-model/files/constant.json
new file mode 100644
index 00000000000..63f64a73af5
--- /dev/null
+++ b/config-model/src/test/integration/onnx-model/files/constant.json
@@ -0,0 +1,6 @@
+{
+ "cells": [
+ { "address": { "d0": "0" }, "value": 2.0 },
+ { "address": { "d0": "1" }, "value": 3.0 }
+ ]
+} \ No newline at end of file
diff --git a/config-model/src/test/integration/onnx-model/searchdefinitions/test.sd b/config-model/src/test/integration/onnx-model/searchdefinitions/test.sd
new file mode 100644
index 00000000000..0f0fa694e6f
--- /dev/null
+++ b/config-model/src/test/integration/onnx-model/searchdefinitions/test.sd
@@ -0,0 +1,70 @@
+# Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+search test {
+
+ document test {
+ field document_field type tensor(d0[2]) {
+ indexing: attribute
+ }
+ }
+
+ constant my_constant {
+ file: files/constant.json
+ type: tensor(d0[2])
+ }
+
+ onnx-model my_model {
+ file: files/ranking_model.onnx
+ input first_input: attribute(document_field)
+ input "second/input:0": constant(my_constant)
+ input "third_input": my_function
+ output "path/to/output:0": out
+ }
+
+ onnx-model another_model {
+ file: files/ranking_model.onnx
+ input first_input: attribute(document_field)
+ input "second/input:0": constant(my_constant)
+ input "third_input": another_function
+ output "path/to/output:2": out
+ }
+
+ rank-profile test_model_config {
+ function my_function() {
+ expression: tensor(d0[2])(1)
+ }
+ first-phase {
+ expression: onnxModel(my_model).out
+ }
+ }
+
+ rank-profile test_generated_model_config inherits test_model_config {
+ function first_input() {
+ expression: attribute(document_field)
+ }
+ function second_input() {
+ expression: constant(my_constant)
+ }
+ function third_input() {
+ expression: my_function()
+ }
+ first-phase {
+ expression: onnxModel("files/ranking_model.onnx", "path/to/output:1")
+ }
+ }
+
+ rank-profile test_summary_features {
+ function another_function() {
+ expression: tensor(d0[2])(2)
+ }
+ first-phase {
+ expression: 1
+ }
+ summary-features {
+ onnxModel(another_model).out
+ onnxModel("files/ranking_model.onnx", "path/to/output:2")
+ }
+
+ }
+
+}
diff --git a/config-model/src/test/integration/onnx-file/services.xml b/config-model/src/test/integration/onnx-model/services.xml
index 892ce9a9f89..892ce9a9f89 100644
--- a/config-model/src/test/integration/onnx-file/services.xml
+++ b/config-model/src/test/integration/onnx-model/services.xml
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithOnnxModelTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithOnnxModelTestCase.java
index 7e129410b37..d9b0c70dfdd 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithOnnxModelTestCase.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithOnnxModelTestCase.java
@@ -1,7 +1,6 @@
// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.searchdefinition.processing;
-import com.yahoo.searchdefinition.expressiontransforms.OnnxModelTransformer;
import com.yahoo.vespa.config.search.RankProfilesConfig;
import com.yahoo.vespa.config.search.core.OnnxModelsConfig;
import com.yahoo.vespa.model.VespaModel;
@@ -16,36 +15,70 @@ public class RankingExpressionWithOnnxModelTestCase {
@Test
public void testOnnxModelFeature() {
- VespaModel model = new VespaModelCreatorWithFilePkg("src/test/integration/onnx-file").create();
+ VespaModel model = new VespaModelCreatorWithFilePkg("src/test/integration/onnx-model").create();
DocumentDatabase db = ((IndexedSearchCluster)model.getSearchClusters().get(0)).getDocumentDbs().get(0);
-
- String modelName = OnnxModelTransformer.toModelName("files/simple.onnx");
-
- // Ranking expression should be transformed from
- // onnxModel("files/simple.onnx", "output")
- // to
- // onnxModel(files_simple_onnx).output
-
- assertTransformedFeature(db, modelName);
- assertGeneratedConfig(db, modelName);
+ assertTransformedFeature(db);
+ assertGeneratedConfig(db);
}
- private void assertGeneratedConfig(DocumentDatabase db, String modelName) {
+ private void assertGeneratedConfig(DocumentDatabase db) {
OnnxModelsConfig.Builder builder = new OnnxModelsConfig.Builder();
((OnnxModelsConfig.Producer) db).getConfig(builder);
OnnxModelsConfig config = new OnnxModelsConfig(builder);
- assertEquals(1, config.model().size());
- assertEquals(modelName, config.model(0).name());
+ assertEquals(3, config.model().size());
+
+ assertEquals("my_model", config.model(1).name());
+ assertEquals(3, config.model(1).input().size());
+ assertEquals("first_input", config.model(1).input(0).name());
+ assertEquals("attribute(document_field)", config.model(1).input(0).source());
+ assertEquals("second/input:0", config.model(1).input(1).name());
+ assertEquals("constant(my_constant)", config.model(1).input(1).source());
+ assertEquals("third_input", config.model(1).input(2).name());
+ assertEquals("rankingExpression(my_function)", config.model(1).input(2).source());
+ assertEquals(1, config.model(1).output().size());
+ assertEquals("path/to/output:0", config.model(1).output(0).name());
+ assertEquals("out", config.model(1).output(0).as());
+
+ assertEquals("files_ranking_model_onnx", config.model(0).name());
+ assertEquals(0, config.model(0).input().size());
+ assertEquals(2, config.model(0).output().size());
+ assertEquals("path/to/output:1", config.model(0).output(0).name());
+ assertEquals("path_to_output_1", config.model(0).output(0).as());
+ assertEquals("path/to/output:2", config.model(0).output(1).name());
+ assertEquals("path_to_output_2", config.model(0).output(1).as());
+
+ assertEquals("another_model", config.model(2).name());
+ assertEquals("third_input", config.model(2).input(2).name());
+ assertEquals("rankingExpression(another_function)", config.model(2).input(2).source());
}
- private void assertTransformedFeature(DocumentDatabase db, String modelName) {
+ private void assertTransformedFeature(DocumentDatabase db) {
RankProfilesConfig.Builder builder = new RankProfilesConfig.Builder();
((RankProfilesConfig.Producer) db).getConfig(builder);
RankProfilesConfig config = new RankProfilesConfig(builder);
- assertEquals(3, config.rankprofile().size());
- assertEquals("my_profile", config.rankprofile(2).name());
- assertEquals("vespa.rank.firstphase", config.rankprofile(2).fef().property(0).name());
- assertEquals("onnxModel(" + modelName + ").output", config.rankprofile(2).fef().property(0).value());
+ assertEquals(5, config.rankprofile().size());
+
+ assertEquals("test_model_config", config.rankprofile(2).name());
+ assertEquals("rankingExpression(my_function).rankingScript", config.rankprofile(2).fef().property(0).name());
+ assertEquals("vespa.rank.firstphase", config.rankprofile(2).fef().property(2).name());
+ assertEquals("onnxModel(my_model).out", config.rankprofile(2).fef().property(2).value());
+
+ assertEquals("test_generated_model_config", config.rankprofile(3).name());
+ assertEquals("rankingExpression(my_function).rankingScript", config.rankprofile(3).fef().property(0).name());
+ assertEquals("rankingExpression(first_input).rankingScript", config.rankprofile(3).fef().property(2).name());
+ assertEquals("rankingExpression(second_input).rankingScript", config.rankprofile(3).fef().property(4).name());
+ assertEquals("rankingExpression(third_input).rankingScript", config.rankprofile(3).fef().property(6).name());
+ assertEquals("vespa.rank.firstphase", config.rankprofile(3).fef().property(8).name());
+ assertEquals("onnxModel(files_ranking_model_onnx).path_to_output_1", config.rankprofile(3).fef().property(8).value());
+
+ assertEquals("test_summary_features", config.rankprofile(4).name());
+ assertEquals("rankingExpression(another_function).rankingScript", config.rankprofile(4).fef().property(0).name());
+ assertEquals("rankingExpression(firstphase).rankingScript", config.rankprofile(4).fef().property(3).name());
+ assertEquals("1", config.rankprofile(4).fef().property(3).value());
+ assertEquals("vespa.summary.feature", config.rankprofile(4).fef().property(4).name());
+ assertEquals("onnxModel(another_model).out", config.rankprofile(4).fef().property(4).value());
+ assertEquals("vespa.summary.feature", config.rankprofile(4).fef().property(5).name());
+ assertEquals("onnxModel(files_ranking_model_onnx).path_to_output_2", config.rankprofile(4).fef().property(5).value());
}
}