diff options
19 files changed, 194 insertions, 12 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c291c1952a..56ec901a924 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,6 +88,7 @@ add_subdirectory(container-apache-http-client-bundle) add_subdirectory(container-core) add_subdirectory(container-disc) add_subdirectory(container-messagebus) +add_subdirectory(container-onnxruntime) add_subdirectory(container-search) add_subdirectory(container-search-and-docproc) add_subdirectory(container-spifly) diff --git a/cloud-tenant-base-dependencies-enforcer/pom.xml b/cloud-tenant-base-dependencies-enforcer/pom.xml index 3fce00c3b16..9a640966f6d 100644 --- a/cloud-tenant-base-dependencies-enforcer/pom.xml +++ b/cloud-tenant-base-dependencies-enforcer/pom.xml @@ -28,7 +28,6 @@ <httpclient.version>4.5.13</httpclient.version> <httpcore.version>4.4.13</httpcore.version> <junit5.version>5.8.1</junit5.version> <!-- TODO: in parent this is named 'junit.version' --> - <onnxruntime.version>1.12.1</onnxruntime.version> <!-- END parent/pom.xml --> @@ -117,6 +116,7 @@ <include>com.yahoo.vespa:container-disc:*:provided</include> <include>com.yahoo.vespa:container-documentapi:*:provided</include> <include>com.yahoo.vespa:container-messagebus:*:provided</include> + <include>com.yahoo.vespa:container-onnxruntime:*:provided</include> <include>com.yahoo.vespa:container-search-and-docproc:*:provided</include> <include>com.yahoo.vespa:container-search:*:provided</include> <include>com.yahoo.vespa:container:*:provided</include> @@ -174,7 +174,6 @@ <include>com.google.code.findbugs:jsr305:3.0.2:test</include> <include>com.google.protobuf:protobuf-java:3.21.7:test</include> <include>com.ibm.icu:icu4j:70.1:test</include> - <include>com.microsoft.onnxruntime:onnxruntime:${onnxruntime.version}:test</include> <include>com.thaiopensource:jing:20091111:test</include> <include>commons-codec:commons-codec:${commons-codec.version}:test</include> <include>io.airlift:aircompressor:0.21:test</include> diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerModelEvaluation.java b/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerModelEvaluation.java index 088465f56b1..49292bd6df7 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerModelEvaluation.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerModelEvaluation.java @@ -28,12 +28,15 @@ public class ContainerModelEvaluation implements private final static String EVALUATION_BUNDLE_NAME = "model-evaluation"; private final static String INTEGRATION_BUNDLE_NAME = "model-integration"; + private final static String ONNXRUNTIME_BUNDLE_NAME = "container-onnxruntime.jar"; + private final static String EVALUATOR_NAME = ModelsEvaluator.class.getName(); private final static String REST_HANDLER_NAME = "ai.vespa.models.handler.ModelsEvaluationHandler"; private final static String REST_BINDING_PATH = "/model-evaluation/v1"; public static final Path MODEL_EVALUATION_BUNDLE_FILE = PlatformBundles.absoluteBundlePath(EVALUATION_BUNDLE_NAME); public static final Path MODEL_INTEGRATION_BUNDLE_FILE = PlatformBundles.absoluteBundlePath(INTEGRATION_BUNDLE_NAME); + public static final Path ONNXRUNTIME_BUNDLE_FILE = PlatformBundles.absoluteBundlePath(ONNXRUNTIME_BUNDLE_NAME); /** Global rank profiles, aka models */ private final RankProfileList rankProfileList; diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java b/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java index 159ab26414d..f3b7a28f227 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java @@ -710,6 +710,7 @@ public class ContainerModelBuilder extends ConfigModelBuilder<ContainerModel> { * in the model-evaluation bundle that could be used by customer code. */ cluster.addPlatformBundle(ContainerModelEvaluation.MODEL_EVALUATION_BUNDLE_FILE); cluster.addPlatformBundle(ContainerModelEvaluation.MODEL_INTEGRATION_BUNDLE_FILE); + cluster.addPlatformBundle(ContainerModelEvaluation.ONNXRUNTIME_BUNDLE_FILE); } private void addProcessing(DeployState deployState, Element spec, ApplicationContainerCluster cluster, ConfigModelContext context) { diff --git a/container-dev/pom.xml b/container-dev/pom.xml index 711afe72c62..e088c40e20b 100644 --- a/container-dev/pom.xml +++ b/container-dev/pom.xml @@ -80,6 +80,17 @@ </dependency> <dependency> <groupId>com.yahoo.vespa</groupId> + <artifactId>container-onnxruntime</artifactId> + <version>${project.version}</version> + <exclusions> + <exclusion> + <groupId>com.microsoft.onnxruntime</groupId> + <artifactId>onnxruntime</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>com.yahoo.vespa</groupId> <artifactId>container-disc</artifactId> <version>${project.version}</version> <exclusions> diff --git a/container-onnxruntime/.gitignore b/container-onnxruntime/.gitignore new file mode 100644 index 00000000000..916e17c097a --- /dev/null +++ b/container-onnxruntime/.gitignore @@ -0,0 +1 @@ +dependency-reduced-pom.xml diff --git a/container-onnxruntime/CMakeLists.txt b/container-onnxruntime/CMakeLists.txt new file mode 100644 index 00000000000..4eff1d26e60 --- /dev/null +++ b/container-onnxruntime/CMakeLists.txt @@ -0,0 +1,2 @@ +# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +install_jar(container-onnxruntime.jar) diff --git a/container-onnxruntime/README.md b/container-onnxruntime/README.md new file mode 100644 index 00000000000..ef332b88ba7 --- /dev/null +++ b/container-onnxruntime/README.md @@ -0,0 +1,4 @@ +<!-- Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. --> +# container-onnxruntime + +onnxruntime.ai repackaged as a bundle diff --git a/container-onnxruntime/pom.xml b/container-onnxruntime/pom.xml new file mode 100644 index 00000000000..854a4571028 --- /dev/null +++ b/container-onnxruntime/pom.xml @@ -0,0 +1,86 @@ +<?xml version="1.0"?> +<!-- Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. --> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 + http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <artifactId>container-onnxruntime</artifactId> + <packaging>container-plugin</packaging> + <version>8-SNAPSHOT</version> + <parent> + <groupId>com.yahoo.vespa</groupId> + <artifactId>parent</artifactId> + <version>8-SNAPSHOT</version> + <relativePath>../parent/pom.xml</relativePath> + </parent> + <properties> + <maven.javadoc.skip>true</maven.javadoc.skip> <!-- Javadoc plugin fails because of no source code in module --> + </properties> + <dependencies> + <!-- provided --> + <dependency> + <groupId>com.yahoo.vespa</groupId> + <artifactId>annotations</artifactId> + <version>${project.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <!-- Not directly used in this module, but needed to get Import-Packages for JDK packages it exports. --> + <groupId>com.yahoo.vespa</groupId> + <artifactId>jdisc_core</artifactId> + <version>${project.version}</version> + <scope>provided</scope> + </dependency> + <!-- compile --> + <dependency> + <groupId>com.microsoft.onnxruntime</groupId> + <artifactId>onnxruntime</artifactId> + <scope>compile</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>com.yahoo.vespa</groupId> + <artifactId>bundle-plugin</artifactId> + <extensions>true</extensions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-shade-plugin</artifactId> + <executions> + <execution> + <phase>package</phase> + <goals> + <goal>shade</goal> + </goals> + <configuration> + <minimizeJar>false</minimizeJar> + <filters> + <filter> + <artifact>com.microsoft.onnxruntime:*</artifact> + <excludes> + <exclude>ai/onnxruntime/native/**</exclude> + <exclude>META-INF/**</exclude> + </excludes> + </filter> + </filters> + <transformers> + <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> + <manifestEntries> + <Bundle-Activator>ai.vespa.onnxruntime.OnnxBundleActivator</Bundle-Activator> + </manifestEntries> + </transformer> + </transformers> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> diff --git a/container-onnxruntime/src/main/java/ai/onnxruntime/package-info.java b/container-onnxruntime/src/main/java/ai/onnxruntime/package-info.java new file mode 100644 index 00000000000..8b4b7369115 --- /dev/null +++ b/container-onnxruntime/src/main/java/ai/onnxruntime/package-info.java @@ -0,0 +1,8 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +/** + * @author arnej + */ +@ExportPackage +package ai.onnxruntime; + +import com.yahoo.osgi.annotation.ExportPackage; diff --git a/container-onnxruntime/src/main/java/ai/onnxruntime/providers/package-info.java b/container-onnxruntime/src/main/java/ai/onnxruntime/providers/package-info.java new file mode 100644 index 00000000000..af09aa01661 --- /dev/null +++ b/container-onnxruntime/src/main/java/ai/onnxruntime/providers/package-info.java @@ -0,0 +1,8 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +/** + * @author arnej + */ +@ExportPackage +package ai.onnxruntime.providers; + +import com.yahoo.osgi.annotation.ExportPackage; diff --git a/container-onnxruntime/src/main/java/ai/vespa/onnxruntime/OnnxBundleActivator.java b/container-onnxruntime/src/main/java/ai/vespa/onnxruntime/OnnxBundleActivator.java new file mode 100644 index 00000000000..f43f00990ad --- /dev/null +++ b/container-onnxruntime/src/main/java/ai/vespa/onnxruntime/OnnxBundleActivator.java @@ -0,0 +1,53 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +package ai.vespa.onnxruntime; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +import java.util.logging.Logger; + +/** + * @author arnej + * Loads native libraries when the bundle is activated. + * Use system properties to ensure onnxruntime won't try + * to load them itself. + **/ +public class OnnxBundleActivator implements BundleActivator { + + private static final String SKIP_PREFIX = "onnxruntime.native."; + private static final String SKIP_SUFFIX = ".skip"; + private static final String SKIP_VALUE = "true"; + private static final String[] LIBRARY_NAMES = { "onnxruntime", "onnxruntime4j_jni" }; + private static final Logger log = Logger.getLogger(OnnxBundleActivator.class.getName()); + + @Override + public void start(BundleContext ctx) { + for (String libName : LIBRARY_NAMES) { + String skipProp = SKIP_PREFIX + libName + SKIP_SUFFIX; + if (SKIP_VALUE.equals(System.getProperty(skipProp))) { + log.info("already loaded native library "+libName+", skipping"); + } else { + System.setProperty(skipProp, SKIP_VALUE); + log.info("loading native library: "+libName); + try { + System.loadLibrary(libName); + log.fine("loaded native library OK: "+libName); + } catch (Exception e) { + log.warning("Could not load native library '"+libName+"' because: "+e.getMessage()); + } + } + } + } + + @Override + public void stop(BundleContext ctx) { + // not sure how to test that loading and unloading multiple times actually works, + // but this should in theory do the necessary thing. + for (String libName : LIBRARY_NAMES) { + String skipProp = SKIP_PREFIX + libName + SKIP_SUFFIX; + System.clearProperty(skipProp); + log.info("will unload native library: "+libName); + } + } +} diff --git a/container-onnxruntime/src/main/javadoc/README b/container-onnxruntime/src/main/javadoc/README new file mode 100644 index 00000000000..97109fa2cc5 --- /dev/null +++ b/container-onnxruntime/src/main/javadoc/README @@ -0,0 +1 @@ +No javadoc available for module diff --git a/dist/vespa.spec b/dist/vespa.spec index 37e333932e8..895356e7425 100644 --- a/dist/vespa.spec +++ b/dist/vespa.spec @@ -777,6 +777,7 @@ fi %{_prefix}/lib/jars/config-provisioning-jar-with-dependencies.jar %{_prefix}/lib/jars/container-apache-http-client-bundle-jar-with-dependencies.jar %{_prefix}/lib/jars/container-disc-jar-with-dependencies.jar +%{_prefix}/lib/jars/container-onnxruntime.jar %{_prefix}/lib/jars/container-search-and-docproc-jar-with-dependencies.jar %{_prefix}/lib/jars/container-spifly.jar %{_prefix}/lib/jars/docprocs-jar-with-dependencies.jar diff --git a/fat-model-dependencies/pom.xml b/fat-model-dependencies/pom.xml index f69cbc55617..4c7b213adc8 100644 --- a/fat-model-dependencies/pom.xml +++ b/fat-model-dependencies/pom.xml @@ -73,13 +73,6 @@ <groupId>com.yahoo.vespa</groupId> <artifactId>model-integration</artifactId> <version>${project.version}</version> - <exclusions> - <exclusion> - <!-- OPTIMIZATION: very large (60 MB) and not needed for config generation --> - <groupId>com.microsoft.onnxruntime</groupId> - <artifactId>onnxruntime</artifactId> - </exclusion> - </exclusions> </dependency> <dependency> <groupId>com.yahoo.vespa</groupId> diff --git a/model-evaluation/pom.xml b/model-evaluation/pom.xml index c0600872666..7c2ee046556 100644 --- a/model-evaluation/pom.xml +++ b/model-evaluation/pom.xml @@ -74,6 +74,12 @@ <scope>provided</scope> </dependency> <dependency> + <groupId>com.yahoo.vespa</groupId> + <artifactId>container-onnxruntime</artifactId> + <version>${project.version}</version> + <scope>provided</scope> + </dependency> + <dependency> <groupId>org.lz4</groupId> <artifactId>lz4-java</artifactId> </dependency> diff --git a/model-integration/pom.xml b/model-integration/pom.xml index 63232b61106..43f24301d9a 100644 --- a/model-integration/pom.xml +++ b/model-integration/pom.xml @@ -51,11 +51,13 @@ <version>${project.version}</version> <scope>provided</scope> </dependency> - <dependency> - <groupId>com.microsoft.onnxruntime</groupId> - <artifactId>onnxruntime</artifactId> + <groupId>com.yahoo.vespa</groupId> + <artifactId>container-onnxruntime</artifactId> + <version>${project.version}</version> + <scope>provided</scope> </dependency> + <dependency> <groupId>com.google.protobuf</groupId> <artifactId>protobuf-java</artifactId> @@ -58,6 +58,7 @@ <module>container-disc</module> <module>container-documentapi</module> <module>container-messagebus</module> + <module>container-onnxruntime</module> <module>container-search-and-docproc</module> <module>container-search</module> <module>container-spifly</module> diff --git a/standalone-container/pom.xml b/standalone-container/pom.xml index 590872282ca..805a318e6ed 100644 --- a/standalone-container/pom.xml +++ b/standalone-container/pom.xml @@ -112,6 +112,7 @@ linguistics-components-jar-with-dependencies.jar, model-evaluation-jar-with-dependencies.jar, model-integration-jar-with-dependencies.jar, + container-onnxruntime.jar, <!-- END config-model dependencies --> </discPreInstallBundle> </configuration> |