Skip to content

Commit

Permalink
Merge pull request #32486 from vespa-engine/interns/magnus/model-feat…
Browse files Browse the repository at this point in the history
…ures

Interns/magnus/model features
  • Loading branch information
Mangern authored Sep 27, 2024
2 parents 52b626e + 82a6928 commit 7a3a408
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import ai.vespa.schemals.parser.ast.functionElm;
import ai.vespa.schemals.parser.ast.inputName;
import ai.vespa.schemals.parser.ast.namedDocument;
import ai.vespa.schemals.parser.ast.onnxModel;
import ai.vespa.schemals.parser.ast.onnxModelInProfile;
import ai.vespa.schemals.parser.ast.rankProfile;
import ai.vespa.schemals.parser.ast.rootSchema;
import ai.vespa.schemals.parser.ast.structDefinitionElm;
Expand All @@ -40,6 +42,7 @@ public class SchemaIndex {
put(functionElm.class, SymbolType.FUNCTION);
put(inputName.class, SymbolType.QUERY_INPUT);
put(constantName.class, SymbolType.RANK_CONSTANT);
put(onnxModel.class, SymbolType.ONNX_MODEL);
}};

public static final HashMap<Class<?>, SymbolType> IDENTIFIER_WITH_DASH_TYPE_MAP = new HashMap<>() {{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public enum SymbolType {
LAMBDA_FUNCTION,
MAP_KEY,
MAP_VALUE,
ONNX_MODEL,
PARAMETER,
PROPERTY,
QUERY_INPUT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void updateFileContent(String content) {
this.CST = parsingResult.CST().get();
lexer.setCST(CST);

// logger.info("======== CST for file: " + fileURI + " ========");
//logger.info("======== CST for file: " + fileURI + " ========");

//CSTUtils.printTree(logger, CST);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,12 @@ public class BuiltInFunctions {
new EnumArgument("operation", List.of("sum", "product", "average", "min", "max", "count"))
))
)));

// === ML Model features ===
put("onnx", new GenericFunction("onnx", new FunctionSignature(new SymbolArgument(SymbolType.ONNX_MODEL, "onnx-model"))));
put("onnxModel", new GenericFunction("onnxModel", new FunctionSignature(new SymbolArgument(SymbolType.ONNX_MODEL, "onnx-model"))));
put("lightbgm", new GenericFunction("lightbgm", new FunctionSignature(new StringArgument("\"/path/to/lightbgm-model.json\""))));
put("xgboost", new GenericFunction("xgboost", new FunctionSignature(new StringArgument("\"/path/to/xgboost-model.json\""))));
}};

// Some features that have not gotten a signature for various reasons
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ Stream<DynamicTest> generateBadFileTests() {
new BadFileTestCase("../../../config-model/src/test/examples/simple.sd", 5), // TODO: unused rank-profile functions should throw errors? Also rank-type doesntexist: ... in field?

new BadFileTestCase("src/test/sdfiles/single/rankprofilefuncs.sd", 2),
new BadFileTestCase("src/test/sdfiles/single/onnxmodel.sd", 1),
};

return Arrays.stream(tests)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
schema onnxmodel {
document onnxmodel {
}

rank-profile profile {
first-phase {
expression: sum( onnxModel(mymodel).output_name )
}

second-phase {
expression: sum( onnx(noexist).nooutput ) # should give error
}

onnx-model mymodel {
file: files/something.onnx
}

function func_a() {
expression: sum(xgboost("xgboost.json"))
}

function func_b() {
expression: sum(lightbgm("/path/to/lightbgm-model.json"))
}
}
}

0 comments on commit 7a3a408

Please sign in to comment.