From e92d113590f7a94e536d80416bcb89be151c7fda Mon Sep 17 00:00:00 2001 From: zhouwei25 <52485244+zhouwei25@users.noreply.github.com> Date: Mon, 16 Dec 2019 14:05:57 +0800 Subject: [PATCH] fix bug that tuple(Variable) is converted to list(Variable) uncorrectly (#21687) --- python/paddle/fluid/framework.py | 4 ++-- python/paddle/fluid/layers/nn.py | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/python/paddle/fluid/framework.py b/python/paddle/fluid/framework.py index f54ceb62c8..10b92bdb7b 100644 --- a/python/paddle/fluid/framework.py +++ b/python/paddle/fluid/framework.py @@ -1814,8 +1814,8 @@ class Operator(object): "The type of '%s' in operator %s should be " "one of [basestring(), str, Varibale] in python2, " "or one of [str, bytes, Variable] in python3." - "but received : " % (in_proto.name, type), - arg) + "but received : %s" % + (in_proto.name, type, arg)) self.desc.set_input(in_proto.name, in_arg_names) else: self.desc.set_input(in_proto.name, []) diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index 879ef5f8e7..47be0690f7 100644 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -12280,16 +12280,18 @@ def py_func(func, x, out, backward_func=None, skip_vars_in_backward_input=None): x = [] elif isinstance(x, Variable): x = [x] - elif not isinstance(x, (list, tuple)): + elif isinstance(x, tuple): + x = list(x) + elif not isinstance(x, (list, tuple, Variable)): raise TypeError('Input must be Variable/list(Variable)/tuple(Variable)') if out is None: out_list = [] elif isinstance(out, Variable): out_list = [out] - elif isinstance(out, (list, tuple)): - out_list = out - else: + elif isinstance(out, tuple): + out_list = list(out) + elif not isinstance(x, (list, tuple, Variable)): raise TypeError( 'Output must be Variable/list(Variable)/tuple(Variable)') -- GitLab