Incubator-mxnet: Clojure Library for mxnet

Created on 6 Dec 2017  路  17Comments  路  Source: apache/incubator-mxnet

Is there any interest for a Clojure library?

I'm interested in helping out. Any helpful pointers, (especially from the Scala side of things), in getting started would be appreciated.

Clojure

Most helpful comment

An update - I've ported over the MnistModule example to clojure - yay! 馃巻
https://github.com/gigasquid/incubator-mxnet/tree/clojure-package/clojure-package/examples

@yzhliu I'm currently developing on a Mac and would like to get GPU going there if possible so I can test that out too. Can I help with a PR to add this to the Scala build? https://github.com/apache/incubator-mxnet/issues/4469?

EDIT - taking a quick look at it and seeing if I can help out in this area. If not, I can test the GPU on the Clojure package on AWS.

  • Followup: Wasn't able to get gpu build for the base on my mac, but was able to verify that it runs fine on AWS linux gpu

All 17 comments

I looked at the Scala example for inspiration and it seems like a data driven information model (spec鈥檈d ?) would fit very well since it鈥檚 passing lots of maps around. I think a Clojure example would be awesome, speaking from an end users perspective.

Thanks. I'm working on porting over the Scala examples to Clojure and getting my feet wet 馃樃

I'll update this thread when I have something tangible.

I don't know whether Clojure has approaches for auto code-generation, like Scala macros. Otherwise it may be difficult to auto pick operators from c++ side.

Yes @javelinjs - Clojure has macros as well 馃槃
I'm still trying to figure out whether it's best to do Scala->Clojure or C++->Clojure, but I can get the Symbol functions either from Java reflection or from the c++ functions either way. I'll see how it shakes out as I dig in.

I have a start on the clojure package in my fork. I have the tests for the ndarray, symbol, and operator tests ported over. I'll continue to work in this branch with the goal of completing the porting over the api, tests, and examples. Feedback is welcome, just ping me on slack.

https://github.com/gigasquid/incubator-mxnet/tree/clojure-package/clojure-package

An update - I've ported over the MnistModule example to clojure - yay! 馃巻
https://github.com/gigasquid/incubator-mxnet/tree/clojure-package/clojure-package/examples

@yzhliu I'm currently developing on a Mac and would like to get GPU going there if possible so I can test that out too. Can I help with a PR to add this to the Scala build? https://github.com/apache/incubator-mxnet/issues/4469?

EDIT - taking a quick look at it and seeing if I can help out in this area. If not, I can test the GPU on the Clojure package on AWS.

  • Followup: Wasn't able to get gpu build for the base on my mac, but was able to verify that it runs fine on AWS linux gpu

Please add labels: "Scala", "Feature request", "Feature" , "Example"

@gigasquid I do not have a mac with GPU, would be good if you can check why doesn't it work - not an urgent issue.

Another update - I have the CNN text classification example as well as the GAN MNIST working!
MXNet rocks :)

gout-9-500

@yzhliu I think my gpu problems were related to moving to High Sierra. I'll circle back and take another look soon in the near future 馃憖

@gigasquid are you using an NVIDIA GPU on a Mac? If so, you might want to consider downgrading your NVIDIA Web Drivers. Currently the latest stable one that works for me is 387.10.10.10.25.106, which is best installed with https://github.com/Benjamin-Dobell/nvidia-update. If you're using an eGPU, you still need the NVIDIAEGPUSupport package that corresponds to your macOS build version (check with system_profiler SPSoftwareDataType).

I understand the MXNet build issue might be a separate one, but perhaps it's relevant to you. Best of luck building this Clojure integration.

I started trying to build clojure version of MXNet. It took half day to make lein test to work on my GPU cluster. All my tests pass (good news) but I think they are loading the CPU version. I am on ubuntu with cuda-8.0.

My GPU version is successfully built at scala-package/native/linux-x86_64-gpu/target/libmxnet-scala-linux-x86_64-gpu.so

Everytime, I run lein test, I get this message. Is there a way to specify LD_LIBRARY_PATH before running lein test or any example for that matter?

Edit: Setting :jvm-opts solved the problem and I could train on multiple GPUs too :) . There should be GPU tests as well.

