summaryrefslogtreecommitdiffstats
path: root/config-model-api/src
diff options
context:
space:
mode:
Diffstat (limited to 'config-model-api/src')
-rw-r--r--config-model-api/src/main/java/com/yahoo/config/application/api/ApplicationFile.java22
-rw-r--r--config-model-api/src/main/java/com/yahoo/config/model/api/OnnxMemoryStats.java49
-rw-r--r--config-model-api/src/main/java/com/yahoo/config/model/api/OnnxModelCost.java25
3 files changed, 75 insertions, 21 deletions
diff --git a/config-model-api/src/main/java/com/yahoo/config/application/api/ApplicationFile.java b/config-model-api/src/main/java/com/yahoo/config/application/api/ApplicationFile.java
index 36d6efdf59b..d262c7bc862 100644
--- a/config-model-api/src/main/java/com/yahoo/config/application/api/ApplicationFile.java
+++ b/config-model-api/src/main/java/com/yahoo/config/application/api/ApplicationFile.java
@@ -27,21 +27,21 @@ public abstract class ApplicationFile implements Comparable<ApplicationFile> {
}
/**
- * Check whether or not this file is a directory.
+ * Checks whether this file is a directory.
*
* @return true if it is, false if not.
*/
public abstract boolean isDirectory();
/**
- * Test whether or not this file exists.
+ * Tests whether this file exists.
*
* @return true if it exists, false if not.
*/
public abstract boolean exists();
/**
- * Create a {@link Reader} for the contents of this file.
+ * Creates a {@link Reader} for the contents of this file.
*
* @return A {@link Reader} that should be closed after use.
* @throws FileNotFoundException if the file is not found.
@@ -50,7 +50,7 @@ public abstract class ApplicationFile implements Comparable<ApplicationFile> {
/**
- * Create an {@link InputStream} for the contents of this file.
+ * Creates an {@link InputStream} for the contents of this file.
*
* @return An {@link InputStream} that should be closed after use.
* @throws FileNotFoundException if the file is not found.
@@ -58,7 +58,7 @@ public abstract class ApplicationFile implements Comparable<ApplicationFile> {
public abstract InputStream createInputStream() throws FileNotFoundException;
/**
- * Create a directory at the path represented by this file. Parent directories will
+ * Creates a directory at the path represented by this file. Parent directories will
* be automatically created.
*
* @return this
@@ -67,7 +67,7 @@ public abstract class ApplicationFile implements Comparable<ApplicationFile> {
public abstract ApplicationFile createDirectory();
/**
- * Write the contents from this reader to this file. Any existing content will be overwritten!
+ * Writes the contents from supplied reader to this file. Any existing content will be overwritten!
*
* @param input A reader pointing to the content that should be written.
* @return this
@@ -82,7 +82,7 @@ public abstract class ApplicationFile implements Comparable<ApplicationFile> {
public abstract ApplicationFile appendFile(String value);
/**
- * List the files under this directory. If this is file, an empty list is returned.
+ * Lists the files under this directory. If this is file, an empty list is returned.
* Only immediate files/subdirectories are returned.
*
* @return a list of files in this directory.
@@ -92,7 +92,7 @@ public abstract class ApplicationFile implements Comparable<ApplicationFile> {
}
/**
- * List the files under this directory. If this is file, an empty list is returned.
+ * Lists the files under this directory. If this is a file, an empty list is returned.
* Only immediate files/subdirectories are returned.
*
* @param filter A filter functor for filtering path names
@@ -101,7 +101,7 @@ public abstract class ApplicationFile implements Comparable<ApplicationFile> {
public abstract List<ApplicationFile> listFiles(PathFilter filter);
/**
- * List the files in this directory, optionally list files for subdirectories recursively as well.
+ * Lists the files in this directory, optionally lists files for subdirectories recursively as well.
*
* @param recurse Set to true if all files in the directory tree should be returned.
* @return a list of files in this directory.
@@ -121,7 +121,7 @@ public abstract class ApplicationFile implements Comparable<ApplicationFile> {
}
/**
- * Delete the file pointed to by this. If it is a non-empty directory, the operation will throw.
+ * Deletes the file pointed to by this. If this is a non-empty directory, the operation will throw.
*
* @return this.
* @throws RuntimeException if the file is a directory and not empty.
@@ -129,7 +129,7 @@ public abstract class ApplicationFile implements Comparable<ApplicationFile> {
public abstract ApplicationFile delete();
/**
- * Get the path that this file represents.
+ * Gets the path that this file represents.
*
* @return a Path
*/
diff --git a/config-model-api/src/main/java/com/yahoo/config/model/api/OnnxMemoryStats.java b/config-model-api/src/main/java/com/yahoo/config/model/api/OnnxMemoryStats.java
new file mode 100644
index 00000000000..4e660c6fe73
--- /dev/null
+++ b/config-model-api/src/main/java/com/yahoo/config/model/api/OnnxMemoryStats.java
@@ -0,0 +1,49 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+package com.yahoo.config.model.api;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.yahoo.config.application.api.ApplicationFile;
+import com.yahoo.config.application.api.ApplicationPackage;
+import com.yahoo.path.Path;
+
+import java.io.IOException;
+import java.util.Optional;
+
+/**
+ * Memory statistics as reported by vespa-analyze-onnx-model.
+ *
+ * @author bjorncs
+ */
+public record OnnxMemoryStats(long vmSize, long vmRss, long mallocPeak, long mallocCurrent) {
+ private static final String VM_SIZE_FIELD = "vm_size", VM_RSS_FIELD = "vm_rss",
+ MALLOC_PEAK_FIELD = "malloc_peak", MALLOC_CURRENT_FIELD = "malloc_current";
+ private static final ObjectMapper jsonParser = new ObjectMapper();
+
+ /** Parse output from `vespa-analyze-onnx-model --probe-types` */
+ public static OnnxMemoryStats fromJson(JsonNode json) {
+ return new OnnxMemoryStats(json.get(VM_SIZE_FIELD).asLong(), json.get(VM_RSS_FIELD).asLong(),
+ // Temporarily allow missing fields until old config model versions are gone
+ Optional.ofNullable(json.get(MALLOC_PEAK_FIELD)).map(JsonNode::asLong).orElse(0L),
+ Optional.ofNullable(json.get(MALLOC_CURRENT_FIELD)).map(JsonNode::asLong).orElse(0L));
+ }
+
+ /** @see #fromJson(JsonNode) */
+ public static OnnxMemoryStats fromJson(ApplicationFile file) throws IOException {
+ return fromJson(jsonParser.readTree(file.createReader()));
+ }
+
+ public static Path memoryStatsFilePath(Path modelPath) {
+ var fileName = modelPath.getRelative().replaceAll("[^\\w\\d\\$@_]", "_") + ".memory_stats";
+ return ApplicationPackage.MODELS_GENERATED_REPLICATED_DIR.append(fileName);
+ }
+
+ public long peakMemoryUsage() { return Long.max(vmSize, Long.max(vmRss, Long.max(mallocPeak, mallocCurrent))); }
+
+ public JsonNode toJson() {
+ return jsonParser.createObjectNode().put(VM_SIZE_FIELD, vmSize).put(VM_RSS_FIELD, vmRss)
+ .put(MALLOC_PEAK_FIELD, mallocPeak).put(MALLOC_CURRENT_FIELD, mallocCurrent);
+ }
+}
+
diff --git a/config-model-api/src/main/java/com/yahoo/config/model/api/OnnxModelCost.java b/config-model-api/src/main/java/com/yahoo/config/model/api/OnnxModelCost.java
index e6fe3ce18b5..abfddfe40be 100644
--- a/config-model-api/src/main/java/com/yahoo/config/model/api/OnnxModelCost.java
+++ b/config-model-api/src/main/java/com/yahoo/config/model/api/OnnxModelCost.java
@@ -2,10 +2,10 @@
package com.yahoo.config.model.api;
-import com.yahoo.config.ModelReference;
import com.yahoo.config.application.api.ApplicationFile;
import com.yahoo.config.application.api.ApplicationPackage;
import com.yahoo.config.application.api.DeployLogger;
+import com.yahoo.config.provision.ApplicationId;
import java.net.URI;
@@ -14,21 +14,26 @@ import java.net.URI;
*/
public interface OnnxModelCost {
- Calculator newCalculator(ApplicationPackage appPkg, DeployLogger logger);
+ // TODO: Remove when 8.250 is oldest model in use
+ default Calculator newCalculator(ApplicationPackage appPkg, DeployLogger deployLogger) {
+ return newCalculator(appPkg, ApplicationId.defaultId());
+ }
+
+ Calculator newCalculator(ApplicationPackage appPkg, ApplicationId applicationId);
interface Calculator {
long aggregatedModelCostInBytes();
void registerModel(ApplicationFile path);
- @Deprecated(forRemoval = true) void registerModel(ModelReference ref); // TODO(bjorncs): remove once no longer in use by old config models
void registerModel(URI uri);
}
- static OnnxModelCost disabled() {
- return (__, ___) -> new Calculator() {
- @Override public long aggregatedModelCostInBytes() { return 0; }
- @Override public void registerModel(ApplicationFile path) {}
- @SuppressWarnings("removal") @Override public void registerModel(ModelReference ref) {}
- @Override public void registerModel(URI uri) {}
- };
+ static OnnxModelCost disabled() { return new DisabledOnnxModelCost(); }
+
+ class DisabledOnnxModelCost implements OnnxModelCost, Calculator {
+ @Override public Calculator newCalculator(ApplicationPackage appPkg, ApplicationId applicationId) { return this; }
+ @Override public long aggregatedModelCostInBytes() {return 0;}
+ @Override public void registerModel(ApplicationFile path) {}
+ @Override public void registerModel(URI uri) {}
}
+
}