diff options
Diffstat (limited to 'config-model/src/test')
10 files changed, 74 insertions, 62 deletions
diff --git a/config-model/src/test/cfg/application/stateless_eval/example.model b/config-model/src/test/cfg/application/stateless_eval/example.model index af1c85be4f0..1d2db15c3ba 100644 --- a/config-model/src/test/cfg/application/stateless_eval/example.model +++ b/config-model/src/test/cfg/application/stateless_eval/example.model @@ -7,6 +7,7 @@ model example { constants { constant1: tensor(x[3]):{{x:0}:0.5, {x:1}:1.5, {x:2}:2.5} constant2: 3.0 + #constant1asLarge tensor(x[3]): file:constant1asLarge.json } constant constant1asLarge { diff --git a/config-model/src/test/integration/onnx-model/schemas/test.sd b/config-model/src/test/integration/onnx-model/schemas/test.sd index a15714767ba..82872758dd9 100644 --- a/config-model/src/test/integration/onnx-model/schemas/test.sd +++ b/config-model/src/test/integration/onnx-model/schemas/test.sd @@ -21,14 +21,6 @@ search test { output "path/to/output:0": out } - onnx-model another_model { - file: files/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 - } - onnx-model dynamic_model { file: files/dynamic_model.onnx input input: my_function @@ -72,6 +64,13 @@ search test { first-phase { expression: 1 } + onnx-model another_model { + file: files/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 + } summary-features { onnx(another_model).out onnx("files/summary_model.onnx", "path/to/output:2") diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/SchemaTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/SchemaTestCase.java index 65f4dab3650..cb57746d82f 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/SchemaTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/SchemaTestCase.java @@ -196,8 +196,8 @@ public class SchemaTestCase { assertTrue(child1profile.constants().containsKey(FeatureNames.asConstantFeature("parent_constant"))); assertNotNull(child1.onnxModels().get("parent_model")); assertNotNull(child1.onnxModels().get("child1_model")); - assertTrue(child1.onnxModels().asMap().containsKey("parent_model")); - assertTrue(child1.onnxModels().asMap().containsKey("child1_model")); + assertTrue(child1.onnxModels().containsKey("parent_model")); + assertTrue(child1.onnxModels().containsKey("child1_model")); assertNotNull(child1.getSummary("parent_summary")); assertNotNull(child1.getSummary("child1_summary")); assertEquals("parent_summary", child1.getSummary("child1_summary").inherited().get().getName()); @@ -231,8 +231,8 @@ public class SchemaTestCase { assertTrue(child2.constants().containsKey(FeatureNames.asConstantFeature("child2_constant"))); assertNotNull(child2.onnxModels().get("parent_model")); assertNotNull(child2.onnxModels().get("child2_model")); - assertTrue(child2.onnxModels().asMap().containsKey("parent_model")); - assertTrue(child2.onnxModels().asMap().containsKey("child2_model")); + assertTrue(child2.onnxModels().containsKey("parent_model")); + assertTrue(child2.onnxModels().containsKey("child2_model")); assertNotNull(child2.getSummary("parent_summary")); assertNotNull(child2.getSummary("child2_summary")); assertEquals("parent_summary", child2.getSummary("child2_summary").inherited().get().getName()); @@ -430,7 +430,7 @@ public class SchemaTestCase { assertNotNull(schema.constants().get(FeatureNames.asConstantFeature("parent_constant"))); assertTrue(schema.constants().containsKey(FeatureNames.asConstantFeature("parent_constant"))); assertNotNull(schema.onnxModels().get("parent_model")); - assertTrue(schema.onnxModels().asMap().containsKey("parent_model")); + assertTrue(schema.onnxModels().containsKey("parent_model")); assertNotNull(schema.getSummary("parent_summary")); assertTrue(schema.getSummaries().containsKey("parent_summary")); assertNotNull(schema.getSummaryField("pf1")); diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/derived/GeminiTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/derived/GeminiTestCase.java index 07e6fbf7b1b..207792ffe06 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/derived/GeminiTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/derived/GeminiTestCase.java @@ -19,7 +19,7 @@ public class GeminiTestCase extends AbstractExportingTestCase { @Test public void testRanking2() throws IOException, ParseException { DerivedConfiguration c = assertCorrectDeriving("gemini2"); - RawRankProfile p = c.getRankProfileList().getRankProfile("test"); + RawRankProfile p = c.getRankProfileList().getRankProfiles().get("test"); Map<String, String> ranking = removePartKeySuffixes(asMap(p.configProperties())); assertEquals("attribute(right)", resolve(lookup("toplevel", ranking), ranking)); } diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/parser/IntermediateParserTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/parser/SchemaParserTestCase.java index 1e0c554af81..17d94639d87 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/parser/IntermediateParserTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/parser/SchemaParserTestCase.java @@ -10,20 +10,22 @@ import java.io.File; import org.junit.Test; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertThrows; /** * @author arnej */ -public class IntermediateParserTestCase { +public class SchemaParserTestCase { ParsedSchema parseString(String input) throws Exception { var deployLogger = new BaseDeployLogger(); var modelProperties = new TestProperties(); var stream = new SimpleCharStream(input); try { - var parser = new IntermediateParser(stream, deployLogger, modelProperties); + var parser = new SchemaParser(stream, deployLogger, modelProperties); return parser.schema(); } catch (ParseException pe) { throw new ParseException(stream.formatException(pe.getMessage())); @@ -60,7 +62,7 @@ public class IntermediateParserTestCase { } @Test - public void multiple_documents_disallowed() throws Exception { + public void multiple_documents_disallowed() { String input = joinLines ("schema foo {", " document foo {", @@ -85,11 +87,10 @@ public class IntermediateParserTestCase { } void checkFileParses(String fileName) throws Exception { - System.err.println("TRY parsing: "+fileName); var schema = parseFile(fileName); - assertTrue(schema != null); - assertTrue(schema.name() != null); - assertTrue(! schema.name().equals("")); + assertNotNull(schema); + assertNotNull(schema.name()); + assertNotEquals("", schema.name()); } @Test 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 2057bcaba04..6820a8d9678 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 @@ -8,6 +8,7 @@ import com.yahoo.io.IOUtils; import com.yahoo.path.Path; import com.yahoo.vespa.config.search.RankProfilesConfig; import com.yahoo.vespa.config.search.core.OnnxModelsConfig; +import com.yahoo.vespa.config.search.core.RankingConstantsConfig; import com.yahoo.vespa.model.VespaModel; import com.yahoo.vespa.model.search.DocumentDatabase; import com.yahoo.vespa.model.search.IndexedSearchCluster; @@ -57,6 +58,15 @@ public class RankingExpressionWithOnnxModelTestCase { private void assertGeneratedConfig(VespaModel vespaModel) { DocumentDatabase db = ((IndexedSearchCluster)vespaModel.getSearchClusters().get(0)).getDocumentDbs().get(0); + + RankingConstantsConfig.Builder rankingConstantsConfigBuilder = new RankingConstantsConfig.Builder(); + db.getConfig(rankingConstantsConfigBuilder); + var rankingConstantsConfig = rankingConstantsConfigBuilder.build(); + assertEquals(1, rankingConstantsConfig.constant().size()); + assertEquals("my_constant", rankingConstantsConfig.constant(0).name()); + assertEquals("tensor(d0[2])", rankingConstantsConfig.constant(0).type()); + assertEquals("files/constant.json", rankingConstantsConfig.constant(0).fileref().value()); + OnnxModelsConfig.Builder builder = new OnnxModelsConfig.Builder(); ((OnnxModelsConfig.Producer) db).getConfig(builder); OnnxModelsConfig config = new OnnxModelsConfig(builder); @@ -83,6 +93,18 @@ public class RankingExpressionWithOnnxModelTestCase { assertEquals("path_to_output_2", model.output(2).as()); model = config.model(1); + assertEquals("dynamic_model", model.name()); + assertEquals(1, model.input().size()); + assertEquals(1, model.output().size()); + assertEquals("rankingExpression(my_function)", model.input(0).source()); + + model = config.model(2); + assertEquals("unbound_model", model.name()); + assertEquals(1, model.input().size()); + assertEquals(1, model.output().size()); + assertEquals("rankingExpression(my_function)", model.input(0).source()); + + model = config.model(3); assertEquals("files_model_onnx", model.name()); assertEquals(3, model.input().size()); assertEquals(3, model.output().size()); @@ -94,27 +116,15 @@ public class RankingExpressionWithOnnxModelTestCase { assertEquals("path_to_output_2", model.output(2).as()); assertEquals("files_model_onnx", model.name()); - model = config.model(2); + model = config.model(4); assertEquals("another_model", model.name()); assertEquals("third_input", model.input(2).name()); assertEquals("rankingExpression(another_function)", model.input(2).source()); - model = config.model(3); + model = config.model(5); assertEquals("files_summary_model_onnx", model.name()); assertEquals(3, model.input().size()); assertEquals(3, model.output().size()); - - model = config.model(4); - assertEquals("unbound_model", model.name()); - assertEquals(1, model.input().size()); - assertEquals(1, model.output().size()); - assertEquals("rankingExpression(my_function)", model.input(0).source()); - - model = config.model(5); - assertEquals("dynamic_model", model.name()); - assertEquals(1, model.input().size()); - assertEquals(1, model.output().size()); - assertEquals("rankingExpression(my_function)", model.input(0).source()); } private void assertTransformedFeature(VespaModel model) { diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/VespaMlModelTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/VespaMlModelTestCase.java index e0427d93ee4..4446f01aa95 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/VespaMlModelTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/VespaMlModelTestCase.java @@ -68,7 +68,7 @@ public class VespaMlModelTestCase { private String rankConfigOf(String rankProfileName, VespaModel model) { StringBuilder b = new StringBuilder(); - RawRankProfile profile = model.rankProfileList().getRankProfile(rankProfileName); + RawRankProfile profile = model.rankProfileList().getRankProfiles().get(rankProfileName); for (var property : profile.configProperties()) b.append(property.getFirst()).append(" : ").append(property.getSecond()).append("\n"); return b.toString(); diff --git a/config-model/src/test/java/com/yahoo/vespa/model/container/ml/ModelsEvaluatorTest.java b/config-model/src/test/java/com/yahoo/vespa/model/container/ml/ModelsEvaluatorTest.java index f246b87d9bf..3deeef7f2a2 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/container/ml/ModelsEvaluatorTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/container/ml/ModelsEvaluatorTest.java @@ -18,8 +18,11 @@ import static org.junit.Assume.assumeTrue; public class ModelsEvaluatorTest { @Test - public void testModelsEvaluatorTester() { + public void testModelsEvaluator() { + // Assumption fails but test passes on Intel macs + // Assumption fails and test fails on ARM64 assumeTrue(OnnxEvaluator.isRuntimeAvailable()); + ModelsEvaluator modelsEvaluator = ModelsEvaluatorTester.create("src/test/cfg/application/stateless_eval"); assertEquals(3, modelsEvaluator.models().size()); diff --git a/config-model/src/test/java/com/yahoo/vespa/model/ml/ImportedModelTester.java b/config-model/src/test/java/com/yahoo/vespa/model/ml/ImportedModelTester.java index 556d91acb70..bd07513b704 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/ml/ImportedModelTester.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/ml/ImportedModelTester.java @@ -1,6 +1,7 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.model.ml; +import com.yahoo.config.FileReference; import com.yahoo.config.model.ApplicationPackageTester; import ai.vespa.rankingexpression.importer.configmodelview.MlModelImporter; import com.yahoo.config.model.deploy.DeployState; @@ -22,9 +23,9 @@ import java.io.UncheckedIOException; import java.util.List; import java.util.Optional; -import static junit.framework.TestCase.assertTrue; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; /** * Helper for testing of imported models. @@ -74,6 +75,8 @@ public class ImportedModelTester { assertEquals(constantName, constant.getName()); assertTrue(constant.getFileName().endsWith(constantApplicationPackagePath.toString())); + assertTrue(model.fileReferences().contains(new FileReference(constant.getFileName()))); + if (expectedSize.isPresent()) { Path constantPath = applicationDir.append(constantApplicationPackagePath); assertTrue("Constant file '" + constantPath + "' has been written", diff --git a/config-model/src/test/java/com/yahoo/vespa/model/search/test/DocumentDatabaseTestCase.java b/config-model/src/test/java/com/yahoo/vespa/model/search/test/DocumentDatabaseTestCase.java index 059c1ceb208..d541a6422e7 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/search/test/DocumentDatabaseTestCase.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/search/test/DocumentDatabaseTestCase.java @@ -42,21 +42,21 @@ public class DocumentDatabaseTestCase { @Test public void requireThatConcurrencyIsReflectedCorrectlyForDefault() { - verifyConcurrency("index", "", 0.50, 0.50); - verifyConcurrency("streaming", "", 1.0, 0.0); - verifyConcurrency("store-only", "", 1.0, 0.0); + verifyConcurrency("index", "", 0.50); + verifyConcurrency("streaming", "", 1.0); + verifyConcurrency("store-only", "", 1.0); } @Test public void requireThatFeatureFlagConcurrencyIsReflectedCorrectlyForDefault() { - verifyConcurrency("index", "", 0.30, 0.30, 0.3); - verifyConcurrency("streaming", "", 0.6, 0.0, 0.3); - verifyConcurrency("store-only", "", 0.8, 0.0, 0.4); + verifyConcurrency("index", "", 0.30, 0.3); + verifyConcurrency("streaming", "", 0.6, 0.3); + verifyConcurrency("store-only", "", 0.8, 0.4); } @Test public void requireThatMixedModeConcurrencyIsReflectedCorrectlyForDefault() { - verifyConcurrency(Arrays.asList(DocType.create("a", "index"), DocType.create("b", "streaming")), "", 1.0, Arrays.asList(0.50, 0.0)); + verifyConcurrency(Arrays.asList(DocType.create("a", "index"), DocType.create("b", "streaming")), "", 1.0); } @Test @@ -64,7 +64,7 @@ public class DocumentDatabaseTestCase { String feedTuning = "<feeding>" + " <concurrency>0.7</concurrency>" + "</feeding>\n"; - verifyConcurrency(Arrays.asList(DocType.create("a", "index"), DocType.create("b", "streaming")), feedTuning, 0.7, Arrays.asList(0.7, 0.0)); + verifyConcurrency(Arrays.asList(DocType.create("a", "index"), DocType.create("b", "streaming")), feedTuning, 0.7); } @Test @@ -72,25 +72,24 @@ public class DocumentDatabaseTestCase { String feedTuning = "<feeding>" + " <concurrency>0.7</concurrency>" + "</feeding>\n"; - verifyConcurrency("index", feedTuning, 0.7, 0.7); - verifyConcurrency("streaming", feedTuning, 0.7, 0.0); - verifyConcurrency("store-only", feedTuning, 0.7, 0.0); + verifyConcurrency("index", feedTuning, 0.7); + verifyConcurrency("streaming", feedTuning, 0.7); + verifyConcurrency("store-only", feedTuning, 0.7); } - private void verifyConcurrency(String mode, String xmlTuning, double global, double local, double featureFlagConcurrency) { - verifyConcurrency(Arrays.asList(DocType.create("a", mode)), xmlTuning, global, Arrays.asList(local), featureFlagConcurrency); + private void verifyConcurrency(String mode, String xmlTuning, double expectedConcurrency, double featureFlagConcurrency) { + verifyConcurrency(Arrays.asList(DocType.create("a", mode)), xmlTuning, expectedConcurrency, featureFlagConcurrency); } - private void verifyConcurrency(String mode, String xmlTuning, double global, double local) { - verifyConcurrency(Arrays.asList(DocType.create("a", mode)), xmlTuning, global, Arrays.asList(local), null); + private void verifyConcurrency(String mode, String xmlTuning, double expectedConcurrency) { + verifyConcurrency(Arrays.asList(DocType.create("a", mode)), xmlTuning, expectedConcurrency, null); } - private void verifyConcurrency(List<DocType> nameAndModes, String xmlTuning, double global, List<Double> local) { - verifyConcurrency(nameAndModes, xmlTuning, global, local, null); + private void verifyConcurrency(List<DocType> nameAndModes, String xmlTuning, double expectedConcurrency) { + verifyConcurrency(nameAndModes, xmlTuning, expectedConcurrency, null); } - private void verifyConcurrency(List<DocType> nameAndModes, String xmlTuning, double global, List<Double> local, Double featureFlagConcurrency) { - assertEquals(nameAndModes.size(), local.size()); + private void verifyConcurrency(List<DocType> nameAndModes, String xmlTuning, double expectedConcurrency, Double featureFlagConcurrency) { TestProperties properties = new TestProperties(); if (featureFlagConcurrency != null) { properties.setFeedConcurrency(featureFlagConcurrency); @@ -99,11 +98,7 @@ public class DocumentDatabaseTestCase { VespaModel model = tester.createModel(nameAndModes, xmlTuning, new DeployState.Builder().properties(properties)); ContentSearchCluster contentSearchCluster = model.getContentClusters().get("test").getSearch(); ProtonConfig proton = tester.getProtonConfig(contentSearchCluster); - assertEquals(global, proton.feeding().concurrency(), SMALL); - assertEquals(local.size(), proton.documentdb().size()); - for (int i = 0; i < local.size(); i++) { - assertEquals(local.get(i), proton.documentdb(i).feeding().concurrency(), SMALL); - } + assertEquals(expectedConcurrency, proton.feeding().concurrency(), SMALL); } @Test |