INFO  MXNetJVM: Try loading mxnet-scala from native path.
INFO  MXNetJVM: Try loading mxnet-scala-linux-x86_64-gpu from native path.
INFO  MXNetJVM: Try loading mxnet-scala-linux-x86_64-cpu from native path.
WARN  MXNetJVM: MXNet Scala native library not found in path. Copying native library from the archive. Consider installing the library somewhere in the path (for Windows: PATH, for Linux: LD_LIBRARY_PATH), or specifying by Java cmd option -Djava.library.path=[lib path].
INFO  ml.dmlc.mxnet.util.NativeLibraryLoader: Loading libmxnet-scala.so from /lib/native/ copying to mxnet-scala

FYI, I checked whether .so is built with cuda or not.

ldd ../scala-package/native/linux-x86_64-gpu/target/libmxnet-scala-linux-x86_64-gpu.so | grep cuda
    libcuda.so.1 => /usr/local/nvidia/lib64/libcuda.so.1 (0x00007f6ad725e000)
    libcudart.so.8.0 => /usr/local/cuda/lib64/libcudart.so.8.0 (0x00007f6ad6ff7000)
    libcublas.so.8.0 => /usr/local/cuda/lib64/libcublas.so.8.0 (0x00007f6ad3fb2000)
    libcurand.so.8.0 => /usr/local/cuda/lib64/libcurand.so.8.0 (0x00007f6ad003c000)
    libcusolver.so.8.0 => /usr/local/cuda/lib64/libcusolver.so.8.0 (0x00007f6accacd000)
    libcudnn.so.6 => /usr/local/cuda/lib64/libcudnn.so.6 (0x00007f6ac07b6000)
    libcufft.so.8.0 => /usr/local/cuda/lib64/libcufft.so.8.0 (0x00007f6ab7967000)
    libnvrtc.so.8.0 => /usr/local/cuda/lib64/libnvrtc.so.8.0 (0x00007f6ab654a000)
    libicudata.so.55 => /usr/lib/x86_64-linux-gnu/libicudata.so.55 (0x00007f6a9ed21000)

Thank you very much for this!

@sivakon Thanks for your interest!
The clojure package just uses the Scala package mechanism for loading the native library https://github.com/apache/incubator-mxnet/blob/master/scala-package/core/src/main/scala/org/apache/mxnet/Base.scala. In this case, it extracts the native library from your the bundled jar and loads it.

One way you can test for sure to make sure the gpu is being used is to specify running with it directly in one of your tests. There is is an example of this in examples/tutorial in the tutorial.ndarray file.

(def gpu-b (ndarray/zeros [100 200] {:ctx (context/gpu 0)})) ;; to use with gpu

If you are using the cpu native lib, you will get an error saying that you should recompile with gpu flag.
[08:53:00] src/storage/storage.cc:123: Compile with USE_CUDA=1 to enable GPU usage

There are some settings for leiningen to use to specify native lib path, but I haven't really looked into that or tested that config yet.

I've been developing the project so far on my local osx laptop, so I've stuck to cpu, but there are some examples that can be easily converted to use cpu/gpu. (for example see imclassification.train-mnist). I'll also do a pass on the examples to make sure there is a easy runnable switch to change context in the near future.

Just a heads up that the scala jars should be pushed to maven soon 馃巿 so it will be much better to test the package. At that point, I will most likely mirror this out to a separate github repo to make it easier for people to alpha test it and collect feedback to get it to a good shape to create a PR to be included in the main project.

I'll post a link here when that happens. Thanks again.

@gigasquid Thanks for this. I tested some of the examples on GPU (all static graphs using symbols). Will there be gluon support later? Gluon support will ideally give this an imperative python like API (clojurish may be tough)

@sivakon The goal is to have the same level of support for MXNet as in the other language packages. The Clojure package will most likely piggy back on the Scala work when it lands there.

You can do the same level of imperative operations with the Module API right now if you want to check out some of their examples.

Update: The scala jars have been published to Maven (yay!) - I've created up a repo for testing of the Clojure package and getting feedback before opening a formal PR https://github.com/gigasquid/clojure-mxnet.

Please feel free to give it a test drive and let me know in issues any problems you have 馃樃

I think this issue can be closed now that #11205 has been merged?

Was this page helpful?
0 / 5 - 0 ratings