You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2017/12/13 03:11:57 UTC

[GitHub] piiswrong closed pull request #9039: update autograd.Function docstring for usage

piiswrong closed pull request #9039: update autograd.Function docstring for usage
URL: https://github.com/apache/incubator-mxnet/pull/9039
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/python/mxnet/autograd.py b/python/mxnet/autograd.py
index 340a9e66f4..cc9cad86da 100644
--- a/python/mxnet/autograd.py
+++ b/python/mxnet/autograd.py
@@ -372,7 +372,7 @@ class Function(object):
 
     For example, a stable sigmoid function can be defined as::
 
-        class sigmoid(Function):
+        class sigmoid(mx.autograd.Function):
             def forward(self, x):
                 y = 1 / (1 + mx.nd.exp(-x))
                 self.save_for_backward(y)
@@ -383,6 +383,18 @@ def backward(self, dy):
                 # and returns as many NDArrays as forward's arguments.
                 y, = self.saved_tensors
                 return y * (1-y)
+
+    Then, the function can be used in the following way::
+
+        func = sigmoid()
+        x = mx.nd.random.uniform(shape=(10,))
+        x.attach_grad()
+
+        with mx.autograd.record():
+            m = func(x)
+            m.backward()
+        dx = x.grad.asnumpy()
+
     """
     _bwd_functype = CFUNCTYPE(c_int, c_int, c_int, POINTER(c_void_p),
                               POINTER(c_int), c_int, c_void_p)


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services