diff options
author | Jon Bratseth <bratseth@gmail.com> | 2023-03-01 16:33:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-01 16:33:05 +0100 |
commit | 7812f8fea31fcbb5ae636f27e05ae8d3ba485c97 (patch) | |
tree | f5e6f6c446d9f707763472fc939c8fb2b5137a7c | |
parent | 8a2f4892657953379ed00a225916f128f0feec97 (diff) | |
parent | b44cb70c0587eaf1b902dc28f5f9b5a7c6c96515 (diff) |
Merge pull request #26256 from vespa-engine/arnej/handle-more-rank-profiles
Arnej/handle more rank profiles
6 files changed, 187 insertions, 8 deletions
diff --git a/model-evaluation/src/main/java/ai/vespa/models/evaluation/FunctionReference.java b/model-evaluation/src/main/java/ai/vespa/models/evaluation/FunctionReference.java index 53592be7883..46134074137 100644 --- a/model-evaluation/src/main/java/ai/vespa/models/evaluation/FunctionReference.java +++ b/model-evaluation/src/main/java/ai/vespa/models/evaluation/FunctionReference.java @@ -24,13 +24,13 @@ import java.util.regex.Pattern; class FunctionReference { private static final Pattern referencePattern = - Pattern.compile("rankingExpression\\(([a-zA-Z0-9_.]+)(@[a-f0-9]+\\.[a-f0-9]+)?\\)(\\.rankingScript)?"); + Pattern.compile("rankingExpression\\(([a-zA-Z0-9_.]+)(@[a-f0-9]+[.a-f0-9]*)?\\)(\\.rankingScript)?"); private static final Pattern externalReferencePattern = - Pattern.compile("rankingExpression\\(([a-zA-Z0-9_.]+)(@[a-f0-9]+\\.[a-f0-9]+)?\\)(\\.expressionName)?"); + Pattern.compile("rankingExpression\\(([a-zA-Z0-9_.]+)(@[a-f0-9]+[.a-f0-9]*)?\\)(\\.expressionName)?"); private static final Pattern argumentTypePattern = - Pattern.compile("rankingExpression\\(([a-zA-Z0-9_.]+)(@[a-f0-9]+\\.[a-f0-9]+)?\\)\\.([a-zA-Z0-9_]+)\\.type?"); + Pattern.compile("rankingExpression\\(([a-zA-Z0-9_.]+)(@[a-f0-9]+[.a-f0-9]*)?\\)\\.([a-zA-Z0-9_]+)\\.type"); private static final Pattern returnTypePattern = - Pattern.compile("rankingExpression\\(([a-zA-Z0-9_.]+)(@[a-f0-9]+\\.[a-f0-9]+)?\\)\\.type?"); + Pattern.compile("rankingExpression\\(([a-zA-Z0-9_.]+)(@[a-f0-9]+[.a-f0-9]*)?\\)\\.type"); /** The name of the function referenced */ private final String name; diff --git a/model-evaluation/src/main/java/ai/vespa/models/evaluation/Model.java b/model-evaluation/src/main/java/ai/vespa/models/evaluation/Model.java index 84c8e2b1e38..1da8121ba8e 100644 --- a/model-evaluation/src/main/java/ai/vespa/models/evaluation/Model.java +++ b/model-evaluation/src/main/java/ai/vespa/models/evaluation/Model.java @@ -99,13 +99,17 @@ public class Model implements AutoCloseable { } } this.contextPrototypes = Map.copyOf(contextBuilder); - this.functions = List.copyOf(functions.values()); + // Optimize free functions + this.functions = List.copyOf(functions.entrySet() + .stream() + .map(f -> optimize(f.getValue(), + contextPrototypes.get(f.getKey().functionName()))) + .collect(Collectors.toList())); + this.publicFunctions = functions.values().stream() .filter(f -> !f.getName().startsWith(INTERMEDIATE_OPERATION_FUNCTION_PREFIX)).toList(); - // Optimize functions - this.referencedFunctions = Map.copyOf(referencedFunctions.entrySet().stream() - .collect(CustomCollectors.toLinkedMap(f -> f.getKey(), f -> optimize(f.getValue(), contextPrototypes.get(f.getKey().functionName()))))); + this.referencedFunctions = Map.copyOf(referencedFunctions); this.closeActions = onnxModels.stream().map(o -> (Runnable)o::close).toList(); } diff --git a/model-evaluation/src/test/resources/config/expressions-as-arguments/onnx-models.cfg b/model-evaluation/src/test/resources/config/expressions-as-arguments/onnx-models.cfg new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/model-evaluation/src/test/resources/config/expressions-as-arguments/onnx-models.cfg diff --git a/model-evaluation/src/test/resources/config/expressions-as-arguments/rank-profiles.cfg b/model-evaluation/src/test/resources/config/expressions-as-arguments/rank-profiles.cfg new file mode 100644 index 00000000000..d8ccbeaf0fb --- /dev/null +++ b/model-evaluation/src/test/resources/config/expressions-as-arguments/rank-profiles.cfg @@ -0,0 +1,175 @@ +rankprofile[0].name "default" +rankprofile[0].fef.property[0].name "vespa.type.attribute.t1" +rankprofile[0].fef.property[0].value "tensor<float>(x{})" +rankprofile[0].fef.property[1].name "vespa.type.attribute.t2" +rankprofile[0].fef.property[1].value "tensor<float>(x{})" +rankprofile[1].name "unranked" +rankprofile[1].fef.property[0].name "vespa.rank.firstphase" +rankprofile[1].fef.property[0].value "value(0)" +rankprofile[1].fef.property[1].name "vespa.hitcollector.heapsize" +rankprofile[1].fef.property[1].value "0" +rankprofile[1].fef.property[2].name "vespa.hitcollector.arraysize" +rankprofile[1].fef.property[2].value "0" +rankprofile[1].fef.property[3].name "vespa.dump.ignoredefaultfeatures" +rankprofile[1].fef.property[3].value "true" +rankprofile[1].fef.property[4].name "vespa.type.attribute.t1" +rankprofile[1].fef.property[4].value "tensor<float>(x{})" +rankprofile[1].fef.property[5].name "vespa.type.attribute.t2" +rankprofile[1].fef.property[5].value "tensor<float>(x{})" +rankprofile[2].name "test" +rankprofile[2].fef.property[0].name "rankingExpression(my_square@31852fecfab75f29).rankingScript" +rankprofile[2].fef.property[0].value "2 * 2" +rankprofile[2].fef.property[1].name "rankingExpression(my_square@56bfa257b4b447a2).rankingScript" +rankprofile[2].fef.property[1].value "-3.14 * -3.14" +rankprofile[2].fef.property[2].name "rankingExpression(test_constant).rankingScript" +rankprofile[2].fef.property[2].value "rankingExpression(my_square@31852fecfab75f29) + rankingExpression(my_square@56bfa257b4b447a2)" +rankprofile[2].fef.property[3].name "rankingExpression(autogenerated_ranking_feature@c76aeb97d0b6610c).rankingScript" +rankprofile[2].fef.property[3].value "attribute(i1) * 2" +rankprofile[2].fef.property[4].name "rankingExpression(my_square@52d8ef83411bc8d0).rankingScript" +rankprofile[2].fef.property[4].value "rankingExpression(autogenerated_ranking_feature@c76aeb97d0b6610c) * rankingExpression(autogenerated_ranking_feature@c76aeb97d0b6610c)" +rankprofile[2].fef.property[5].name "rankingExpression(autogenerated_ranking_feature@828fd0618dc7fc06).rankingScript" +rankprofile[2].fef.property[5].value "attribute(i1) < 1" +rankprofile[2].fef.property[6].name "rankingExpression(my_square@6b77cba8e7358f11).rankingScript" +rankprofile[2].fef.property[6].value "rankingExpression(autogenerated_ranking_feature@828fd0618dc7fc06) * rankingExpression(autogenerated_ranking_feature@828fd0618dc7fc06)" +rankprofile[2].fef.property[7].name "rankingExpression(test_arithmetic).rankingScript" +rankprofile[2].fef.property[7].value "rankingExpression(my_square@52d8ef83411bc8d0) + rankingExpression(my_square@6b77cba8e7358f11)" +rankprofile[2].fef.property[8].name "rankingExpression(autogenerated_ranking_feature@675b0f8c6790c8bb).rankingScript" +rankprofile[2].fef.property[8].value "!attribute(i1)" +rankprofile[2].fef.property[9].name "rankingExpression(my_square@35879139f3786e2f).rankingScript" +rankprofile[2].fef.property[9].value "rankingExpression(autogenerated_ranking_feature@675b0f8c6790c8bb) * rankingExpression(autogenerated_ranking_feature@675b0f8c6790c8bb)" +rankprofile[2].fef.property[10].name "rankingExpression(autogenerated_ranking_feature@6084beaceb676bf2).rankingScript" +rankprofile[2].fef.property[10].value "-attribute(i1)" +rankprofile[2].fef.property[11].name "rankingExpression(my_square@819381f707f3ee78).rankingScript" +rankprofile[2].fef.property[11].value "rankingExpression(autogenerated_ranking_feature@6084beaceb676bf2) * rankingExpression(autogenerated_ranking_feature@6084beaceb676bf2)" +rankprofile[2].fef.property[12].name "rankingExpression(test_not_neg).rankingScript" +rankprofile[2].fef.property[12].value "rankingExpression(my_square@35879139f3786e2f) + rankingExpression(my_square@819381f707f3ee78)" +rankprofile[2].fef.property[13].name "rankingExpression(autogenerated_ranking_feature@b41d2fa3c2ee40a3).rankingScript" +rankprofile[2].fef.property[13].value "if (attribute(i1) in [0, 1, 2], 0, 1)" +rankprofile[2].fef.property[14].name "rankingExpression(my_square@643af1a7339a8b1b).rankingScript" +rankprofile[2].fef.property[14].value "rankingExpression(autogenerated_ranking_feature@b41d2fa3c2ee40a3) * rankingExpression(autogenerated_ranking_feature@b41d2fa3c2ee40a3)" +rankprofile[2].fef.property[15].name "rankingExpression(autogenerated_ranking_feature@335f7caa94692e97).rankingScript" +rankprofile[2].fef.property[15].value "attribute(i1) in [0, 1, 2]" +rankprofile[2].fef.property[16].name "rankingExpression(my_square@d48185ac029647a5).rankingScript" +rankprofile[2].fef.property[16].value "rankingExpression(autogenerated_ranking_feature@335f7caa94692e97) * rankingExpression(autogenerated_ranking_feature@335f7caa94692e97)" +rankprofile[2].fef.property[17].name "rankingExpression(test_if_in).rankingScript" +rankprofile[2].fef.property[17].value "rankingExpression(my_square@643af1a7339a8b1b) + rankingExpression(my_square@d48185ac029647a5)" +rankprofile[2].fef.property[18].name "rankingExpression(my_square@9a5117ae5a6d491b).rankingScript" +rankprofile[2].fef.property[18].value "cos(attribute(i1)) * cos(attribute(i1))" +rankprofile[2].fef.property[19].name "rankingExpression(test_function).rankingScript" +rankprofile[2].fef.property[19].value "rankingExpression(my_square@9a5117ae5a6d491b)" +rankprofile[2].fef.property[20].name "rankingExpression(autogenerated_ranking_feature@6c8232a0cd94322d).rankingScript" +rankprofile[2].fef.property[20].value "(attribute(i1) * 2)" +rankprofile[2].fef.property[21].name "rankingExpression(my_square@181aa0cc505c1788).rankingScript" +rankprofile[2].fef.property[21].value "rankingExpression(autogenerated_ranking_feature@6c8232a0cd94322d) * rankingExpression(autogenerated_ranking_feature@6c8232a0cd94322d)" +rankprofile[2].fef.property[22].name "rankingExpression(test_embraced).rankingScript" +rankprofile[2].fef.property[22].value "rankingExpression(my_square@181aa0cc505c1788)" +rankprofile[2].fef.property[23].name "rankingExpression(my_func@9bbaee2bad5a2fc0).rankingScript" +rankprofile[2].fef.property[23].value "reduce(attribute(t1), sum, x) + 1" +rankprofile[2].fef.property[24].name "rankingExpression(test_func).rankingScript" +rankprofile[2].fef.property[24].value "rankingExpression(my_func@9bbaee2bad5a2fc0)" +rankprofile[2].fef.property[25].name "rankingExpression(autogenerated_ranking_feature@43bc412603c00a4a).rankingScript" +rankprofile[2].fef.property[25].value "attribute(t1) * attribute(t2)" +rankprofile[2].fef.property[26].name "rankingExpression(my_func@7f288a910482845a).rankingScript" +rankprofile[2].fef.property[26].value "reduce(rankingExpression(autogenerated_ranking_feature@43bc412603c00a4a), sum, x) + 1" +rankprofile[2].fef.property[27].name "rankingExpression(test_tensor_func_with_expr).rankingScript" +rankprofile[2].fef.property[27].value "rankingExpression(my_func@7f288a910482845a)" +rankprofile[2].fef.property[28].name "rankingExpression(autogenerated_ranking_feature@c1057dea8228da3a).rankingScript" +rankprofile[2].fef.property[28].value "map(attribute(t1), f(x)(x * x))" +rankprofile[2].fef.property[29].name "rankingExpression(my_func@901c2cc6ceb37765).rankingScript" +rankprofile[2].fef.property[29].value "reduce(rankingExpression(autogenerated_ranking_feature@c1057dea8228da3a), sum, x) + 1" +rankprofile[2].fef.property[30].name "rankingExpression(test_func_with_tensor_func).rankingScript" +rankprofile[2].fef.property[30].value "rankingExpression(my_func@901c2cc6ceb37765)" +rankprofile[2].fef.property[31].name "rankingExpression(autogenerated_ranking_feature@fb1a4642f23d9d05).rankingScript" +rankprofile[2].fef.property[31].value "attribute(t1){x:0}" +rankprofile[2].fef.property[32].name "rankingExpression(my_square@1d27f1b495b50910).rankingScript" +rankprofile[2].fef.property[32].value "rankingExpression(autogenerated_ranking_feature@fb1a4642f23d9d05) * rankingExpression(autogenerated_ranking_feature@fb1a4642f23d9d05)" +rankprofile[2].fef.property[33].name "rankingExpression(test_func_with_slice).rankingScript" +rankprofile[2].fef.property[33].value "rankingExpression(my_square@1d27f1b495b50910)" +rankprofile[2].fef.property[34].name "rankingExpression(call_func_with_expr@640470df47a83000.c156faa8f98c0b0c).rankingScript" +rankprofile[2].fef.property[34].value "rankingExpression(my_func@7f288a910482845a)" +rankprofile[2].fef.property[35].name "rankingExpression(test_func_via_func_with_expr).rankingScript" +rankprofile[2].fef.property[35].value "rankingExpression(call_func_with_expr@640470df47a83000.c156faa8f98c0b0c)" +rankprofile[2].fef.property[36].name "rankingExpression(my_square).rankingScript" +rankprofile[2].fef.property[36].value "x * x" +rankprofile[2].fef.property[37].name "rankingExpression(my_func).rankingScript" +rankprofile[2].fef.property[37].value "reduce(t, sum, x) + 1" +rankprofile[2].fef.property[38].name "rankingExpression(autogenerated_ranking_feature@1044065d971a7507).rankingScript" +rankprofile[2].fef.property[38].value "a * b" +rankprofile[2].fef.property[39].name "rankingExpression(my_func@93366be10bade547).rankingScript" +rankprofile[2].fef.property[39].value "reduce(rankingExpression(autogenerated_ranking_feature@1044065d971a7507), sum, x) + 1" +rankprofile[2].fef.property[40].name "rankingExpression(call_func_with_expr).rankingScript" +rankprofile[2].fef.property[40].value "rankingExpression(my_func@93366be10bade547)" +rankprofile[2].fef.property[41].name "vespa.rank.firstphase" +rankprofile[2].fef.property[41].value "rankingExpression(firstphase)" +rankprofile[2].fef.property[42].name "rankingExpression(firstphase).rankingScript" +rankprofile[2].fef.property[42].value "42" +rankprofile[2].fef.property[43].name "vespa.summary.feature" +rankprofile[2].fef.property[43].value "rankingExpression(test_constant)" +rankprofile[2].fef.property[44].name "vespa.summary.feature" +rankprofile[2].fef.property[44].value "rankingExpression(test_arithmetic)" +rankprofile[2].fef.property[45].name "vespa.summary.feature" +rankprofile[2].fef.property[45].value "rankingExpression(test_not_neg)" +rankprofile[2].fef.property[46].name "vespa.summary.feature" +rankprofile[2].fef.property[46].value "rankingExpression(test_if_in)" +rankprofile[2].fef.property[47].name "vespa.summary.feature" +rankprofile[2].fef.property[47].value "rankingExpression(test_function)" +rankprofile[2].fef.property[48].name "vespa.summary.feature" +rankprofile[2].fef.property[48].value "rankingExpression(test_embraced)" +rankprofile[2].fef.property[49].name "vespa.summary.feature" +rankprofile[2].fef.property[49].value "rankingExpression(test_func)" +rankprofile[2].fef.property[50].name "vespa.summary.feature" +rankprofile[2].fef.property[50].value "rankingExpression(test_tensor_func_with_expr)" +rankprofile[2].fef.property[51].name "vespa.summary.feature" +rankprofile[2].fef.property[51].value "rankingExpression(test_func_with_tensor_func)" +rankprofile[2].fef.property[52].name "vespa.summary.feature" +rankprofile[2].fef.property[52].value "rankingExpression(test_func_with_slice)" +rankprofile[2].fef.property[53].name "vespa.summary.feature" +rankprofile[2].fef.property[53].value "rankingExpression(test_func_via_func_with_expr)" +rankprofile[2].fef.property[54].name "vespa.feature.rename" +rankprofile[2].fef.property[54].value "rankingExpression(test_constant)" +rankprofile[2].fef.property[55].name "vespa.feature.rename" +rankprofile[2].fef.property[55].value "test_constant" +rankprofile[2].fef.property[56].name "vespa.feature.rename" +rankprofile[2].fef.property[56].value "rankingExpression(test_arithmetic)" +rankprofile[2].fef.property[57].name "vespa.feature.rename" +rankprofile[2].fef.property[57].value "test_arithmetic" +rankprofile[2].fef.property[58].name "vespa.feature.rename" +rankprofile[2].fef.property[58].value "rankingExpression(test_not_neg)" +rankprofile[2].fef.property[59].name "vespa.feature.rename" +rankprofile[2].fef.property[59].value "test_not_neg" +rankprofile[2].fef.property[60].name "vespa.feature.rename" +rankprofile[2].fef.property[60].value "rankingExpression(test_if_in)" +rankprofile[2].fef.property[61].name "vespa.feature.rename" +rankprofile[2].fef.property[61].value "test_if_in" +rankprofile[2].fef.property[62].name "vespa.feature.rename" +rankprofile[2].fef.property[62].value "rankingExpression(test_function)" +rankprofile[2].fef.property[63].name "vespa.feature.rename" +rankprofile[2].fef.property[63].value "test_function" +rankprofile[2].fef.property[64].name "vespa.feature.rename" +rankprofile[2].fef.property[64].value "rankingExpression(test_embraced)" +rankprofile[2].fef.property[65].name "vespa.feature.rename" +rankprofile[2].fef.property[65].value "test_embraced" +rankprofile[2].fef.property[66].name "vespa.feature.rename" +rankprofile[2].fef.property[66].value "rankingExpression(test_func)" +rankprofile[2].fef.property[67].name "vespa.feature.rename" +rankprofile[2].fef.property[67].value "test_func" +rankprofile[2].fef.property[68].name "vespa.feature.rename" +rankprofile[2].fef.property[68].value "rankingExpression(test_tensor_func_with_expr)" +rankprofile[2].fef.property[69].name "vespa.feature.rename" +rankprofile[2].fef.property[69].value "test_tensor_func_with_expr" +rankprofile[2].fef.property[70].name "vespa.feature.rename" +rankprofile[2].fef.property[70].value "rankingExpression(test_func_with_tensor_func)" +rankprofile[2].fef.property[71].name "vespa.feature.rename" +rankprofile[2].fef.property[71].value "test_func_with_tensor_func" +rankprofile[2].fef.property[72].name "vespa.feature.rename" +rankprofile[2].fef.property[72].value "rankingExpression(test_func_with_slice)" +rankprofile[2].fef.property[73].name "vespa.feature.rename" +rankprofile[2].fef.property[73].value "test_func_with_slice" +rankprofile[2].fef.property[74].name "vespa.feature.rename" +rankprofile[2].fef.property[74].value "rankingExpression(test_func_via_func_with_expr)" +rankprofile[2].fef.property[75].name "vespa.feature.rename" +rankprofile[2].fef.property[75].value "test_func_via_func_with_expr" +rankprofile[2].fef.property[76].name "vespa.type.attribute.t1" +rankprofile[2].fef.property[76].value "tensor<float>(x{})" +rankprofile[2].fef.property[77].name "vespa.type.attribute.t2" +rankprofile[2].fef.property[77].value "tensor<float>(x{})" diff --git a/model-evaluation/src/test/resources/config/expressions-as-arguments/ranking-constants.cfg b/model-evaluation/src/test/resources/config/expressions-as-arguments/ranking-constants.cfg new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/model-evaluation/src/test/resources/config/expressions-as-arguments/ranking-constants.cfg diff --git a/model-evaluation/src/test/resources/config/expressions-as-arguments/ranking-expressions.cfg b/model-evaluation/src/test/resources/config/expressions-as-arguments/ranking-expressions.cfg new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/model-evaluation/src/test/resources/config/expressions-as-arguments/ranking-expressions.cfg |