Repository: deepjavalibrary/djl
Pull request #1911 (2022-08-16 02:40:28)

[bom] Adds xgboost-gpu to bom
Change-Id: I7ef58aab4a0e993c4d11b0a745bf9a69b3143468

## 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/api/src/main/java/ai/djl/engine/Engine.java b/api/src/main/java/ai/djl/engine/Engine.java
index ef636e5e2..e8408c1b6 100644
--- a/api/src/main/java/ai/djl/engine/Engine.java
+++ b/api/src/main/java/ai/djl/engine/Engine.java
@@ -332,6 +332,12 @@ public abstract class Engine {
         return seed;
     }
 
+    /** {@inheritDoc} */
+    @Override
+    public String toString() {
+        return getEngineName() + ':' + getVersion();
+    }
+
     /** Prints debug information about the environment for debugging environment issues. */
     @SuppressWarnings("PMD.SystemPrintln")
     public static void debugEnvironment() {
@@ -380,7 +386,7 @@ public abstract class Engine {
         System.out.println();
         System.out.println("----------------- Engines ---------------");
         System.out.println("DJL version: " + Engine.class.getPackage().getSpecificationVersion());
-        System.out.println("Default Engine: " + DEFAULT_ENGINE);
+        System.out.println("Default Engine: " + Engine.getInstance());
         System.out.println("Default Device: " + Engine.getInstance().defaultDevice());
         for (EngineProvider provider : ALL_ENGINES.values()) {
             System.out.println(provider.getEngineName() + ": " + provider.getEngineRank());
diff --git a/bom/build.gradle b/bom/build.gradle
index e6eadb38f..c7119f07e 100644
--- a/bom/build.gradle
+++ b/bom/build.gradle
@@ -27,6 +27,7 @@ dependencies {
         api "ai.djl.huggingface:tokenizers:${version}"
         api "ai.djl.ml.lightgbm:lightgbm:${version}"
         api "ai.djl.ml.xgboost:xgboost:${version}"
+        api "ai.djl.ml.xgboost:xgboost-gpu:${version}"
         api "ai.djl.mxnet:mxnet-engine:${version}"
         api "ai.djl.mxnet:mxnet-model-zoo:${version}"
         api "ai.djl.opencv:opencv:${version}"
diff --git a/engines/dlr/dlr-engine/src/main/java/ai/djl/dlr/engine/DlrEngine.java b/engines/dlr/dlr-engine/src/main/java/ai/djl/dlr/engine/DlrEngine.java
index 5b73e5ad5..ee8bf0d4f 100644
--- a/engines/dlr/dlr-engine/src/main/java/ai/djl/dlr/engine/DlrEngine.java
+++ b/engines/dlr/dlr-engine/src/main/java/ai/djl/dlr/engine/DlrEngine.java
@@ -125,10 +125,4 @@ public final class DlrEngine extends Engine {
     public void setRandomSeed(int seed) {
         throw new UnsupportedOperationException("Not supported for DLR");
     }
-
-    /** {@inheritDoc} */
-    @Override
-    public String toString() {
-        return getEngineName() + ':' + getVersion();
-    }
 }
diff --git a/engines/ml/lightgbm/build.gradle b/engines/ml/lightgbm/build.gradle
index 42c872163..86f5945d9 100644
--- a/engines/ml/lightgbm/build.gradle
+++ b/engines/ml/lightgbm/build.gradle
@@ -15,7 +15,6 @@ dependencies {
 publishing {
     publications {
         maven(MavenPublication) {
-            artifactId "lightgbm-engine"
             pom {
                 name = "DJL Engine Adapter for LightGBM"
                 description = "Deep Java Library (DJL) Engine Adapter for LightGBM"
diff --git a/engines/ml/lightgbm/src/main/java/ai/djl/ml/lightgbm/LgbmEngine.java b/engines/ml/lightgbm/src/main/java/ai/djl/ml/lightgbm/LgbmEngine.java
index 435a8976b..23d0c1adb 100644
--- a/engines/ml/lightgbm/src/main/java/ai/djl/ml/lightgbm/LgbmEngine.java
+++ b/engines/ml/lightgbm/src/main/java/ai/djl/ml/lightgbm/LgbmEngine.java
@@ -124,10 +124,4 @@ public final class LgbmEngine extends Engine {
     public void setRandomSeed(int seed) {
         throw new UnsupportedOperationException("Not supported for LightGBM");
     }
-
-    /** {@inheritDoc} */
-    @Override
-    public String toString() {
-        return getEngineName() + ':' + getVersion();
-    }
 }
diff --git a/engines/ml/xgboost/src/main/java/ai/djl/ml/xgboost/XgbEngine.java b/engines/ml/xgboost/src/main/java/ai/djl/ml/xgboost/XgbEngine.java
index ec20893fb..6449ee5f3 100644
--- a/engines/ml/xgboost/src/main/java/ai/djl/ml/xgboost/XgbEngine.java
+++ b/engines/ml/xgboost/src/main/java/ai/djl/ml/xgboost/XgbEngine.java
@@ -140,6 +140,12 @@ public final class XgbEngine extends Engine {
     /** {@inheritDoc} */
     @Override
     public String toString() {
-        return getEngineName() + ':' + getVersion();
+        StringBuilder sb = new StringBuilder(200);
+        sb.append(getEngineName()).append(':').append(getVersion()).append(", ");
+        sb.append(getEngineName()).append(':').append(getVersion()).append(", capabilities: [\n");
+        if (hasCapability(StandardCapabilities.CUDA)) {
+            sb.append("\t").append(StandardCapabilities.CUDA).append(",\n"); // NOPMD
+        }
+        return sb.toString();
     }
 }
diff --git a/engines/paddlepaddle/paddlepaddle-engine/src/main/java/ai/djl/paddlepaddle/engine/PpEngine.java b/engines/paddlepaddle/paddlepaddle-engine/src/main/java/ai/djl/paddlepaddle/engine/PpEngine.java
index a73a4941e..e48249159 100644
--- a/engines/paddlepaddle/paddlepaddle-engine/src/main/java/ai/djl/paddlepaddle/engine/PpEngine.java
+++ b/engines/paddlepaddle/paddlepaddle-engine/src/main/java/ai/djl/paddlepaddle/engine/PpEngine.java
@@ -127,10 +127,4 @@ public final class PpEngine extends Engine {
     public void setRandomSeed(int seed) {
         throw new UnsupportedOperationException("Not supported for PaddlePaddle");
     }
-
-    /** {@inheritDoc} */
-    @Override
-    public String toString() {
-        return getEngineName() + ':' + getVersion();
-    }
 }
diff --git a/engines/tflite/tflite-engine/src/main/java/ai/djl/tflite/engine/TfLiteEngine.java b/engines/tflite/tflite-engine/src/main/java/ai/djl/tflite/engine/TfLiteEngine.java
index f13d70aee..02be61faa 100644
--- a/engines/tflite/tflite-engine/src/main/java/ai/djl/tflite/engine/TfLiteEngine.java
+++ b/engines/tflite/tflite-engine/src/main/java/ai/djl/tflite/engine/TfLiteEngine.java
@@ -118,10 +118,4 @@ public final class TfLiteEngine extends Engine {
     public void setRandomSeed(int seed) {
         throw new UnsupportedOperationException("Not supported for TFLite");
     }
-
-    /** {@inheritDoc} */
-    @Override
-    public String toString() {
-        return getEngineName() + ':' + getVersion();
-    }
 }


Test patch:
diff --git a/engines/ml/xgboost/src/test/java/ai/djl/ml/xgboost/XgbModelTest.java b/engines/ml/xgboost/src/test/java/ai/djl/ml/xgboost/XgbModelTest.java
index ea9aabc38..8dffbdbbc 100644
--- a/engines/ml/xgboost/src/test/java/ai/djl/ml/xgboost/XgbModelTest.java
+++ b/engines/ml/xgboost/src/test/java/ai/djl/ml/xgboost/XgbModelTest.java
@@ -43,6 +43,7 @@ public class XgbModelTest {
     @BeforeClass
     public void downloadXGBoostModel() throws IOException {
         TestRequirements.notArm();
+        TestRequirements.notWindows();
 
         Path modelDir = Paths.get("build/model");
         DownloadUtils.download(
@@ -76,23 +77,24 @@ public class XgbModelTest {
 
     @Test
     public void testLoad() throws MalformedModelException, IOException, TranslateException {
-        // TODO: skip for Windows since it is not supported by XGBoost
-        if (!System.getProperty("os.name").startsWith("Win")) {
-            try (Model model = Model.newInstance("XGBoost")) {
-                model.load(Paths.get("build/model"), "regression");
-                Predictor<NDList, NDList> predictor = model.newPredictor(new NoopTranslator());
-                try (NDManager manager = NDManager.newBaseManager()) {
-                    NDArray array = manager.ones(new Shape(10, 13));
-                    NDList output = predictor.predict(new NDList(array));
-                    Assert.assertEquals(output.singletonOrThrow().getDataType(), DataType.FLOAT32);
-                    Assert.assertEquals(output.singletonOrThrow().toFloatArray().length, 10);
-                }
+        TestRequirements.notArm();
+        TestRequirements.notWindows();
+
+        try (Model model = Model.newInstance("XGBoost")) {
+            model.load(Paths.get("build/model"), "regression");
+            Predictor<NDList, NDList> predictor = model.newPredictor(new NoopTranslator());
+            try (NDManager manager = NDManager.newBaseManager()) {
+                NDArray array = manager.ones(new Shape(10, 13));
+                NDList output = predictor.predict(new NDList(array));
+                Assert.assertEquals(output.singletonOrThrow().getDataType(), DataType.FLOAT32);
+                Assert.assertEquals(output.singletonOrThrow().toFloatArray().length, 10);
             }
         }
     }
 
     @Test
     public void testNDArray() {
+        TestRequirements.notArm();
         TestRequirements.notWindows();
 
         try (XgbNDManager manager =