The MXNet Scala/Java Package brings flexible and efficient GPU/CPU computing and state-of-art deep learning to the JVM.
The MXNet Scala/Java packages can be easily included in your Maven managed project. The stable jar files for the packages are available on the MXNet Maven Package Repository. Currently we provide packages for Linux (Ubuntu 16.04) (CPU and GPU) and macOS (CPU only). Stable packages for Windows and CentOS will come soon. For now, if you have a CentOS machine, follow the Build From Source
section below.
To add the MXNet Scala/Java packages to your project, add the dependency as shown below corresponding to your platform, under the dependencies
tag in your project's pom.xml
:
Linux GPU
<dependency> <groupId>org.apache.mxnet</groupId> <artifactId>mxnet-full_2.11-linux-x86_64-gpu</artifactId> <version>[1.4.0,)</version> </dependency>
Linux CPU
<dependency> <groupId>org.apache.mxnet</groupId> <artifactId>mxnet-full_2.11-linux-x86_64-cpu</artifactId> <version>[1.4.0,)</version> </dependency>
macOS CPU
<dependency> <groupId>org.apache.mxnet</groupId> <artifactId>mxnet-full_2.11-osx-x86_64-cpu</artifactId> <version>[1.4.0,)</version> </dependency>
Note: <version>[1.4.0,)<\version>
indicates that we will fetch packages with version 1.4.0 or higher. This will always ensure that the pom.xml is able to fetch the latest and greatest jar files from Maven.
Apart from these, the nightly builds representing the bleeding edge development on Scala/Java packages are also available on the MXNet Maven Nexus Package Repository. Currently we provide nightly packages for Linux (CPU and GPU) and MacOS (CPU only). The Linux nightly jar files also work on CentOS. Nightly packages for Windows will come soon.
Add the following repository
to your project's pom.xml
file :
<repositories> <repository> <id>Apache Snapshot</id> <url>https://repository.apache.org/content/groups/snapshots</url> </repository> </repositories>
Also, add the dependency which corresponds to your platform to the dependencies
tag :
Linux GPU
<dependency> <groupId>org.apache.mxnet</groupId> <artifactId>mxnet-full_2.11-linux-x86_64-gpu</artifactId> <version>[1.6.0-SNAPSHOT,)</version> </dependency>
Linux CPU
<dependency> <groupId>org.apache.mxnet</groupId> <artifactId>mxnet-full_2.11-linux-x86_64-cpu</artifactId> <version>[1.6.0-SNAPSHOT,)</version> </dependency>
macOS CPU
<dependency> <groupId>org.apache.mxnet</groupId> <artifactId>mxnet-full_2.11-osx-x86_64-cpu</artifactId> <version>[1.6.0-SNAPSHOT,)</version> </dependency>
Note: <version>[1.6.0-SNAPSHOT,)</version>
indicates that we will fetch packages with version 1.6.0 or higher. This will always ensure that the pom.xml is able to fetch the latest and greatest jar files from Maven Snapshot repository.
The Installation Guide contains instructions to install mxnet or build it from source. The Scala/Java package is built from source using Maven. The maven build assumes you already have a lib/libmxnet.so
file. If you have built MXNet from source and are looking to set up Scala\Java from that point, you may simply run the following from the MXNet source root, the build will detect your platform (OSX/Linux) and libmxnet.so flavor (CPU/GPU):
cd scala-package mvn install
You can also run the unit tests and integration tests on the Scala Package by :
cd scala-package mvn integration-test -DskipTests=false
Or run a subset of unit tests, for e.g.,
cd scala-package mvn -Dsuites=org.apache.mxnet.NDArraySuite integration-test
If everything goes well, you will find jars for assembly
, core
and example
modules. Also it produces the native library in native/target
, which you can use in conjunction with the core
module.
By default, maven deploy
will deploy artifacts to local file system, you can find them in the scala-package/deploy/target/repo
folder.
For nightly builds (typically done by CI), a snapshot build will be uploaded to an apache snapshot repository with the following command:
cd scala-package mvn deploy -Pnightly
Use the following command when performing a release (pushes artifacts to an apache staging repository):
cd scala-package mvn deploy -Pstaging
Assuming you use mvn install
, you can find the mxnet-full_scala_version-INTERNAL.jar
e.g. mxnet-full_2.11-INTERNAL.jar
under the path incubator-mxnet/scala-package/assembly/target
.
Adding the following configuration in pom.xml
<dependency> <groupId>org.apache.mxnet</groupId> <artifactId>mxnet-full_2.11-INTERNAL</artifactId> <version>1.6.0</version> <scope>system</scope> <systemPath>path_to_jar/mxnet-full_2.11-INTERNAL.jar</systemPath> </dependency>
If you have following error message
Error: A JNI error has occurred, please check your installation and try again Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/mxnet/NDArray at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) at java.lang.Class.privateGetMethodRecursive(Class.java:3048) at java.lang.Class.getMethod0(Class.java:3018) at java.lang.Class.getMethod(Class.java:1784) at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544) at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526) Caused by: java.lang.ClassNotFoundException: org.apache.mxnet.NDArray at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
Please make sure your $CLASSPATH contains mxnet-full_scala_version-INTERNAL.jar
.
Module API : The Module API provides an intermediate and high-level interface for performing computation with neural networks in MXNet. Modules provide high-level APIs for training, predicting, and evaluating.
KVStore API : To run training over multiple GPUs and multiple hosts, one can use the KVStore API.
IO/Data Loading : MXNet Scala provides APIs for preparing data to feed as an input to models. Check out Data Loading API for more info.
Other available Scala APIs for training can be found here.
The Scala Inference APIs provide an easy, out of the box solution to load a pre-trained MXNet model and run inference on it. The Inference APIs are present in the Infer Package under the MXNet Scala Package repository, while the documentation for the Infer API is available here.
The Java Inference APIs also provide an easy, out of the box solution to load a pre-trained MXNet model and run inference on it. The Inference APIs are present in the Infer Package under the MXNet Scala Package repository, while the documentation for the Infer API is available here. More APIs will be added to the Java Inference APIs soon.
The Scala/Java APIs also provide an automated resource management system, thus making it easy to manage the native memory footprint without any degradation in performance. More details about JVM Memory Management are available here.
MXNet Scala Package is licensed under Apache-2 license.
MXNet uses some 3rd party softwares. Following 3rd party license files are bundled inside Scala jar file: