Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 446F2200BD4 for ; Fri, 16 Dec 2016 14:42:34 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 431A0160B24; Fri, 16 Dec 2016 13:42:34 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 88250160AF6 for ; Fri, 16 Dec 2016 14:42:33 +0100 (CET) Received: (qmail 75045 invoked by uid 500); 16 Dec 2016 13:42:32 -0000 Mailing-List: contact commits-help@singa.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@singa.incubator.apache.org Delivered-To: mailing list commits@singa.incubator.apache.org Received: (qmail 75036 invoked by uid 99); 16 Dec 2016 13:42:32 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 16 Dec 2016 13:42:32 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 53EDB1A8C2C for ; Fri, 16 Dec 2016 13:42:32 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -6.219 X-Spam-Level: X-Spam-Status: No, score=-6.219 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-2.999] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id 6tx67Ham_n3v for ; Fri, 16 Dec 2016 13:42:28 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id D75B45FB7F for ; Fri, 16 Dec 2016 13:42:27 +0000 (UTC) Received: (qmail 75009 invoked by uid 99); 16 Dec 2016 13:42:27 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 16 Dec 2016 13:42:27 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id DAC57DFCE0; Fri, 16 Dec 2016 13:42:26 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: zhaojing@apache.org To: commits@singa.incubator.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: incubator-singa git commit: SINGA-283 Fix a bug of net.py backward function for layers with multiple inputs Date: Fri, 16 Dec 2016 13:42:26 +0000 (UTC) archived-at: Fri, 16 Dec 2016 13:42:34 -0000 Repository: incubator-singa Updated Branches: refs/heads/master a43f2912b -> 7956019cf SINGA-283 Fix a bug of net.py backward function for layers with multiple inputs 1. reversed(list) returns a reversedlistiterator, it should return a list. fixed by using list[::-1] 2. add debugging output for backward function Project: http://git-wip-us.apache.org/repos/asf/incubator-singa/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-singa/commit/7956019c Tree: http://git-wip-us.apache.org/repos/asf/incubator-singa/tree/7956019c Diff: http://git-wip-us.apache.org/repos/asf/incubator-singa/diff/7956019c Branch: refs/heads/master Commit: 7956019cf326c5f84401551f31f1e597fba77d46 Parents: a43f291 Author: Wei Wang Authored: Fri Dec 16 15:52:03 2016 +0800 Committer: Wei Wang Committed: Fri Dec 16 15:52:03 2016 +0800 ---------------------------------------------------------------------- python/singa/layer.py | 9 ++++++--- python/singa/net.py | 11 ++++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/7956019c/python/singa/layer.py ---------------------------------------------------------------------- diff --git a/python/singa/layer.py b/python/singa/layer.py index f82d2df..a9f6a3b 100644 --- a/python/singa/layer.py +++ b/python/singa/layer.py @@ -206,7 +206,8 @@ class Layer(object): y = self.layer.ForwardWithMultInputs(flag, xs) else: assert isinstance(x, tensor.Tensor), \ - 'input must be a Tensor or a list of Tensor' + 'input of %s (type:%s) must be a Tensor or Tensor list'\ + % (self.name, type(x).__name__) y = self.layer.Forward(flag, x.singa_tensor) if type(y) is tuple: return tensor.from_raw_tensors(y) @@ -235,7 +236,8 @@ class Layer(object): ret = self.layer.BackwardWithMultInputs(flag, dys) else: assert isinstance(dy, tensor.Tensor), \ - 'the input must be a Tensor or a set of Tensor' + 'input of %s (type:%s) must be a Tensor or Tensor list'\ + % (self.name, type(dy).__name__) dys = dy.singa_tensor ret = self.layer.Backward(flag, dys) if type(ret[0]) is tuple: @@ -761,7 +763,8 @@ class Merge(Layer): Returns: A list of replicated grad, one per source layer ''' - assert isinstance(grad, tensor.Tensor), 'The input must be Tensor' + assert isinstance(grad, tensor.Tensor), 'The input must be Tensor'\ + ' instead of %s' % type(grad).__name__ return [grad] * self.num_input, [] # * self.num_input http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/7956019c/python/singa/net.py ---------------------------------------------------------------------- diff --git a/python/singa/net.py b/python/singa/net.py index b6f973d..36c70f8 100644 --- a/python/singa/net.py +++ b/python/singa/net.py @@ -301,8 +301,17 @@ class FeedForwardNet(object): grads = grads[0] outs, _pgrads = cur.backward(kTrain, grads) pgrads.append(_pgrads) + if verbose: + disp_src = '+'.join( + [dst.name for dst in self.dst_of_layer[cur.name]]) + disp_src += '-->' + cur.name + if type(outs) is list: + print '%s: %s' % (disp_src, + ' '.join([str(o.l1()) for o in outs])) + else: + print '%s: %f' % (disp_src, outs.l1()) if type(outs) is list: - output_of_layer[cur.name] = reversed(outs) + output_of_layer[cur.name] = outs[::-1] else: output_of_layer[cur.name] = outs grads = []