Repository: deepjavalibrary/djl
Pull request #1978 (2022-08-31 03:57:04)

[api] Remove unnecessary DeviceType interface
Change-Id: Ife754d8b82371c1cd86d8201d003fe8f7995ed92

## 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


codecov-commenter: # [Codecov](https://codecov.io/gh/deepjavalibrary/djl/pull/1978?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary) Report
> Merging [#1978](https://codecov.io/gh/deepjavalibrary/djl/pull/1978?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary) (22a0d12) into [master](https://codecov.io/gh/deepjavalibrary/djl/commit/bb5073f7ffc33f1883621fc1783dbb01e70b418f?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary) (bb5073f) will **decrease** coverage by `2.00%`.
> The diff coverage is `68.47%`.

```diff
@@             Coverage Diff              @@
##             master    #1978      +/-   ##
============================================
- Coverage     72.08%   70.08%   -2.01%     
- Complexity     5126     5860     +734     
============================================
  Files           473      579     +106     
  Lines         21970    25957    +3987     
  Branches       2351     2795     +444     
============================================
+ Hits          15838    18193    +2355     
- Misses         4925     6392    +1467     
- Partials       1207     1372     +165     
```


| [Impacted Files](https://codecov.io/gh/deepjavalibrary/djl/pull/1978?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary) | Coverage Δ | |
|---|---|---|
| [api/src/main/java/ai/djl/modality/cv/Image.java](https://codecov.io/gh/deepjavalibrary/djl/pull/1978/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary#diff-YXBpL3NyYy9tYWluL2phdmEvYWkvZGpsL21vZGFsaXR5L2N2L0ltYWdlLmphdmE=) | `69.23% <ø> (-4.11%)` | :arrow_down: |
| [...rc/main/java/ai/djl/modality/cv/MultiBoxPrior.java](https://codecov.io/gh/deepjavalibrary/djl/pull/1978/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary#diff-YXBpL3NyYy9tYWluL2phdmEvYWkvZGpsL21vZGFsaXR5L2N2L011bHRpQm94UHJpb3IuamF2YQ==) | `76.00% <ø> (ø)` | |
| [...rc/main/java/ai/djl/modality/cv/output/Joints.java](https://codecov.io/gh/deepjavalibrary/djl/pull/1978/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary#diff-YXBpL3NyYy9tYWluL2phdmEvYWkvZGpsL21vZGFsaXR5L2N2L291dHB1dC9Kb2ludHMuamF2YQ==) | `71.42% <ø> (ø)` | |
| [.../main/java/ai/djl/modality/cv/output/Landmark.java](https://codecov.io/gh/deepjavalibrary/djl/pull/1978/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary#diff-YXBpL3NyYy9tYWluL2phdmEvYWkvZGpsL21vZGFsaXR5L2N2L291dHB1dC9MYW5kbWFyay5qYXZh) | `100.00% <ø> (ø)` | |
| [...main/java/ai/djl/modality/cv/output/Rectangle.java](https://codecov.io/gh/deepjavalibrary/djl/pull/1978/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary#diff-YXBpL3NyYy9tYWluL2phdmEvYWkvZGpsL21vZGFsaXR5L2N2L291dHB1dC9SZWN0YW5nbGUuamF2YQ==) | `72.41% <0.00%> (ø)` | |
| [...i/djl/modality/cv/translator/BigGANTranslator.java](https://codecov.io/gh/deepjavalibrary/djl/pull/1978/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary#diff-YXBpL3NyYy9tYWluL2phdmEvYWkvZGpsL21vZGFsaXR5L2N2L3RyYW5zbGF0b3IvQmlnR0FOVHJhbnNsYXRvci5qYXZh) | `21.42% <0.00%> (-5.24%)` | :arrow_down: |
| [...odality/cv/translator/BigGANTranslatorFactory.java](https://codecov.io/gh/deepjavalibrary/djl/pull/1978/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary#diff-YXBpL3NyYy9tYWluL2phdmEvYWkvZGpsL21vZGFsaXR5L2N2L3RyYW5zbGF0b3IvQmlnR0FOVHJhbnNsYXRvckZhY3RvcnkuamF2YQ==) | `33.33% <0.00%> (+8.33%)` | :arrow_up: |
| [...nslator/InstanceSegmentationTranslatorFactory.java](https://codecov.io/gh/deepjavalibrary/djl/pull/1978/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary#diff-YXBpL3NyYy9tYWluL2phdmEvYWkvZGpsL21vZGFsaXR5L2N2L3RyYW5zbGF0b3IvSW5zdGFuY2VTZWdtZW50YXRpb25UcmFuc2xhdG9yRmFjdG9yeS5qYXZh) | `14.28% <0.00%> (-3.90%)` | :arrow_down: |
| [.../cv/translator/SemanticSegmentationTranslator.java](https://codecov.io/gh/deepjavalibrary/djl/pull/1978/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary#diff-YXBpL3NyYy9tYWluL2phdmEvYWkvZGpsL21vZGFsaXR5L2N2L3RyYW5zbGF0b3IvU2VtYW50aWNTZWdtZW50YXRpb25UcmFuc2xhdG9yLmphdmE=) | `0.00% <0.00%> (ø)` | |
| [.../cv/translator/StyleTransferTranslatorFactory.java](https://codecov.io/gh/deepjavalibrary/djl/pull/1978/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary#diff-YXBpL3NyYy9tYWluL2phdmEvYWkvZGpsL21vZGFsaXR5L2N2L3RyYW5zbGF0b3IvU3R5bGVUcmFuc2ZlclRyYW5zbGF0b3JGYWN0b3J5LmphdmE=) | `40.00% <ø> (ø)` | |
| ... and [485 more](https://codecov.io/gh/deepjavalibrary/djl/pull/1978/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary) | |

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary)


Patch:
diff --git a/api/src/main/java/ai/djl/DeviceType.java b/api/src/main/java/ai/djl/DeviceType.java
deleted file mode 100644
index 45cc4fad4..000000000
--- a/api/src/main/java/ai/djl/DeviceType.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright 2019 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;
-
-/** {@code DeviceType} is a class used to map the Device name to their corresponding type number. */
-public interface DeviceType {
-
-    /**
-     * Map device to its type number.
-     *
-     * @param device {@link Device} to map from
-     * @return the number specified by engine
-     */
-    static int toDeviceType(Device device) {
-        return 0;
-    }
-
-    /**
-     * Map device to its type number.
-     *
-     * @param deviceType the number specified by engine
-     * @return {@link Device} to map to
-     */
-    static String fromDeviceType(int deviceType) {
-        return null;
-    }
-}
diff --git a/engines/mxnet/mxnet-engine/src/main/java/ai/djl/mxnet/engine/MxDeviceType.java b/engines/mxnet/mxnet-engine/src/main/java/ai/djl/mxnet/engine/MxDeviceType.java
index 7d4e754a8..6b38c2f40 100644
--- a/engines/mxnet/mxnet-engine/src/main/java/ai/djl/mxnet/engine/MxDeviceType.java
+++ b/engines/mxnet/mxnet-engine/src/main/java/ai/djl/mxnet/engine/MxDeviceType.java
@@ -13,10 +13,9 @@
 package ai.djl.mxnet.engine;
 
 import ai.djl.Device;
-import ai.djl.DeviceType;
 
 /** DeviceType is the MXNet equivalent of the types in {@link Device}. */
-public final class MxDeviceType implements DeviceType {
+public final class MxDeviceType {
 
     private static final String CPU_PINNED = "cpu_pinned";
 
@@ -38,7 +37,7 @@ public final class MxDeviceType implements DeviceType {
         } else if (CPU_PINNED.equals(deviceType)) {
             return 3;
         } else {
-            throw new IllegalArgumentException("Unsupported device: " + device.toString());
+            throw new IllegalArgumentException("Unsupported device: " + device);
         }
     }
 
diff --git a/engines/pytorch/pytorch-engine/src/main/java/ai/djl/pytorch/engine/PtDeviceType.java b/engines/pytorch/pytorch-engine/src/main/java/ai/djl/pytorch/engine/PtDeviceType.java
index c898ddfd8..78b620345 100644
--- a/engines/pytorch/pytorch-engine/src/main/java/ai/djl/pytorch/engine/PtDeviceType.java
+++ b/engines/pytorch/pytorch-engine/src/main/java/ai/djl/pytorch/engine/PtDeviceType.java
@@ -13,10 +13,9 @@
 package ai.djl.pytorch.engine;
 
 import ai.djl.Device;
-import ai.djl.DeviceType;
 
 /** DeviceType is the PyTorch equivalent of the types in {@link Device}. */
-public final class PtDeviceType implements DeviceType {
+public final class PtDeviceType {
 
     private PtDeviceType() {}
 


Test patch:
diff --git a/engines/mxnet/mxnet-model-zoo/src/test/java/ai/djl/mxnet/integration/modality/nlp/WordEmbeddingTest.java b/engines/mxnet/mxnet-model-zoo/src/test/java/ai/djl/mxnet/integration/modality/nlp/WordEmbeddingTest.java
index 726374423..7f6822359 100644
--- a/engines/mxnet/mxnet-model-zoo/src/test/java/ai/djl/mxnet/integration/modality/nlp/WordEmbeddingTest.java
+++ b/engines/mxnet/mxnet-model-zoo/src/test/java/ai/djl/mxnet/integration/modality/nlp/WordEmbeddingTest.java
@@ -32,6 +32,7 @@ public class WordEmbeddingTest {
     @Test
     public void testGlove() throws IOException, ModelException, EmbeddingException {
         TestRequirements.notArm();
+        TestRequirements.engine("MXNet");
 
         Criteria<String, NDList> criteria =
                 Criteria.builder()
diff --git a/extensions/audio/src/test/java/ai/djl/audio/FFmpegAudioFactoryTest.java b/extensions/audio/src/test/java/ai/djl/audio/FFmpegAudioFactoryTest.java
index 7cfe2ca63..4539fedd7 100644
--- a/extensions/audio/src/test/java/ai/djl/audio/FFmpegAudioFactoryTest.java
+++ b/extensions/audio/src/test/java/ai/djl/audio/FFmpegAudioFactoryTest.java
@@ -17,6 +17,7 @@ import ai.djl.modality.audio.AudioFactory;
 import ai.djl.ndarray.NDArray;
 import ai.djl.ndarray.NDManager;
 import ai.djl.ndarray.types.Shape;
+import ai.djl.testing.TestRequirements;
 import ai.djl.training.util.DownloadUtils;
 
 import org.testng.Assert;
@@ -32,6 +33,7 @@ public class FFmpegAudioFactoryTest {
 
     @BeforeClass
     public void setUp() throws IOException {
+        TestRequirements.notArm();
         DownloadUtils.download(URL, "build/test/test_01.wav");
     }
 
diff --git a/extensions/timeseries/src/test/java/ai/djl/timeseries/transform/TransformTest.java b/extensions/timeseries/src/test/java/ai/djl/timeseries/transform/TransformTest.java
index 8e521f048..0a840fcc4 100644
--- a/extensions/timeseries/src/test/java/ai/djl/timeseries/transform/TransformTest.java
+++ b/extensions/timeseries/src/test/java/ai/djl/timeseries/transform/TransformTest.java
@@ -18,6 +18,7 @@ import ai.djl.ndarray.NDArray;
 import ai.djl.ndarray.NDManager;
 import ai.djl.ndarray.index.NDIndex;
 import ai.djl.ndarray.types.Shape;
+import ai.djl.testing.TestRequirements;
 import ai.djl.timeseries.TimeSeriesData;
 import ai.djl.timeseries.dataset.FieldName;
 import ai.djl.timeseries.timefeature.TimeFeature;
@@ -27,6 +28,7 @@ import ai.djl.timeseries.transform.field.Field;
 import ai.djl.timeseries.transform.split.Split;
 
 import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
 import java.time.LocalDateTime;
@@ -36,6 +38,11 @@ import java.util.function.BiFunction;
 
 public class TransformTest {
 
+    @BeforeClass
+    public void setUp() {
+        TestRequirements.notArm();
+    }
+
     @Test
     public void testVstackFeatures() {
         try (NDManager manager = NDManager.newBaseManager(Device.cpu())) {
diff --git a/extensions/timeseries/src/test/java/ai/djl/timeseries/translator/DeepARTranslatorTest.java b/extensions/timeseries/src/test/java/ai/djl/timeseries/translator/DeepARTranslatorTest.java
index 8e64746ba..4c442dde1 100644
--- a/extensions/timeseries/src/test/java/ai/djl/timeseries/translator/DeepARTranslatorTest.java
+++ b/extensions/timeseries/src/test/java/ai/djl/timeseries/translator/DeepARTranslatorTest.java
@@ -19,6 +19,7 @@ import ai.djl.ndarray.NDManager;
 import ai.djl.ndarray.types.Shape;
 import ai.djl.repository.zoo.Criteria;
 import ai.djl.repository.zoo.ZooModel;
+import ai.djl.testing.TestRequirements;
 import ai.djl.timeseries.Forecast;
 import ai.djl.timeseries.TimeSeriesData;
 import ai.djl.timeseries.dataset.FieldName;
@@ -37,6 +38,8 @@ public class DeepARTranslatorTest {
 
     @Test
     public void testDeepARTranslator() throws IOException, TranslateException, ModelException {
+        TestRequirements.notArm();
+
         String modelUrl = "https://resources.djl.ai/test-models/mxnet/timeseries/deepar.zip";
         Map<String, Object> arguments = new ConcurrentHashMap<>();
         arguments.put("prediction_length", 28);
diff --git a/extensions/timeseries/src/test/java/ai/djl/timeseries/translator/TransformerTranslatorTest.java b/extensions/timeseries/src/test/java/ai/djl/timeseries/translator/TransformerTranslatorTest.java
index e12af5150..49295b4f9 100644
--- a/extensions/timeseries/src/test/java/ai/djl/timeseries/translator/TransformerTranslatorTest.java
+++ b/extensions/timeseries/src/test/java/ai/djl/timeseries/translator/TransformerTranslatorTest.java
@@ -19,6 +19,7 @@ import ai.djl.ndarray.NDManager;
 import ai.djl.ndarray.types.Shape;
 import ai.djl.repository.zoo.Criteria;
 import ai.djl.repository.zoo.ZooModel;
+import ai.djl.testing.TestRequirements;
 import ai.djl.timeseries.Forecast;
 import ai.djl.timeseries.TimeSeriesData;
 import ai.djl.timeseries.dataset.FieldName;
@@ -37,6 +38,8 @@ public class TransformerTranslatorTest {
 
     @Test
     public void testTransformerTranslator() throws IOException, TranslateException, ModelException {
+        TestRequirements.notArm();
+
         String modelUrl = "https://resources.djl.ai/test-models/mxnet/timeseries/transformer.zip";
         Map<String, Object> arguments = new ConcurrentHashMap<>();
         arguments.put("prediction_length", 28);
diff --git a/extensions/tokenizers/src/test/java/ai/djl/huggingface/tokenizers/TranslatorTest.java b/extensions/tokenizers/src/test/java/ai/djl/huggingface/tokenizers/TranslatorTest.java
index 88c72d41c..c37743565 100644
--- a/extensions/tokenizers/src/test/java/ai/djl/huggingface/tokenizers/TranslatorTest.java
+++ b/extensions/tokenizers/src/test/java/ai/djl/huggingface/tokenizers/TranslatorTest.java
@@ -33,7 +33,6 @@ import ai.djl.nn.LambdaBlock;
 import ai.djl.repository.zoo.Criteria;
 import ai.djl.repository.zoo.ZooModel;
 import ai.djl.testing.Assertions;
-import ai.djl.testing.TestRequirements;
 import ai.djl.translate.TranslateException;
 import ai.djl.util.JsonUtils;
 import ai.djl.util.Utils;
@@ -59,8 +58,6 @@ public class TranslatorTest {
 
     @Test
     public void testQATranslator() throws ModelException, IOException, TranslateException {
-        TestRequirements.notArm();
-
         String question = "When did BBC Japan start broadcasting?";
         String paragraph =
                 "BBC Japan was a general entertainment Channel. "
@@ -146,8 +143,6 @@ public class TranslatorTest {
 
     @Test
     public void testFillMaskTranslator() throws ModelException, IOException, TranslateException {
-        TestRequirements.notArm();
-
         String text = "Hello I'm a [MASK] model.";
 
         Block block =
@@ -235,8 +230,6 @@ public class TranslatorTest {
     @Test
     public void testTokenClassificationTranslator()
             throws ModelException, IOException, TranslateException {
-        TestRequirements.notArm();
-
         String text = "My name is Wolfgang and I live in Berlin.";
 
         Block block =
@@ -331,8 +324,6 @@ public class TranslatorTest {
     @Test
     public void testTextEmbeddingTranslator()
             throws ModelException, IOException, TranslateException {
-        TestRequirements.notArm();
-
         String text = "This is an example sentence";
 
         Block block =