Repository: deepjavalibrary/djl
Pull request #1694 (2022-06-05 00:06:20)

[xgb] Avoid download cudf dependency at build time
Change-Id: I35a5b5cf91cda9095369f35b7b609a78070b50b3

## Description ##

Brief description of what this PR is about

- If this change is a backward incompatible change, why must this change be made?
- Interesting edge cases to note here



Patch:
diff --git a/android/build.gradle b/android/build.gradle
index 88d1750bb..d469c4627 100644
--- a/android/build.gradle
+++ b/android/build.gradle
@@ -18,6 +18,10 @@ allprojects {
     repositories {
         google()
         mavenCentral()
+        mavenLocal()
+        maven {
+            url "https://oss.sonatype.org/content/repositories/snapshots/"
+        }
     }
 }
 
diff --git a/android/core/build.gradle b/android/core/build.gradle
index acf6c1021..4ab1e3783 100644
--- a/android/core/build.gradle
+++ b/android/core/build.gradle
@@ -27,12 +27,6 @@ android {
     }
 }
 
-repositories {
-    maven {
-        url "https://oss.sonatype.org/content/repositories/snapshots/"
-    }
-}
-
 signing {
     required(project.hasProperty("staging") || project.hasProperty("snapshot"))
     def signingKey = findProperty("signingKey")
diff --git a/android/core/src/main/java/ai/djl/android/core/BitmapImageFactory.java b/android/core/src/main/java/ai/djl/android/core/BitmapImageFactory.java
index 191fcfcd2..f670a4590 100644
--- a/android/core/src/main/java/ai/djl/android/core/BitmapImageFactory.java
+++ b/android/core/src/main/java/ai/djl/android/core/BitmapImageFactory.java
@@ -189,6 +189,13 @@ public class BitmapImageFactory extends ImageFactory {
             }
         }
 
