diff options
author | Harald Musum <musum@verizonmedia.com> | 2021-11-05 11:43:19 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-05 11:43:19 +0100 |
commit | 7e6517d5a039f1f3bc6551ec7baff9616cefa24a (patch) | |
tree | 03b9016df6561f912f61b195b66083a27e5b350b | |
parent | 6b48d8014e6284f67a5291f18fdbd233771dcd53 (diff) | |
parent | 8709b88bb1ab50242687706217cf843fb9f6452c (diff) |
Merge pull request #19885 from vespa-engine/balder/avoid-keeping-large-expressions-alive-longer-than-necessary
LargeExpressions are not needed in the vespa-model after construction…
-rw-r--r-- | config-model/src/main/java/com/yahoo/vespa/model/VespaModel.java | 21 | ||||
-rw-r--r-- | config-model/src/test/java/com/yahoo/vespa/model/ml/ImportedModelTester.java | 10 |
2 files changed, 13 insertions, 18 deletions
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/VespaModel.java b/config-model/src/main/java/com/yahoo/vespa/model/VespaModel.java index 92e1226ddf6..362b3f3a75c 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/VespaModel.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/VespaModel.java @@ -128,11 +128,6 @@ public final class VespaModel extends AbstractConfigProducerRoot implements Seri /** The global ranking constants of this model */ private final RankingConstants rankingConstants; - /** Large rank expression files of this */ - private final LargeRankExpressions largeRankExpressions; - - private final FileRegistry fileRegistry; - /** The validation overrides of this. This is never null. */ private final ValidationOverrides validationOverrides; @@ -176,8 +171,6 @@ public final class VespaModel extends AbstractConfigProducerRoot implements Seri throws IOException, SAXException { super("vespamodel"); version = deployState.getVespaVersion(); - fileRegistry = deployState.getFileRegistry(); - largeRankExpressions = new LargeRankExpressions(deployState.getFileRegistry()); rankingConstants = new RankingConstants(deployState.getFileRegistry(), Optional.empty()); validationOverrides = deployState.validationOverrides(); applicationPackage = deployState.getApplicationPackage(); @@ -185,10 +178,10 @@ public final class VespaModel extends AbstractConfigProducerRoot implements Seri VespaModelBuilder builder = new VespaDomBuilder(); root = builder.getRoot(VespaModel.ROOT_CONFIGID, deployState, this); - createGlobalRankProfiles(deployState); + createGlobalRankProfiles(deployState, rankingConstants, deployState.getFileRegistry()); rankProfileList = new RankProfileList(null, // null search -> global rankingConstants, - largeRankExpressions, + new LargeRankExpressions(deployState.getFileRegistry()), new OnnxModels(deployState.getFileRegistry(), Optional.empty()), AttributeFields.empty, deployState.rankProfileRegistry(), @@ -289,7 +282,7 @@ public final class VespaModel extends AbstractConfigProducerRoot implements Seri * Creates a rank profile not attached to any search definition, for each imported model in the application package, * and adds it to the given rank profile registry. */ - private void createGlobalRankProfiles(DeployState deployState) { + private void createGlobalRankProfiles(DeployState deployState, RankingConstants rankingConstants, FileRegistry fileRegistry) { var importedModels = deployState.getImportedModels().all(); DeployLogger deployLogger = deployState.getDeployLogger(); RankProfileRegistry rankProfileRegistry = deployState.rankProfileRegistry(); @@ -298,7 +291,7 @@ public final class VespaModel extends AbstractConfigProducerRoot implements Seri if ( ! importedModels.isEmpty()) { // models/ directory is available for (ImportedMlModel model : importedModels) { // Due to automatic naming not guaranteeing unique names, there must be a 1-1 between OnnxModels and global RankProfiles. - OnnxModels onnxModels = onnxModelInfoFromSource(model); + OnnxModels onnxModels = onnxModelInfoFromSource(model, fileRegistry); RankProfile profile = new RankProfile(model.name(), applicationPackage, deployLogger, rankProfileRegistry, rankingConstants, onnxModels); rankProfileRegistry.add(profile); futureModels.add(deployState.getExecutor().submit(() -> { @@ -315,7 +308,7 @@ public final class VespaModel extends AbstractConfigProducerRoot implements Seri String modelName = generatedModelDir.getPath().last(); if (modelName.contains(".")) continue; // Name space: Not a global profile // Due to automatic naming not guaranteeing unique names, there must be a 1-1 between OnnxModels and global RankProfiles. - OnnxModels onnxModels = onnxModelInfoFromStore(modelName); + OnnxModels onnxModels = onnxModelInfoFromStore(modelName, fileRegistry); RankProfile profile = new RankProfile(modelName, applicationPackage, deployLogger, rankProfileRegistry, rankingConstants, onnxModels); rankProfileRegistry.add(profile); futureModels.add(deployState.getExecutor().submit(() -> { @@ -335,7 +328,7 @@ public final class VespaModel extends AbstractConfigProducerRoot implements Seri new Processing().processRankProfiles(deployLogger, rankProfileRegistry, queryProfiles, true, false); } - private OnnxModels onnxModelInfoFromSource(ImportedMlModel model) { + private OnnxModels onnxModelInfoFromSource(ImportedMlModel model, FileRegistry fileRegistry) { OnnxModels onnxModels = new OnnxModels(fileRegistry, Optional.empty()); if (model.modelType().equals(ImportedMlModel.ModelType.ONNX)) { String path = model.source(); @@ -348,7 +341,7 @@ public final class VespaModel extends AbstractConfigProducerRoot implements Seri return onnxModels; } - private OnnxModels onnxModelInfoFromStore(String modelName) { + private OnnxModels onnxModelInfoFromStore(String modelName, FileRegistry fileRegistry) { String path = ApplicationPackage.MODELS_DIR.append(modelName + ".onnx").toString(); OnnxModels onnxModels = new OnnxModels(fileRegistry, Optional.empty()); loadOnnxModelInfo(onnxModels, modelName, path); 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 e3362a08048..a1fc13adf5c 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 @@ -42,18 +42,20 @@ public class ImportedModelTester { private final String modelName; private final Path applicationDir; + private final DeployState deployState; public ImportedModelTester(String modelName, Path applicationDir) { this.modelName = modelName; this.applicationDir = applicationDir; + deployState = new DeployState.Builder() + .applicationPackage(ApplicationPackageTester.create(applicationDir.toString()).app()) + .modelImporters(importers) + .build(); } public VespaModel createVespaModel() { try { - DeployState.Builder state = new DeployState.Builder(); - state.applicationPackage(ApplicationPackageTester.create(applicationDir.toString()).app()); - state.modelImporters(importers); - return new VespaModel(state.build()); + return new VespaModel(deployState); } catch (SAXException | IOException e) { throw new RuntimeException(e); |