summaryrefslogtreecommitdiffstats
path: root/container-llama
diff options
context:
space:
mode:
authorArne Juul <arnej@vespa.ai>2024-03-21 13:28:56 +0000
committerArne Juul <arnej@yahooinc.com>2024-04-02 15:56:18 +0200
commitf83cc4e37fea07eb758f8c4a734326800a2d0f6a (patch)
treed039b35da74d21184978d0c1242888dfbf387097 /container-llama
parent1faf824436a0e071415d689593949569b52eca58 (diff)
add container-llama bundle
Diffstat (limited to 'container-llama')
-rw-r--r--container-llama/CMakeLists.txt2
-rw-r--r--container-llama/README.md4
-rw-r--r--container-llama/pom.xml92
-rw-r--r--container-llama/src/main/java/ai/vespa/llama/LlamaBundleActivator.java51
4 files changed, 149 insertions, 0 deletions
diff --git a/container-llama/CMakeLists.txt b/container-llama/CMakeLists.txt
new file mode 100644
index 00000000000..ba41a4ef835
--- /dev/null
+++ b/container-llama/CMakeLists.txt
@@ -0,0 +1,2 @@
+# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+install_jar(container-llama.jar)
diff --git a/container-llama/README.md b/container-llama/README.md
new file mode 100644
index 00000000000..3f172726124
--- /dev/null
+++ b/container-llama/README.md
@@ -0,0 +1,4 @@
+<!-- Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -->
+# container-llama
+
+llama repackaged as a bundle
diff --git a/container-llama/pom.xml b/container-llama/pom.xml
new file mode 100644
index 00000000000..38b9f96d653
--- /dev/null
+++ b/container-llama/pom.xml
@@ -0,0 +1,92 @@
+<?xml version="1.0"?>
+<!-- Copyright Vespa.ai. 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-llama</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>de.kherud</groupId>
+ <artifactId>llama</artifactId>
+ <version>2.3.5</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>com.yahoo.vespa</groupId>
+ <artifactId>bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <bundleType>CORE</bundleType>
+ </configuration>
+ </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>
+ <createDependencyReducedPom>false</createDependencyReducedPom>
+ <filters>
+ <filter>
+ <artifact>de.kherud:*</artifact>
+ <excludes>
+ <exclude>de/kherud/llama/Linux-Android//**</exclude>
+ <exclude>de/kherud/llama/Linux/**</exclude>
+ <exclude>de/kherud/llama/Mac/**</exclude>
+ <exclude>de/kherud/llama/Windows/**</exclude>
+ </excludes>
+ </filter>
+ </filters>
+ <transformers>
+ <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
+ <manifestEntries>
+ <Bundle-Activator>ai.vespa.llama.LlamaBundleActivator</Bundle-Activator>
+ </manifestEntries>
+ </transformer>
+ </transformers>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/container-llama/src/main/java/ai/vespa/llama/LlamaBundleActivator.java b/container-llama/src/main/java/ai/vespa/llama/LlamaBundleActivator.java
new file mode 100644
index 00000000000..11ba05e363d
--- /dev/null
+++ b/container-llama/src/main/java/ai/vespa/llama/LlamaBundleActivator.java
@@ -0,0 +1,51 @@
+// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+package ai.vespa.llama;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+import java.util.logging.Logger;
+
+/**
+ * @author arnej
+ * Finds native libraries when the bundle is activated.
+ **/
+public class LlamaBundleActivator implements BundleActivator {
+
+ private static final String PATH_PROPNAME = "de.kherud.llama.lib.path";
+ private static final Logger log = Logger.getLogger(LlamaBundleActivator.class.getName());
+
+ @Override
+ public void start(BundleContext ctx) {
+ log.fine("start bundle");
+ if (checkFilenames(
+ "/dev/nvidia0",
+ "/opt/vespa-deps/lib64/cuda/libllama.so",
+ "/opt/vespa-deps/lib64/cuda/libjllama.so")) {
+ System.setProperty(PATH_PROPNAME, "/opt/vespa-deps/lib64/cuda");
+ } else if (checkFilenames(
+ "/opt/vespa-deps/lib64/libllama.so",
+ "/opt/vespa-deps/lib64/libjllama.so")) {
+ System.setProperty(PATH_PROPNAME, "/opt/vespa-deps/lib64");
+ } else {
+ throw new IllegalArgumentException("Cannot find shared libraries");
+ }
+ }
+
+ @Override
+ public void stop(BundleContext ctx) {
+ log.fine("stop bundle");
+ }
+
+ private boolean checkFilenames(String... filenames) {
+ for (String fn : filenames) {
+ var f = new java.io.File(fn);
+ if (! f.canRead()) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+}