Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved incremental build #3231

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/continuous.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,9 @@ jobs:
run: ./gradlew :engines:pytorch:pytorch-native:compileJNI
- name: Test ONNX Runtime
run: |
./gradlew -Dai.djl.default_engine=OnnxRuntime :integration:test --stacktrace
./gradlew :integration:clean
./gradlew -Dai.djl.default_engine=OnnxRuntime :integration:clean :integration:test --stacktrace
- name: Build with Gradle
run: ./gradlew build :jacoco:testCodeCoverageReport --stacktrace
run: ./gradlew clean build :jacoco:testCodeCoverageReport --stacktrace
- name: Upload test results
uses: actions/upload-artifact@v3
if: always()
Expand Down
9 changes: 3 additions & 6 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@ tasks {
compileJava { dependsOn(processResources) }

processResources {
outputs.file(buildDirectory / "classes/java/main/ai/djl/engine/api.properties")
doFirst {
val classesDir = file("$buildDirectory/classes/java/main/ai/djl/engine/")
classesDir.mkdirs()
val propFile = File(classesDir, "api.properties")
propFile.text = "djl_version=${project.version}"
inputs.properties(mapOf("version" to version))
filesMatching("**/api.properties") {
expand(mapOf("version" to version))
}
}

Expand Down
1 change: 1 addition & 0 deletions api/src/main/resources/ai/djl/engine/api.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
djl_version=${version}
5 changes: 4 additions & 1 deletion buildSrc/src/main/kotlin/ai/djl/check.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ spotbugs {
excludeFilter = file("${rootProject.projectDir}/tools/conf/findbugs-exclude.xml")
ignoreFailures = false
}

tasks {
named<SpotBugsTask>("spotbugsMain") {
reports.create("html") {
Expand All @@ -26,7 +27,7 @@ tasks {
enabled = true
reports.create("html") {
required = true
outputLocation = file("$buildDirectory/reports/spotbugs.html")
outputLocation = file("$buildDirectory/reports/test/spotbugs.html")
}
}
}
Expand All @@ -37,6 +38,7 @@ pmd {
ruleSets = emptyList() // workaround pmd gradle plugin bug
ruleSetFiles = files("${rootProject.projectDir}/tools/conf/pmd.xml")
}

tasks.withType<Pmd> {
reports {
xml.required = true
Expand All @@ -54,6 +56,7 @@ checkstyle {
)
configFile = file("${rootProject.projectDir}/tools/conf/checkstyle.xml")
}

tasks {
named<Checkstyle>("checkstyleMain") {
classpath += configurations["compileClasspath"]
Expand Down
5 changes: 5 additions & 0 deletions buildSrc/src/main/kotlin/ai/djl/javaFormatter.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ tasks {
}

val verifyJava by registering {
val resultFilePath = "build/verifyJava-result.txt"
inputs.files(project.sourceSets.flatMap { it.allSource })
inputs.files(project.fileTree("generated-src"))
outputs.file(project.file(resultFilePath))
doLast {
val formatter = Main(PrintWriter(System.out, true), PrintWriter(System.err, true), System.`in`)
for (item in project.sourceSets)
Expand All @@ -35,6 +39,7 @@ tasks {
+ "See https://github.com/deepjavalibrary/djl/blob/master/docs/development/development_guideline.md#coding-conventions for more details"
)
}
project.file(resultFilePath).writeText("Success")
}
}

Expand Down
11 changes: 7 additions & 4 deletions buildSrc/src/main/kotlin/ai/djl/javaProject.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,18 @@ tasks {
}

jvmArgs("--add-opens", "java.base/jdk.internal.loader=ALL-UNNAMED")
systemProperties = System.getProperties().toMap() as Map<String, Any>
systemProperties.remove("user.dir")
// systemProperty "ai.djl.logging.level", "debug"
for (prop in System.getProperties().iterator()) {
val key = prop.key.toString()
if (key.startsWith("ai.djl.")) {
systemProperty(key, prop.value)
}
}
systemProperties(
"org.slf4j.simpleLogger.defaultLogLevel" to "debug",
"org.slf4j.simpleLogger.log.org.mortbay.log" to "warn",
"org.slf4j.simpleLogger.log.org.testng" to "info",
"disableProgressBar" to "true",
"nightly" to System.getProperty("nightly", "false")
"nightly" to System.getProperty("nightly", "false"),
)
if (gradle.startParameter.isOffline)
systemProperty("ai.djl.offline", "true")
Expand Down
10 changes: 6 additions & 4 deletions engines/llama/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ tasks {
compileJava { dependsOn(processResources) }

processResources {
outputs.dir(project.projectDir / "build/classes/java/main/native/lib")
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 {
val llamacpp = libs.versions.llamacpp.get()
val djl = libs.versions.djl.get()
Expand Down Expand Up @@ -49,15 +51,15 @@ tasks {
}
copy {
from(jnilibDir)
into(project.projectDir / "build/classes/java/main/native/lib")
into("$path/native/lib")
}

// write properties
val propFile = project.projectDir / "build/classes/java/main/native/lib/llama.properties"
val propFile = file("$path/native/lib/llama.properties")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which one is preferred in gradle: file() or File()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing as far as I know, just my personal preference 😄 File would be the constructor, and file() would be the option provided by the Gradle DSL

propFile.text = "version=$llamacpp-$version\n"

url = "https://mlrepo.djl.ai/model/nlp/text_generation/ai/djl/huggingface/gguf/models.json.gz"
val prefix = project.projectDir / "build/classes/java/main/nlp/text_generation"
val prefix = File("$path/nlp/text_generation")
val file = prefix / "ai.djl.huggingface.gguf.json"
if (file.exists())
project.logger.lifecycle("gguf index file already exists")
Expand Down
4 changes: 3 additions & 1 deletion 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 Expand Up @@ -42,7 +43,8 @@ tasks {
compileJava { dependsOn(processResources) }

processResources {
val jnilibDir = buildDirectory / "classes/java/main/lib/linux/aarch64/"
val jnilibDir = buildDirectory / "resources/java/main/lib/linux/aarch64/"
inputs.properties(mapOf("xgboostVersion" to libs.versions.xgboost.get()))
outputs.dir(jnilibDir)
doLast {
val url =
Expand Down
10 changes: 10 additions & 0 deletions engines/mxnet/jnarator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ tasks {
pmdMain { exclude("ai/djl/mxnet/jnarator/parser/*") }

jar {
dependsOn(generateGrammarSource)
manifest {
attributes(
"Main-Class" to "ai.djl.mxnet.jnarator.Main",
Expand All @@ -30,4 +31,13 @@ tasks {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
from(configurations.runtimeClasspath.get().map { if (it.isDirectory()) it else zipTree(it) })
}

generateGrammarSource {
dependsOn(verifyJava)
}

generateTestGrammarSource {
dependsOn(verifyJava)
}

}
13 changes: 8 additions & 5 deletions engines/mxnet/mxnet-engine/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ sourceSets.main {

tasks {
processResources {
doFirst {
val classesDir = buildDirectory / "classes/java/main/"
classesDir.mkdirs()
val file = classesDir / "mxnet-engine.properties"
file.text = "djl_version=${libs.versions.djl.get()}\nmxnet_version=" + libs.versions.mxnet.get()
inputs.properties(mapOf("djlVersion" to libs.versions.djl.get(), "mxnetVersion" to libs.versions.mxnet.get()))
filesMatching("**/mxnet-engine.properties") {
expand(mapOf("djlVersion" to libs.versions.djl.get(), "mxnetVersion" to libs.versions.mxnet.get()))
}
}

Expand All @@ -39,7 +37,11 @@ tasks {
val jnarator by registering {
val jnaratorJar = project(":engines:mxnet:jnarator").tasks.jar
dependsOn(jnaratorJar)
inputs.file("${project.projectDir}/src/main/jna/mapping.properties")
.withPathSensitivity(PathSensitivity.RELATIVE)
.withPropertyName("jna/mapping.properties file")
outputs.dir(buildDirectory / "generated-src")
outputs.cacheIf { true }
doLast {
val jnaGenerator = jnaratorJar.get().outputs.files.singleFile
javaexec {
Expand Down Expand Up @@ -106,6 +108,7 @@ tasks {
}
compileJava { dependsOn(jnarator) }
javadoc { dependsOn(jnarator) }
verifyJava { dependsOn(jnarator) }

publishing {
publications {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
djl_version=${djlVersion}
mxnet_version=${mxnetVersion}
6 changes: 3 additions & 3 deletions engines/onnxruntime/onnxruntime-engine/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ dependencies {

tasks {
processResources {
outputs.dir(projectDir / "build/classes/java/main/nlp")
var basePath = "${project.projectDir}/build/resources/main/nlp"
outputs.dir(basePath)
doLast {
val url = "https://mlrepo.djl.ai/model/nlp"
val tasks = listOf(
Expand All @@ -30,9 +31,8 @@ tasks {
"text_embedding",
"token_classification"
)
val prefix = projectDir / "build/classes/java/main/nlp"
for (task in tasks) {
val file = prefix / task / "ai.djl.huggingface.onnxruntime.json"
val file = File("$basePath/$task/ai.djl.huggingface.onnxruntime.json")
if (file.exists())
project.logger.lifecycle("model zoo metadata alrady exists: $task")
else {
Expand Down
9 changes: 3 additions & 6 deletions engines/pytorch/pytorch-engine/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@ tasks {
compileJava { dependsOn(processResources) }

processResources {
outputs.file(buildDirectory / "classes/java/main/pytorch-engine.properties")
doFirst {
val classesDir = buildDirectory / "classes/java/main/"
classesDir.mkdirs()
val propFile = classesDir / "pytorch-engine.properties"
propFile.text = "djl_version=${libs.versions.djl.get()}\npytorch_version=${libs.versions.pytorch.get()}"
inputs.properties(mapOf("djlVersion" to libs.versions.djl.get(), "pytorchVersion" to libs.versions.pytorch.get()))
filesMatching("**/pytorch-engine.properties") {
expand(mapOf("djlVersion" to libs.versions.djl.get(), "pytorchVersion" to libs.versions.pytorch.get()))
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
djl_version=${djlVersion}
pytorch_version=${pytorchVersion}
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
8 changes: 3 additions & 5 deletions engines/tensorflow/tensorflow-engine/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ dependencies {
}

tasks.processResources {
doFirst {
val classesDir = buildDirectory / "classes/java/main/"
classesDir.mkdirs()
val file = classesDir / "tensorflow-engine.properties"
file.text = "djl_version=${libs.versions.djl.get()}\ntensorflow_version=${libs.versions.tensorflow.get()}"
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
@@ -0,0 +1,2 @@
djl_version=${djlVersion}
tensorflow_version=${tensorflowVersion}
13 changes: 8 additions & 5 deletions engines/tensorrt/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ tasks {
compileJava { dependsOn(processResources) }

processResources {
outputs.dir(buildDirectory / "classes/java/main/native/lib")
inputs.properties(mapOf("djlVersion" to libs.versions.djl, "trtVersion" to libs.versions.tensorrt.get(),
"version" to version))
val baseResourcePath = "${project.projectDir}/build/resources/main"
outputs.dir(file("${baseResourcePath}/native/lib"))
doLast {
val trtVersion = libs.versions.tensorrt.get()
val djlVersion = libs.versions.djl.get()
Expand All @@ -41,12 +44,12 @@ tasks {

copy {
from(jnilibDir)
into(buildDirectory / "classes/java/main/native/lib")
into("$baseResourcePath/native/lib")
}
}

// write properties
val propFile = buildDirectory / "classes/java/main/native/lib/tensorrt.properties"
propFile.text = "version=${trtVersion}-${version}\n"
filesMatching("**/tensorrt.properties") {
expand(mapOf("trtVersion" to libs.versions.tensorrt.get(), "version" to version))
}
}

Expand Down
1 change: 1 addition & 0 deletions engines/tensorrt/src/main/resources/tensorrt.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version=${trtVersion}-${version}
28 changes: 16 additions & 12 deletions examples/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:Suppress("UNCHECKED_CAST")

plugins {
ai.djl.javaProject
application
Expand Down Expand Up @@ -32,22 +30,28 @@ tasks {

run.configure {
environment("TF_CPP_MIN_LOG_LEVEL" to "1") // turn off TensorFlow print out
// @Niels Doucet
// Just a heads-up: gradle support warned me about systemProperties System.getProperties(). It's really
// dangerous to just copy over all system properties to a task invocation. You should really be specific about
// the properties you'd like to expose inside the task, or you might get very strange issues.
systemProperties = System.getProperties().toMap() as Map<String, Any>
systemProperties.remove("user.dir")
systemProperty("file.encoding", "UTF-8")
for (prop in System.getProperties().iterator()) {
val key = prop.key.toString()
if (key.startsWith("ai.djl.")) {
systemProperty(key, prop.value)
}
}
}

register<JavaExec>("listmodels") {
systemProperties(System.getProperties() as Map<String, Any>)
systemProperties.remove("user.dir")
systemProperty("file.encoding", "UTF-8")
for (prop in System.getProperties().iterator()) {
val key = prop.key.toString()
if (key.startsWith("ai.djl.")) {
systemProperty(key, prop.value)
}
}
if (!systemProperties.containsKey("ai.djl.logging.level")) {
systemProperty("ai.djl.logging.level", "debug")
}
classpath = sourceSets.main.get().runtimeClasspath
mainClass = "ai.djl.examples.inference.ListModels"
}

distTar { enabled = false }
distZip { enabled = false }
}
14 changes: 9 additions & 5 deletions extensions/fasttext/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ tasks {
compileJava { dependsOn(processResources) }

processResources {
outputs.dir(buildDirectory / "classes/java/main/native/lib")
inputs.properties(mapOf("djlVersion" to libs.versions.djl.get(),
"fasttextVersion" to libs.versions.fasttext.get(),
"version" to version))
val baseResourcePath = "${project.projectDir}/build/resources/main"
outputs.dir("$baseResourcePath/native/lib")
doLast {
val url =
"https://publish.djl.ai/fasttext-${libs.versions.fasttext.get()}/jnilib/${libs.versions.djl.get()}"
Expand All @@ -41,12 +45,12 @@ tasks {
}
copy {
from(jnilibDir)
into(buildDirectory / "classes/java/main/native/lib")
into("$baseResourcePath/native/lib")
}
}

// write properties
val propFile = buildDirectory / "classes/java/main/native/lib/fasttext.properties"
propFile.text = "version=${libs.versions.fasttext.get()}-${version}\n"
filesMatching("**/fasttext.properties") {
expand(mapOf("fasttextVersion" to libs.versions.fasttext.get(), "version" to version))
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version=${fasttextVersion}-${version}
Loading
Loading