Repository: deepjavalibrary/djl
Pull request #3444 (2024-08-28 16:48:50)

[rust] Adds text classification models to Rust model zoo
## 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/bom/build.gradle.kts b/bom/build.gradle.kts
index 9c4e87c58..3ee65ff6d 100644
--- a/bom/build.gradle.kts
+++ b/bom/build.gradle.kts
@@ -48,6 +48,7 @@ dependencies {
         api("ai.djl.timeseries:timeseries:${version}")
         api("com.microsoft.onnxruntime:onnxruntime:${libs.versions.onnxruntime.get()}")
         api("com.microsoft.onnxruntime:onnxruntime_gpu:${libs.versions.onnxruntime.get()}")
+        api("com.microsoft.onnxruntime:onnxruntime-extensions:${libs.versions.onnxruntimeExtensions.get()}")
     }
 }
 
diff --git a/engines/onnxruntime/onnxruntime-engine/src/main/java/ai/djl/onnxruntime/engine/OrtEngine.java b/engines/onnxruntime/onnxruntime-engine/src/main/java/ai/djl/onnxruntime/engine/OrtEngine.java
index ee843bfdd..c3c2ea0ee 100644
--- a/engines/onnxruntime/onnxruntime-engine/src/main/java/ai/djl/onnxruntime/engine/OrtEngine.java
+++ b/engines/onnxruntime/onnxruntime-engine/src/main/java/ai/djl/onnxruntime/engine/OrtEngine.java
@@ -102,7 +102,7 @@ public final class OrtEngine extends Engine {
     /** {@inheritDoc} */
     @Override
     public String getVersion() {
-        return "1.18.0";
+        return "1.19.0";
     }
 
     /** {@inheritDoc} */
diff --git a/extensions/tokenizers/src/main/java/ai/djl/engine/rust/zoo/RsModelZoo.java b/extensions/tokenizers/src/main/java/ai/djl/engine/rust/zoo/RsModelZoo.java
index f706bc865..6bd7cfc9d 100644
--- a/extensions/tokenizers/src/main/java/ai/djl/engine/rust/zoo/RsModelZoo.java
+++ b/extensions/tokenizers/src/main/java/ai/djl/engine/rust/zoo/RsModelZoo.java
@@ -68,6 +68,7 @@ public class RsModelZoo extends ModelZoo {
                 if (!initialized) {
                     Version version = new Version(Engine.getDjlVersion());
                     addModels(Application.NLP.TEXT_EMBEDDING, version);
+                    addModels(Application.NLP.TEXT_CLASSIFICATION, version);
                     initialized = true;
                 }
             }
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index ce3a61619..7ac16b108 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -7,8 +7,8 @@ pytorch = "2.4.0"
 tensorflow = "2.16.1"
 tensorflowCore = "1.0.0-rc.1"
 mxnet = "1.9.1"
-onnxruntime = "1.18.0"
-onnxruntimeExtensions = "0.11.0"
+onnxruntime = "1.19.0"
+onnxruntimeExtensions = "0.12.4"
 xgboost = "2.0.3"
 lightgbm = "3.2.110"
 tensorrt = "8.4.1"
diff --git a/model-zoo/src/main/java/ai/djl/basicmodelzoo/basic/Mlp.java b/model-zoo/src/main/java/ai/djl/basicmodelzoo/basic/Mlp.java
index 2869e42f5..642b48364 100644
--- a/model-zoo/src/main/java/ai/djl/basicmodelzoo/basic/Mlp.java
+++ b/model-zoo/src/main/java/ai/djl/basicmodelzoo/basic/Mlp.java
@@ -59,8 +59,8 @@ public class Mlp extends SequentialBlock {
     @SuppressWarnings("this-escape")
     public Mlp(int input, int output, int[] hidden, Function<NDList, NDList> activation) {
         add(Blocks.batchFlattenBlock(input));
-        for (int hiddenSize : hidden) {
-            add(Linear.builder().setUnits(hiddenSize).build());
+        for (int hiddenLayerSize : hidden) {
+            add(Linear.builder().setUnits(hiddenLayerSize).build());
             add(activation);
         }
 


Test patch:
diff --git a/engines/onnxruntime/onnxruntime-engine/src/test/java/ai/djl/onnxruntime/engine/OrtTest.java b/engines/onnxruntime/onnxruntime-engine/src/test/java/ai/djl/onnxruntime/engine/OrtTest.java
index dce451975..df6fa99fc 100644
--- a/engines/onnxruntime/onnxruntime-engine/src/test/java/ai/djl/onnxruntime/engine/OrtTest.java
+++ b/engines/onnxruntime/onnxruntime-engine/src/test/java/ai/djl/onnxruntime/engine/OrtTest.java
@@ -73,6 +73,7 @@ public class OrtTest {
             Criteria<IrisFlower, Classifications> criteria =
                     Criteria.builder()
                             .setTypes(IrisFlower.class, Classifications.class)
+                            .optModelUrls("djl://ai.djl.onnxruntime/iris_flowers")
                             .optEngine("OnnxRuntime") // use OnnxRuntime engine
                             .optOption("interOpNumThreads", "1")
                             .optOption("intraOpNumThreads", "1")
diff --git a/extensions/tokenizers/src/test/java/ai/djl/huggingface/zoo/ModelZooTest.java b/extensions/tokenizers/src/test/java/ai/djl/huggingface/zoo/ModelZooTest.java
index 4605702a1..6ea38ddb0 100644
--- a/extensions/tokenizers/src/test/java/ai/djl/huggingface/zoo/ModelZooTest.java
+++ b/extensions/tokenizers/src/test/java/ai/djl/huggingface/zoo/ModelZooTest.java
@@ -55,8 +55,8 @@ public class ModelZooTest {
         try (ZooModel<QAInput, String> model = criteria.loadModel();
                 Predictor<QAInput, String> predictor = model.newPredictor()) {
             QAInput input = new QAInput(question, paragraph);
-            String res = predictor.predict(input);
-            Assert.assertEquals(res, "december 2004");
+            String result = predictor.predict(input);
+            Assert.assertEquals(result, "december 2004");
         }
     }
 
@@ -101,7 +101,7 @@ public class ModelZooTest {
     }
 
     @Test
-    public void testOffLine() {
+    public void testOffline() {
         System.setProperty("DJL_CACHE_DIR", "build/cache");
         System.setProperty("ai.djl.offline", "true");
         try {