forked from apache/mxnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MXNET-624] Clojure Package Api Docs for the Website (apache#11574)
Clojure Package Api Docs
- Loading branch information
Showing
16 changed files
with
750 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# MXNet - Clojure API | ||
MXNet supports the Clojure programming language. The MXNet Clojure package brings flexible and efficient GPU | ||
computing and state-of-art deep learning to Clojure. It enables you to write seamless tensor/matrix computation with multiple GPUs in Clojure. It also lets you construct and customize the state-of-art deep learning models in Clojure, and apply them to tasks, such as image classification and data science challenges. | ||
|
||
See the [MXNet Clojure API Documentation](docs/index.html) for detailed API information. | ||
|
||
|
||
## Tensor and Matrix Computations | ||
You can perform tensor or matrix computation in pure Clojure: | ||
|
||
```clojure | ||
(def arr (ndarray/ones [2 3])) | ||
|
||
arr ;=> #object[org.apache.mxnet.NDArray 0x597d72e "org.apache.mxnet.NDArray@e35c3ba9"] | ||
|
||
(ndarray/shape-vec arr) ;=> [2 3] | ||
|
||
(-> (ndarray/* arr 2) | ||
(ndarray/->vec)) ;=> [2.0 2.0 2.0 2.0 2.0 2.0] | ||
|
||
(ndarray/shape-vec (ndarray/* arr 2)) ;=> [2 3] | ||
|
||
``` | ||
|
||
## Clojure API Tutorials | ||
* [Module API is a flexible high-level interface for training neural networks.](module.html) | ||
* [Symbolic API performs operations on NDArrays to assemble neural networks from layers.](symbol.html) | ||
* [NDArray API performs vector/matrix/tensor operations.](ndarray.html) | ||
* [KVStore API performs multi-GPU and multi-host distributed training.](kvstore.html) | ||
|
||
|
||
## Related Resources | ||
* [MXNet Clojure API Documentation](docs/index.html) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# KVStore API | ||
|
||
Topics: | ||
|
||
* [Basic Push and Pull](#basic-push-and-pull) | ||
* [List Key-Value Pairs](#list-key-value-pairs) | ||
* [API Reference](http://mxnet.incubator.apache.org/api/clojure/docs/org.apache.clojure-mxnet.kvstore.html) | ||
|
||
To follow along with this documentation, you can use this namespace to with the needed requires: | ||
|
||
```clojure | ||
(ns docs.kvstore | ||
(:require [org.apache.clojure-mxnet.kvstore :as kvstore] | ||
[org.apache.clojure-mxnet.ndarray :as ndarray] | ||
[org.apache.clojure-mxnet.context :as context])) | ||
``` | ||
|
||
## Basic Push and Pull | ||
|
||
Provides basic operation over multiple devices (GPUs) on a single device. | ||
|
||
### Initialization | ||
|
||
Let's consider a simple example. It initializes | ||
a (`int`, `NDArray`) pair into the store, and then pulls the value out. | ||
|
||
```clojure | ||
(def kv (kvstore/create "local")) ;; create a local kvstore | ||
(def shape [2 3]) | ||
;;; init the kvstore with a vector of keys (strings) and ndarrays | ||
(kvstore/init kv ["3"] [(ndarray/* (ndarray/ones shape) 2)]) | ||
(def a (ndarray/zeros shape)) | ||
(kvstore/pull kv ["3"] [a]) | ||
(ndarray/->vec a) ;=> [2.0 2.0 2.0 2.0 2.0 2.0] | ||
``` | ||
|
||
### Push, Aggregation, and Updater | ||
|
||
For any key that's been initialized, you can push a new value with the same shape to the key, as follows: | ||
|
||
```clojure | ||
(kvstore/push kv ["3"] [(ndarray/* (ndarray/ones shape) 8)]) | ||
(kvstore/pull kv ["3"] [a]) | ||
(ndarray/->vec a);=>[8.0 8.0 8.0 8.0 8.0 8.0] | ||
``` | ||
|
||
The data that you want to push can be stored on any device. Furthermore, you can push multiple | ||
values into the same key, where KVStore first sums all of these | ||
values, and then pushes the aggregated value, as follows (Here we use multiple cpus): | ||
|
||
```clojure | ||
(def cpus [(context/cpu 0) (context/cpu 1) (context/cpu 2)]) | ||
(def b [(ndarray/ones shape {:ctx (nth cpus 0)}) | ||
(ndarray/ones shape {:ctx (nth cpus 1)}) | ||
(ndarray/ones shape {:ctx (nth cpus 2)})]) | ||
(kvstore/push kv ["3" "3" "3"] b) | ||
(kvstore/pull kv "3" a) | ||
(ndarray/->vec a) ;=> [3.0 3.0 3.0 3.0 3.0 3.0] | ||
``` | ||
|
||
|
||
### Pull | ||
|
||
You've already seen how to pull a single key-value pair. Similar to the way that you use the push command, you can | ||
pull the value into several devices with a single call. | ||
|
||
```clojure | ||
(def b [(ndarray/ones shape {:ctx (context/cpu 0)}) | ||
(ndarray/ones shape {:ctx (context/cpu 1)})]) | ||
(kvstore/pull kv ["3" "3"] b) | ||
(map ndarray/->vec b) ;=> ([3.0 3.0 3.0 3.0 3.0 3.0] [3.0 3.0 3.0 3.0 3.0 3.0]) | ||
``` | ||
|
||
## List Key-Value Pairs | ||
|
||
All of the operations that we've discussed so far are performed on a single key. KVStore also provides | ||
the interface for generating a list of key-value pairs. For a single device, use the following: | ||
|
||
```clojure | ||
(def ks ["5" "7" "9"]) | ||
(kvstore/init kv ks [(ndarray/ones shape) (ndarray/ones shape) (ndarray/ones shape)]) | ||
(kvstore/push kv ks [(ndarray/ones shape) (ndarray/ones shape) (ndarray/ones shape)]) | ||
(def b [(ndarray/zeros shape) (ndarray/zeros shape) (ndarray/zeros shape)]) | ||
(kvstore/pull kv ks b) | ||
(map ndarray/->vec b);=> ([1.0 1.0 1.0 1.0 1.0 1.0] [1.0 1.0 1.0 1.0 1.0 1.0] [1.0 1.0 1.0 1.0 1.0 1.0]) | ||
``` |
Oops, something went wrong.