diff options
author | Jon Bratseth <bratseth@gmail.com> | 2022-04-29 16:21:20 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2022-04-29 16:21:20 +0200 |
commit | ff32f4efa2fb814c406703f0c6302c817865c2cd (patch) | |
tree | 345bc93bda1e7a35f47acd9a283a230a62ada596 /model-evaluation | |
parent | 34fb52a1026ca3027f47c42c10af6e53fe12618d (diff) |
Allow models referencing functions they don't define
ML models may not be designed to be used standalone
but only in context of another ranking expression,
which then supplies functions referenced by the model.
Tolerate such models in stateløess evaluation.
Diffstat (limited to 'model-evaluation')
3 files changed, 7 insertions, 2 deletions
diff --git a/model-evaluation/src/main/java/ai/vespa/models/evaluation/LazyArrayContext.java b/model-evaluation/src/main/java/ai/vespa/models/evaluation/LazyArrayContext.java index d97235d11d2..3314ecb23fc 100644 --- a/model-evaluation/src/main/java/ai/vespa/models/evaluation/LazyArrayContext.java +++ b/model-evaluation/src/main/java/ai/vespa/models/evaluation/LazyArrayContext.java @@ -237,7 +237,9 @@ public final class LazyArrayContext extends Context implements ContextIndex { FunctionReference reference = FunctionReference.fromSerial(node.toString()).get(); bindTargets.add(reference.serialForm()); - ExpressionNode functionNode = functions.get(reference).getBody().getRoot(); + ExpressionFunction function = functions.get(reference); + if (function == null) return; // Function not included in this model: Not all models are for standalone use + ExpressionNode functionNode = function.getBody().getRoot(); extractBindTargets(functionNode, functions, bindTargets, arguments, onnxModels, onnxModelsInUse); } else if (isOnnx(node)) { diff --git a/model-evaluation/src/test/java/ai/vespa/models/evaluation/MlModelsImportingTest.java b/model-evaluation/src/test/java/ai/vespa/models/evaluation/MlModelsImportingTest.java index f3434011401..6a66202609b 100644 --- a/model-evaluation/src/test/java/ai/vespa/models/evaluation/MlModelsImportingTest.java +++ b/model-evaluation/src/test/java/ai/vespa/models/evaluation/MlModelsImportingTest.java @@ -25,7 +25,7 @@ public class MlModelsImportingTest { public void testImportingModels() { ModelTester tester = new ModelTester("src/test/resources/config/models/"); - assertEquals(6, tester.models().size()); + assertEquals(7, tester.models().size()); // TODO: When we get type information in Models, replace the evaluator.context().names() check below by that { diff --git a/model-evaluation/src/test/resources/config/models/rank-profiles.cfg b/model-evaluation/src/test/resources/config/models/rank-profiles.cfg index 4877a24f171..c00a8bbb32d 100644 --- a/model-evaluation/src/test/resources/config/models/rank-profiles.cfg +++ b/model-evaluation/src/test/resources/config/models/rank-profiles.cfg @@ -38,3 +38,6 @@ rankprofile[5].fef.property[2].name "rankingExpression(test_mixed).rankingScript rankprofile[5].fef.property[2].value "tensor(x{},y[3]):{a:[1,2,3], b:[4,5,6]}" rankprofile[5].fef.property[3].name "rankingExpression(test_mixed_2).rankingScript" rankprofile[5].fef.property[3].value "tensor(a[2],b[2],c{},d[2]):{a:[[[1,2], [3,4]], [[5,6], [7,8]]], b:[[[1,2], [3,4]], [[5,6], [7,8]]] }" +rankprofile[6].name "xgboost_non_standalone" +rankprofile[6].fef.property[0].name "rankingExpression(xgboost_non_standalone).rankingScript" +rankprofile[6].fef.property[0].value "if (rankingExpression(someFunction) < 1, 2, 3)" |