+        /** {@inheritDoc} */
+        @Override
+        public List<BoundingBox> findBoundingBoxes() {
+            // TODO: Add grayscale conversion and use BoundFinder to implement
+            throw new UnsupportedOperationException("Not supported for BitMapImage");
+        }
+
         /** {@inheritDoc} */
         @Override
         public void drawBoundingBoxes(DetectedObjects detections) {
diff --git a/android/gradle.properties b/android/gradle.properties
index 591dba5ba..34e83a5c0 100644
--- a/android/gradle.properties
+++ b/android/gradle.properties
@@ -17,5 +17,5 @@ org.gradle.jvmargs=-Xmx1536m
 android.useAndroidX=true
 # Automatically convert third-party libraries to use AndroidX
 android.enableJetifier=true
-djl_version=0.17.0
+djl_version=0.18.0
 pytorch_version=1.11.0
diff --git a/android/pytorch-native/gradlew b/android/pytorch-native/gradlew
new file mode 120000
index 000000000..502f5a2d3
--- /dev/null
+++ b/android/pytorch-native/gradlew
@@ -0,0 +1,1 @@
+../gradlew
\ No newline at end of file
diff --git a/api/build.gradle b/api/build.gradle
index 94c2c2e7e..5f16a668e 100644
--- a/api/build.gradle
+++ b/api/build.gradle
@@ -8,7 +8,7 @@ dependencies {
         exclude group: "junit", module: "junit"
     }
     testImplementation "org.slf4j:slf4j-simple:${slf4j_version}"
-    testRuntimeOnly project(":engines:mxnet:mxnet-model-zoo")
+    testRuntimeOnly project(":engines:pytorch:pytorch-model-zoo")
 }
 
 javadoc {
diff --git a/basicdataset/build.gradle b/basicdataset/build.gradle
index 132999c50..eac450c4d 100644
--- a/basicdataset/build.gradle
+++ b/basicdataset/build.gradle
@@ -10,7 +10,7 @@ dependencies {
     testImplementation "org.slf4j:slf4j-simple:${slf4j_version}"
 
     testImplementation project(":testing")
-    testImplementation project(":engines:mxnet:mxnet-engine")
+    testImplementation project(":engines:pytorch:pytorch-engine")
 }
 
 task syncS3(type: Exec) {
diff --git a/engines/ml/xgboost/build.gradle b/engines/ml/xgboost/build.gradle
index 9d31691b7..d7b36ad03 100644
--- a/engines/ml/xgboost/build.gradle
+++ b/engines/ml/xgboost/build.gradle
@@ -1,5 +1,3 @@
-import groovy.xml.QName
-
 group "ai.djl.ml.xgboost"
 boolean isGpu = project.hasProperty("gpu")
 def XGB_FLAVOR = isGpu ? "-gpu" : ""
@@ -25,19 +23,18 @@ dependencies {
         exclude group: "org.scala-lang", module: "scala-reflect"
         exclude group: "org.scala-lang", module: "scala-library"
     }
-    if (isGpu) {
-        api "ai.rapids:cudf:${rapis_version}:cuda11"
-    }
 
     exclusion project(":api")
     exclusion "commons-logging:commons-logging:${commons_logging_version}"
-    exclusion "ai.rapids:cudf:${rapis_version}:cuda11"
     testImplementation(project(":testing"))
     testImplementation("org.testng:testng:${testng_version}") {
         exclude group: "junit", module: "junit"
     }
 
     testRuntimeOnly "org.slf4j:slf4j-simple:${slf4j_version}"
+    if (isGpu) {
+        testRuntimeOnly "ai.rapids:cudf:${rapis_version}:cuda11"
+    }
 }
 
 jar {
@@ -67,12 +64,20 @@ publishing {
                 url = "https://djl.ai/engines/ml/${project.name}"
 
                 withXml {
-                    Node pomNode = asNode()
+                    def pomNode = asNode()
                     pomNode.dependencies."*".findAll() {
                         it.artifactId.text().startsWith("xgboost")
                     }.each() {
                         it.parent().remove(it)
                     }
+                    if (isGpu) {
+                        def dep = pomNode.dependencies[0].appendNode("dependency")
+                        dep.appendNode("groupId", "ai.rapids")
+                        dep.appendNode("artifactId", "cudf")
+                        dep.appendNode("version", "${rapis_version}")
+                        dep.appendNode("classifier", "cuda11")
+                        dep.appendNode("scope", "compile")
+                    }
                 }
             }
         }
diff --git a/extensions/aws-ai/build.gradle b/extensions/aws-ai/build.gradle
index 360ede00f..e28f63b0a 100644
--- a/extensions/aws-ai/build.gradle
+++ b/extensions/aws-ai/build.gradle
@@ -9,7 +9,7 @@ dependencies {
     api "software.amazon.awssdk:sts"
     api project(":api")
 
-    testImplementation project(":engines:mxnet:mxnet-model-zoo")
+    testImplementation project(":engines:pytorch:pytorch-model-zoo")
 
     testImplementation("org.testng:testng:${testng_version}") {
         exclude group: "junit", module: "junit"


Test patch:
diff --git a/api/src/test/java/ai/djl/repository/DjlRepositoryTest.java b/api/src/test/java/ai/djl/repository/DjlRepositoryTest.java
index 83b8e9507..0f39630a7 100644
--- a/api/src/test/java/ai/djl/repository/DjlRepositoryTest.java
+++ b/api/src/test/java/ai/djl/repository/DjlRepositoryTest.java
@@ -26,16 +26,16 @@ public class DjlRepositoryTest {
 
     @Test
     public void testResource() throws ModelNotFoundException, MalformedModelException, IOException {
-        Repository repo = Repository.newInstance("DJL", "djl://ai.djl.mxnet/mlp");
+        Repository repo = Repository.newInstance("DJL", "djl://ai.djl.pytorch/resnet");
         Assert.assertEquals(repo.getResources().size(), 1);
 
-        repo = Repository.newInstance("DJL", "djl://ai.djl.mxnet/resnet/0.0.1");
+        repo = Repository.newInstance("DJL", "djl://ai.djl.pytorch/resnet/0.0.1");
         Assert.assertEquals(repo.getResources().size(), 1);
 
-        repo = Repository.newInstance("DJL", "djl://ai.djl.mxnet/resnet/0.0.1/resnet18_v1");
+        repo = Repository.newInstance("DJL", "djl://ai.djl.pytorch/resnet/0.0.1/traced_resnet18");
         Assert.assertEquals(repo.getResources().size(), 1);
 
-        repo = Repository.newInstance("DJL", "djl://ai.djl.mxnet/fake/0.0.1");
+        repo = Repository.newInstance("DJL", "djl://ai.djl.pytorch/fake/0.0.1");
         Assert.assertEquals(repo.getResources().size(), 0);
 
         repo = Repository.newInstance("DJL", "djl://ai.djl.fake/mlp/0.0.1");
@@ -46,19 +46,19 @@ public class DjlRepositoryTest {
 
         Assert.expectThrows(
                 IllegalArgumentException.class,
-                () -> Repository.newInstance("DJL", "djl://ai.djl.mxnet"));
+                () -> Repository.newInstance("DJL", "djl://ai.djl.pytorch"));
 
         Assert.expectThrows(
                 IllegalArgumentException.class,
-                () -> Repository.newInstance("DJL", "djl://ai.djl.mxnet/"));
+                () -> Repository.newInstance("DJL", "djl://ai.djl.pytorch/"));
 
         Criteria<Image, Classifications> criteria =
                 Criteria.builder()
                         .setTypes(Image.class, Classifications.class)
-                        .optModelUrls("djl://ai.djl.mxnet/resnet/0.0.1/resnet18_v1")
+                        .optModelUrls("djl://ai.djl.pytorch/resnet/0.0.1/traced_resnet18")
                         .build();
         try (ZooModel<Image, Classifications> model = criteria.loadModel()) {
-            Assert.assertEquals(model.getName(), "resnet18_v1");
+            Assert.assertEquals(model.getName(), "traced_resnet18");
         }
     }
 }
diff --git a/extensions/aws-ai/src/test/java/ai/djl/aws/s3/S3RepositoryTest.java b/extensions/aws-ai/src/test/java/ai/djl/aws/s3/S3RepositoryTest.java
index 96ab442f1..7afc9e17e 100644
--- a/extensions/aws-ai/src/test/java/ai/djl/aws/s3/S3RepositoryTest.java
+++ b/extensions/aws-ai/src/test/java/ai/djl/aws/s3/S3RepositoryTest.java
@@ -51,13 +51,12 @@ public class S3RepositoryTest {
         Criteria<NDList, NDList> criteria =
                 Criteria.builder()
                         .setTypes(NDList.class, NDList.class)
-                        .optModelUrls(
-                                "s3://djl-ai/mlrepo/model/cv/image_classification/ai/djl/mxnet/mlp/0.0.1")
-                        .optModelName("mlp")
+                        .optModelUrls("s3://djl-ai/resources/demo/pytorch/traced_resnet18")
+                        .optModelName("traced_resnet18")
                         .build();
 
         try (ZooModel<NDList, NDList> model = criteria.loadModel()) {
-            Assert.assertEquals(model.getName(), "mlp");
+            Assert.assertEquals(model.getName(), "traced_resnet18");
         }
     }
 
@@ -75,12 +74,12 @@ public class S3RepositoryTest {
         Criteria<NDList, NDList> criteria =
                 Criteria.builder()
                         .setTypes(NDList.class, NDList.class)
-                        .optModelUrls("s3://djl-ai/resources/test-models/mlp.tar.gz")
-                        .optModelName("mlp")
+                        .optModelUrls("s3://djl-ai/resources/demo/pytorch/traced_resnet18.zip")
+                        .optModelName("traced_resnet18")
                         .build();
 
         try (ZooModel<NDList, NDList> model = criteria.loadModel()) {
-            Assert.assertEquals(model.getName(), "mlp");
+            Assert.assertEquals(model.getName(), "traced_resnet18");
         }
     }