Skip to content

Commit

Permalink
Fixes build script for properties generation
Browse files Browse the repository at this point in the history
  • Loading branch information
frankfliu committed Jun 2, 2024
1 parent caedea6 commit a6e181b
Show file tree
Hide file tree
Showing 17 changed files with 84 additions and 21 deletions.
4 changes: 2 additions & 2 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
2 changes: 1 addition & 1 deletion api/src/main/resources/ai/djl/engine/api.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
djl_version=${projectVersion}
djl_version=${version}
2 changes: 1 addition & 1 deletion engines/llama/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions engines/ml/xgboost/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions engines/tensorflow/tensorflow-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ group = "ai.djl.tensorflow"

val exclusion by configurations.registering

@Suppress("UnstableApiUsage")
dependencies {
api(libs.bytedeco.javacpp)
api(libs.google.protobuf)
Expand Down
6 changes: 3 additions & 3 deletions engines/tensorflow/tensorflow-engine/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
djl_version=${projectVersion}
djl_version=${djlVersion}
tensorflow_version=${tensorflowVersion}
6 changes: 3 additions & 3 deletions engines/tensorrt/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
7 changes: 3 additions & 4 deletions extensions/fasttext/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
6 changes: 3 additions & 3 deletions extensions/sentencepiece/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Long> {
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package ai.djl.sentencepiece;

import ai.djl.engine.Engine;
import ai.djl.testing.TestRequirements;
import ai.djl.training.util.DownloadUtils;

Expand Down Expand Up @@ -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<String> tokens = tokenizer.tokenize(original);
List<String> expected = Arrays.asList("▁He", "ll", "o", "▁", "W", "or", "l", "d");
Expand Down
7 changes: 4 additions & 3 deletions extensions/tokenizers/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -93,6 +90,10 @@ tasks {
}
}
}

filesMatching("**/tokenizers.properties") {
expand(mapOf("tokenizersVersion" to libs.versions.tokenizers.get(), "version" to version))
}
}

register("compileJNI") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -188,6 +189,16 @@ public static HuggingFaceTokenizer newInstance(InputStream is, Map<String, Strin
return new HuggingFaceTokenizer(handle, options);
}

/**
* Returns the version of the Huggingface tokenizer.
*
* @return the version number of the Huggingface tokenizer
*/
public String getVersion() {
Platform platform = Platform.detectPlatform("tokenizers");
return platform.getVersion();
}

/** {@inheritDoc} */
@Override
public List<String> tokenize(String sentence) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 😁 ?";
Expand Down

0 comments on commit a6e181b

Please sign in to comment.