Created by: zhiqiu
PR types
Bug fixes
PR changes
APIs
Describe
paddle.stack does not support a single Tensor as input anymore.
Before this PR, paddle.stack
accepts a single Tensor x
as input, and implicitly convert it to a list of Tensor [x]
.
This is not a good design since it violates the single responsibility. The responsibility of stack is to stack several Tensors, so this PR prohibits that usage.
An Exception, input as Variable of LOD_Tensor_Array
type in static graph is still ok, since it means array of tensors
.
For example, the following code will result in an error.
import paddle
paddle.disable_static()
x1 = paddle.rand([2,2])
result = paddle.stack(x1, axis=0)
- dygraph
Traceback (most recent call last):
File "test_stack.py", line 8, in <module>
result = paddle.stack(x1, axis=0)
File "/usr/local/lib/python3.5/dist-packages/paddle/tensor/manipulation.py", line 468, in stack
return layers.stack(x, axis, name)
File "/usr/local/lib/python3.5/dist-packages/paddle/fluid/layers/nn.py", line 10055, in stack
return core.ops.stack(x, 'axis', axis)
paddle.fluid.core_avx.EnforceNotMet:
--------------------------------------
C++ Traceback (most recent call last):
--------------------------------------
0 paddle::platform::EnforceNotMet::EnforceNotMet(paddle::platform::ErrorSummary const&, char const*, int)
1 paddle::platform::GetCurrentTraceBackString[abi:cxx11]()
----------------------
Error Message Summary:
----------------------
InvalidArgumentError: stack(): argument 'X' (position 0) must be list of Tensors, but got Tensor (at /Paddle/Paddle/paddle/fluid/pybind/op_function.h:88)
- static graph
Traceback (most recent call last):
File "test_stack.py", line 8, in <module>
result = paddle.stack(x1, axis=0)
File "/usr/local/lib/python3.5/dist-packages/paddle/tensor/manipulation.py", line 468, in stack
return layers.stack(x, axis, name)
File "/usr/local/lib/python3.5/dist-packages/paddle/fluid/layers/nn.py", line 10058, in stack
raise TypeError("The type of '%s' in %s must be %s, but received %s" % ( 'x', 'stack', 'list[Tensor] or tuple[Tensor]', type(x)))
TypeError: The type of 'x' in stack must be list[Tensor] or tuple[Tensor], but received <class 'paddle.fluid.framework.Variable'>