diff --git a/api/build.gradle.kts b/api/build.gradle.kts index 8fa167e186a..3c2cdc758e1 100644 --- a/api/build.gradle.kts +++ b/api/build.gradle.kts @@ -23,9 +23,9 @@ tasks { compileJava { dependsOn(processResources) } processResources { - inputs.properties(mapOf("projectVersion" to project.version)) + inputs.properties(mapOf("version" to version)) filesMatching("**/api.properties") { - expand(mapOf("projectVersion" to project.version)) + expand(mapOf("version" to version)) } } diff --git a/api/src/main/resources/ai/djl/engine/api.properties b/api/src/main/resources/ai/djl/engine/api.properties index 0508cf08a2b..7006b178367 100644 --- a/api/src/main/resources/ai/djl/engine/api.properties +++ b/api/src/main/resources/ai/djl/engine/api.properties @@ -1 +1 @@ -djl_version=${projectVersion} \ No newline at end of file +djl_version=${version} \ No newline at end of file diff --git a/engines/llama/build.gradle.kts b/engines/llama/build.gradle.kts index d19ac5d2741..68ada8e8dd6 100644 --- a/engines/llama/build.gradle.kts +++ b/engines/llama/build.gradle.kts @@ -17,7 +17,7 @@ tasks { compileJava { dependsOn(processResources) } processResources { - var path = "${project.projectDir}/build/resources/main" + val path = "${project.projectDir}/build/resources/main" inputs.properties(mapOf("djl_version" to libs.versions.djl.get(), "llamacpp_version" to libs.versions.llamacpp.get())) outputs.dir("$path/native/lib") doLast { diff --git a/engines/ml/xgboost/build.gradle.kts b/engines/ml/xgboost/build.gradle.kts index 824bd2ea987..4a6e6cfa225 100644 --- a/engines/ml/xgboost/build.gradle.kts +++ b/engines/ml/xgboost/build.gradle.kts @@ -11,6 +11,7 @@ val xgbFlavor = if (isGpu) "-gpu" else "" val exclusion by configurations.registering +@Suppress("UnstableApiUsage") dependencies { api(project(":api")) api(libs.commons.logging) diff --git a/engines/mxnet/mxnet-engine/src/main/resources/mx-engine.properties b/engines/mxnet/mxnet-engine/src/main/resources/mxnet-engine.properties similarity index 100% rename from engines/mxnet/mxnet-engine/src/main/resources/mx-engine.properties rename to engines/mxnet/mxnet-engine/src/main/resources/mxnet-engine.properties diff --git a/engines/tensorflow/tensorflow-api/build.gradle.kts b/engines/tensorflow/tensorflow-api/build.gradle.kts index 9fa98d5f2cf..d17e65c3794 100644 --- a/engines/tensorflow/tensorflow-api/build.gradle.kts +++ b/engines/tensorflow/tensorflow-api/build.gradle.kts @@ -9,6 +9,7 @@ group = "ai.djl.tensorflow" val exclusion by configurations.registering +@Suppress("UnstableApiUsage") dependencies { api(libs.bytedeco.javacpp) api(libs.google.protobuf) diff --git a/engines/tensorflow/tensorflow-engine/build.gradle.kts b/engines/tensorflow/tensorflow-engine/build.gradle.kts index ea3009c1fe1..8f4c521b89a 100644 --- a/engines/tensorflow/tensorflow-engine/build.gradle.kts +++ b/engines/tensorflow/tensorflow-engine/build.gradle.kts @@ -14,9 +14,9 @@ dependencies { } tasks.processResources { - inputs.properties(mapOf("djlVersion" to libs.versions.djl, "tensorflowVersion" to libs.versions.tensorflow)) - filesMatching("**/mxnet-engine.properties") { - expand(mapOf("djl_version" to libs.versions.djl, "tensorflow_version" to libs.versions.tensorflow)) + inputs.properties(mapOf("djlVersion" to libs.versions.djl.get(), "tensorflowVersion" to libs.versions.tensorflow.get())) + filesMatching("**/tensorflow-engine.properties") { + expand(mapOf("djlVersion" to libs.versions.djl.get(), "tensorflowVersion" to libs.versions.tensorflow.get())) } } diff --git a/engines/tensorflow/tensorflow-engine/src/main/resources/tensorflow-engine.properties b/engines/tensorflow/tensorflow-engine/src/main/resources/tensorflow-engine.properties index f3ddbf23461..6e470b04b50 100644 --- a/engines/tensorflow/tensorflow-engine/src/main/resources/tensorflow-engine.properties +++ b/engines/tensorflow/tensorflow-engine/src/main/resources/tensorflow-engine.properties @@ -1,2 +1,2 @@ -djl_version=${projectVersion} +djl_version=${djlVersion} tensorflow_version=${tensorflowVersion} \ No newline at end of file diff --git a/engines/tensorrt/build.gradle.kts b/engines/tensorrt/build.gradle.kts index 4a63913ca15..b10a246e957 100644 --- a/engines/tensorrt/build.gradle.kts +++ b/engines/tensorrt/build.gradle.kts @@ -46,10 +46,10 @@ tasks { from(jnilibDir) into("$baseResourcePath/native/lib") } + } - filesMatching("**/tensorrt.properties") { - expand(mapOf("trtVersion" to libs.versions.tensorrt.get(), "version" to version)) - } + filesMatching("**/tensorrt.properties") { + expand(mapOf("trtVersion" to libs.versions.tensorrt.get(), "version" to version)) } } diff --git a/extensions/fasttext/build.gradle.kts b/extensions/fasttext/build.gradle.kts index 4bf844093f3..c17b83d7145 100644 --- a/extensions/fasttext/build.gradle.kts +++ b/extensions/fasttext/build.gradle.kts @@ -47,11 +47,10 @@ tasks { from(jnilibDir) into("$baseResourcePath/native/lib") } + } - // write properties - filesMatching("**/fasttext.properties") { - expand(mapOf("fasttextVersion" to libs.versions.fasttext.get(), "version" to version)) - } + filesMatching("**/fasttext.properties") { + expand(mapOf("fasttextVersion" to libs.versions.fasttext.get(), "version" to version)) } } diff --git a/extensions/sentencepiece/build.gradle.kts b/extensions/sentencepiece/build.gradle.kts index 71d01b0a256..c634ba15494 100644 --- a/extensions/sentencepiece/build.gradle.kts +++ b/extensions/sentencepiece/build.gradle.kts @@ -46,10 +46,10 @@ tasks { from(jnilibDir) into("$baseResourcePath/native/lib") } + } - filesMatching("**/sentencepiece.properties") { - expand(mapOf("sentencepieceVersion" to libs.versions.sentencepiece.get(), "version" to version)) - } + filesMatching("**/sentencepiece.properties") { + expand(mapOf("sentencepieceVersion" to libs.versions.sentencepiece.get(), "version" to version)) } } diff --git a/extensions/sentencepiece/src/main/java/ai/djl/sentencepiece/SpProcessor.java b/extensions/sentencepiece/src/main/java/ai/djl/sentencepiece/SpProcessor.java index c7af964e9a5..d2a627255e4 100644 --- a/extensions/sentencepiece/src/main/java/ai/djl/sentencepiece/SpProcessor.java +++ b/extensions/sentencepiece/src/main/java/ai/djl/sentencepiece/SpProcessor.java @@ -16,6 +16,7 @@ import ai.djl.sentencepiece.jni.SentencePieceLibrary; import ai.djl.util.Ec2Utils; import ai.djl.util.NativeResource; +import ai.djl.util.Platform; /** The processor holder for SentencePiece. */ public final class SpProcessor extends NativeResource { @@ -42,6 +43,16 @@ static SpProcessor newInstance() { return new SpProcessor(); } + /** + * Returns the version of the sentencepiece. + * + * @return the version number of the sentencepiece + */ + public String getVersion() { + Platform platform = Platform.detectPlatform("sentencepiece"); + return platform.getVersion(); + } + void loadModel(String path) { SentencePieceLibrary.LIB.loadModel(getHandle(), path); } diff --git a/extensions/sentencepiece/src/test/java/ai/djl/sentencepiece/SpTokenizerTest.java b/extensions/sentencepiece/src/test/java/ai/djl/sentencepiece/SpTokenizerTest.java index 92a1b0ab1ea..1d18e0a8a83 100644 --- a/extensions/sentencepiece/src/test/java/ai/djl/sentencepiece/SpTokenizerTest.java +++ b/extensions/sentencepiece/src/test/java/ai/djl/sentencepiece/SpTokenizerTest.java @@ -13,6 +13,7 @@ package ai.djl.sentencepiece; +import ai.djl.engine.Engine; import ai.djl.testing.TestRequirements; import ai.djl.training.util.DownloadUtils; @@ -45,6 +46,8 @@ public void testLoadFromBytes() throws IOException { Path modelPath = Paths.get("build/test/sp_model/sp_model.model"); byte[] bytes = Files.readAllBytes(modelPath); try (SpTokenizer tokenizer = new SpTokenizer(bytes)) { + String djlVersion = Engine.getDjlVersion(); + Assert.assertEquals(tokenizer.getProcessor().getVersion(), "0.2.0-" + djlVersion); String original = "Hello World"; List tokens = tokenizer.tokenize(original); List expected = Arrays.asList("▁He", "ll", "o", "▁", "W", "or", "l", "d"); diff --git a/extensions/tokenizers/build.gradle.kts b/extensions/tokenizers/build.gradle.kts index e63314f6350..7510aa48022 100644 --- a/extensions/tokenizers/build.gradle.kts +++ b/extensions/tokenizers/build.gradle.kts @@ -56,9 +56,6 @@ tasks { into("$baseResourcePath/native/lib") } - filesMatching("**/tokenizers.properties") { - expand(mapOf("tokenizersVersion" to tokenizers, "version" to version)) - } url = "https://mlrepo.djl.ai/model/nlp" val tasks = listOf( "fill_mask", @@ -93,6 +90,10 @@ tasks { } } } + + filesMatching("**/tokenizers.properties") { + expand(mapOf("tokenizersVersion" to libs.versions.tokenizers.get(), "version" to version)) + } } register("compileJNI") { diff --git a/extensions/tokenizers/src/main/java/ai/djl/huggingface/tokenizers/HuggingFaceTokenizer.java b/extensions/tokenizers/src/main/java/ai/djl/huggingface/tokenizers/HuggingFaceTokenizer.java index 177366faff2..b04b528d4a3 100644 --- a/extensions/tokenizers/src/main/java/ai/djl/huggingface/tokenizers/HuggingFaceTokenizer.java +++ b/extensions/tokenizers/src/main/java/ai/djl/huggingface/tokenizers/HuggingFaceTokenizer.java @@ -21,6 +21,7 @@ import ai.djl.util.Ec2Utils; import ai.djl.util.NativeResource; import ai.djl.util.PairList; +import ai.djl.util.Platform; import ai.djl.util.Utils; import org.slf4j.Logger; @@ -188,6 +189,16 @@ public static HuggingFaceTokenizer newInstance(InputStream is, Map tokenize(String sentence) { diff --git a/extensions/tokenizers/src/test/java/ai/djl/engine/rust/RsEngineTest.java b/extensions/tokenizers/src/test/java/ai/djl/engine/rust/RsEngineTest.java new file mode 100644 index 00000000000..aea38767c78 --- /dev/null +++ b/extensions/tokenizers/src/test/java/ai/djl/engine/rust/RsEngineTest.java @@ -0,0 +1,27 @@ +/* + * Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance + * with the License. A copy of the License is located at + * + * http://aws.amazon.com/apache2.0/ + * + * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES + * OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ +package ai.djl.engine.rust; + +import ai.djl.engine.Engine; + +import org.testng.Assert; +import org.testng.annotations.Test; + +public class RsEngineTest { + + @Test + public void testVersion() { + Engine engine = Engine.getEngine("Rust"); + Assert.assertEquals(engine.getVersion(), Engine.getDjlVersion()); + } +} diff --git a/extensions/tokenizers/src/test/java/ai/djl/huggingface/tokenizers/HuggingFaceTokenizerTest.java b/extensions/tokenizers/src/test/java/ai/djl/huggingface/tokenizers/HuggingFaceTokenizerTest.java index ead688539e2..713e1fbeb88 100644 --- a/extensions/tokenizers/src/test/java/ai/djl/huggingface/tokenizers/HuggingFaceTokenizerTest.java +++ b/extensions/tokenizers/src/test/java/ai/djl/huggingface/tokenizers/HuggingFaceTokenizerTest.java @@ -13,6 +13,7 @@ package ai.djl.huggingface.tokenizers; +import ai.djl.engine.Engine; import ai.djl.huggingface.tokenizers.jni.CharSpan; import ai.djl.testing.TestRequirements; import ai.djl.training.util.DownloadUtils; @@ -33,6 +34,14 @@ public class HuggingFaceTokenizerTest { + @Test + public void testVersion() { + try (HuggingFaceTokenizer tokenizer = HuggingFaceTokenizer.newInstance("bert-base-cased")) { + String djlVersion = Engine.getDjlVersion(); + Assert.assertEquals(tokenizer.getVersion(), "0.19.1-" + djlVersion); + } + } + @Test public void testTokenizer() throws IOException { String input = "Hello, y'all! How are you 😁 ?";