diff options
author | Arne Juul <arnej@yahooinc.com> | 2022-11-30 12:40:37 +0000 |
---|---|---|
committer | Arne Juul <arnej@yahooinc.com> | 2022-12-02 14:46:10 +0000 |
commit | d9ab932c59cf1d22f22c19b96619024a76aecc32 (patch) | |
tree | 7f1038060b308b26c3c583104ee5dd4f8547a9d8 | |
parent | 0f5a6d241394b7b064debdd38fabd58c7c64f94d (diff) |
add container-onnxruntime-bundle
19 files changed, 197 insertions, 12 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f7d7a0c0bb..2db91166c77 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-bundle) 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..93062c3c037 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-bundle:*: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/pom.xml b/config-model/pom.xml index a11e72fa1be..6da8ff5a868 100644 --- a/config-model/pom.xml +++ b/config-model/pom.xml @@ -165,6 +165,12 @@ </dependency> <dependency> <groupId>com.yahoo.vespa</groupId> + <artifactId>container-onnxruntime-bundle</artifactId> + <version>${project.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>com.yahoo.vespa</groupId> <artifactId>vdslib</artifactId> <version>${project.version}</version> <scope>provided</scope> 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..b581ba1fc45 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-bundle.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 007e8401c70..57eeedcaab7 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 @@ -707,6 +707,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..d016f05b6e2 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-bundle</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-bundle/CMakeLists.txt b/container-onnxruntime-bundle/CMakeLists.txt new file mode 100644 index 00000000000..f19909e8165 --- /dev/null +++ b/container-onnxruntime-bundle/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-bundle.jar) diff --git a/container-onnxruntime-bundle/README.md b/container-onnxruntime-bundle/README.md new file mode 100644 index 00000000000..182695f0023 --- /dev/null +++ b/container-onnxruntime-bundle/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-bundle + +onnxruntime.ai repackaged as a bundle diff --git a/container-onnxruntime-bundle/pom.xml b/container-onnxruntime-bundle/pom.xml new file mode 100644 index 00000000000..eca7aecf343 --- /dev/null +++ b/container-onnxruntime-bundle/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-bundle</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.onnxruntime.vespa.OnnxBundleActivator</Bundle-Activator> + </manifestEntries> + </transformer> + </transformers> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> diff --git a/container-onnxruntime-bundle/src/main/java/ai/onnxruntime/package-info.java b/container-onnxruntime-bundle/src/main/java/ai/onnxruntime/package-info.java new file mode 100644 index 00000000000..8b4b7369115 --- /dev/null +++ b/container-onnxruntime-bundle/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-bundle/src/main/java/ai/onnxruntime/providers/package-info.java b/container-onnxruntime-bundle/src/main/java/ai/onnxruntime/providers/package-info.java new file mode 100644 index 00000000000..af09aa01661 --- /dev/null +++ b/container-onnxruntime-bundle/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-bundle/src/main/java/ai/onnxruntime/vespa/OnnxBundleActivator.java b/container-onnxruntime-bundle/src/main/java/ai/onnxruntime/vespa/OnnxBundleActivator.java new file mode 100644 index 00000000000..e6a93c73d99 --- /dev/null +++ b/container-onnxruntime-bundle/src/main/java/ai/onnxruntime/vespa/OnnxBundleActivator.java @@ -0,0 +1,51 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package ai.onnxruntime.vespa; + +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-bundle/src/main/javadoc/README b/container-onnxruntime-bundle/src/main/javadoc/README new file mode 100644 index 00000000000..97109fa2cc5 --- /dev/null +++ b/container-onnxruntime-bundle/src/main/javadoc/README @@ -0,0 +1 @@ +No javadoc available for module diff --git a/dist/vespa.spec b/dist/vespa.spec index 333ec7b57fc..c58516a9ed8 100644 --- a/dist/vespa.spec +++ b/dist/vespa.spec @@ -778,6 +778,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-bundle.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..444595bd000 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-bundle</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..d2d547bce86 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-bundle</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-bundle</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..5dad287ab97 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-bundle.jar, <!-- END config-model dependencies --> </discPreInstallBundle> </configuration> |