You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@singa.apache.org by wa...@apache.org on 2017/06/05 13:50:18 UTC

incubator-singa git commit: Average gradients otherwise loss overflows

Repository: incubator-singa
Updated Branches:
  refs/heads/master cd485a7ae -> 07ef01f71


Average gradients otherwise loss overflows


Project: http://git-wip-us.apache.org/repos/asf/incubator-singa/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-singa/commit/07ef01f7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-singa/tree/07ef01f7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-singa/diff/07ef01f7

Branch: refs/heads/master
Commit: 07ef01f71bb49423baf037491f83afa684a86cec
Parents: cd485a7
Author: jedshady <mi...@163.com>
Authored: Mon Jun 5 19:43:52 2017 +0800
Committer: jedshady <mi...@163.com>
Committed: Mon Jun 5 19:43:52 2017 +0800

----------------------------------------------------------------------
 python/singa/net.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/07ef01f7/python/singa/net.py
----------------------------------------------------------------------
diff --git a/python/singa/net.py b/python/singa/net.py
index 26b7463..82933e1 100644
--- a/python/singa/net.py
+++ b/python/singa/net.py
@@ -182,12 +182,13 @@ class FeedForwardNet(object):
         out = self.forward(kTrain, x)
         l = self.loss.forward(kTrain, out, y)
         g = self.loss.backward()
+        g /= x.shape[0]
         m = None
         if self.metric is not None:
             m = self.metric.evaluate(out, y)
         grads = []  # store all gradient tensors; memory inefficient
         for _, _, grad, _ in self.backward(g):
-            grads.extend(grad)
+            grads.extend(grad[::-1])
         return grads[::-1], (l.l1(), m)
 
     def evaluate(self, x, y):