From ac3984ab9dd95c0a5dba9f0ada27cd4d90460a1c Mon Sep 17 00:00:00 2001 From: Frank Liu Date: Tue, 5 Mar 2024 08:09:55 -0800 Subject: [PATCH] Avoid duplicated loading native library --- engines/llama/src/main/java/ai/djl/llama/jni/LibUtils.java | 3 ++- .../src/main/java/ai/djl/pytorch/jni/LibUtils.java | 3 ++- .../main/java/ai/djl/huggingface/tokenizers/jni/LibUtils.java | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/engines/llama/src/main/java/ai/djl/llama/jni/LibUtils.java b/engines/llama/src/main/java/ai/djl/llama/jni/LibUtils.java index 3792864c346..d51a4fe2e5e 100644 --- a/engines/llama/src/main/java/ai/djl/llama/jni/LibUtils.java +++ b/engines/llama/src/main/java/ai/djl/llama/jni/LibUtils.java @@ -55,8 +55,9 @@ public static void loadLibrary() { String nativeHelper = System.getProperty("ai.djl.llama.native_helper"); if (nativeHelper != null && !nativeHelper.isEmpty()) { ClassLoaderUtils.nativeLoad(nativeHelper, path); + } else { + System.load(path); // NOPMD } - System.load(path); // NOPMD } } diff --git a/engines/pytorch/pytorch-engine/src/main/java/ai/djl/pytorch/jni/LibUtils.java b/engines/pytorch/pytorch-engine/src/main/java/ai/djl/pytorch/jni/LibUtils.java index b208c79bb95..4d2e8505f02 100644 --- a/engines/pytorch/pytorch-engine/src/main/java/ai/djl/pytorch/jni/LibUtils.java +++ b/engines/pytorch/pytorch-engine/src/main/java/ai/djl/pytorch/jni/LibUtils.java @@ -361,8 +361,9 @@ private static void loadNativeLibrary(String path) { String nativeHelper = System.getProperty("ai.djl.pytorch.native_helper"); if (nativeHelper != null && !nativeHelper.isEmpty()) { ClassLoaderUtils.nativeLoad(nativeHelper, path); + } else { + System.load(path); // NOPMD } - System.load(path); // NOPMD } private static LibTorch downloadPyTorch(Platform platform) { diff --git a/extensions/tokenizers/src/main/java/ai/djl/huggingface/tokenizers/jni/LibUtils.java b/extensions/tokenizers/src/main/java/ai/djl/huggingface/tokenizers/jni/LibUtils.java index 7276b30ae9d..5bc71de4c0e 100644 --- a/extensions/tokenizers/src/main/java/ai/djl/huggingface/tokenizers/jni/LibUtils.java +++ b/extensions/tokenizers/src/main/java/ai/djl/huggingface/tokenizers/jni/LibUtils.java @@ -72,8 +72,9 @@ private static void loadLibrary() { String nativeHelper = System.getProperty("ai.djl.huggingface.native_helper"); if (nativeHelper != null && !nativeHelper.isEmpty()) { ClassLoaderUtils.nativeLoad(nativeHelper, path); + } else { + System.load(path); // NOPMD } - System.load(path); // NOPMD } }