Skip to content

Commit

Permalink
ndarray: porting Python's autograd (#274)
Browse files Browse the repository at this point in the history
Ref: https://github.com/apache/incubator-mxnet/blob/065adb3702c110af7b537799be3ec9c16c27a72b/python/mxnet/autograd.py

* API ported
    * attach_grad
    * grad
    * mark_variables
    * get_symbol
    * record
    * pause
    * train_mode
    * predict_mode
    * backward

* An example

```julia
x = NDArray([1 2; 3 4])
mx.attach_grad!(x)

y = mx.record() do
  mx.square(x)
end

mx.backward!(y)

mx.getgrad(x)
 # 2×2 Array{Int64,2}:
 # 2  4
 # 6  8
```
  • Loading branch information
iblislin authored Dec 18, 2017
1 parent 39ecb32 commit cb443b7
Show file tree
Hide file tree
Showing 7 changed files with 780 additions and 4 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@

### `NDArray`

* A port of Python's `autograd` for `NDArray` (#274)

* `size(x, dims...)` is supported now. (#TBD)

```julia
Expand Down
1 change: 1 addition & 0 deletions src/MXNet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ include("broadcast.jl")

include("ndarray.jl")
include("random.jl")
include("autograd.jl")

include("name.jl")
include("symbolic-node.jl")
Expand Down
Loading

0 comments on commit cb443b7

Please sign in to comment.