Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refine paddle.stack #25305

Merged
merged 8 commits into from
Aug 6, 2020
Merged

Conversation

zhiqiu
Copy link
Contributor

@zhiqiu zhiqiu commented Jul 1, 2020

PR types

Function optimization

PR changes

APIs

Describe

Refine paddle.stack API

  • Variable -> Tensor
  • use core.ops.stack in dygraph mode
  • refine document
  • fluid.layers.stack(x, axis=0) -> fluid.layers.stack(x, axis=0, name=None), which is compatible upgrade.
  • reuse code of fluid.layers.stack

@zhiqiu zhiqiu changed the title refine stack in dygraph mode, test=develop refine stack Jul 28, 2020
@@ -243,65 +248,39 @@ def stack(x, axis=0, out=None, name=None):
[5.0, 6.0] ] ]

Args:
x (Variable|list(Variable)): Input :code:`x` can be a single Tensor, a :code:`list` of Tensors.
x (Tensor|list(Tensor)): Input :code:`x` can be a single Tensor, a :code:`list` of Tensors.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
x (Tensor|list(Tensor)): Input :code:`x` can be a single Tensor, a :code:`list` of Tensors.
x (Tensor|list(Tensor)): Input :code:`x` can be a single Tensor, or a :code:`list` of Tensors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks.

@@ -243,65 +248,39 @@ def stack(x, axis=0, out=None, name=None):
[5.0, 6.0] ] ]

Args:
x (Variable|list(Variable)): Input :code:`x` can be a single Tensor, a :code:`list` of Tensors.
x (Tensor|list(Tensor)): Input :code:`x` can be a single Tensor, a :code:`list` of Tensors.
If :code:`x` is a :code:`list`, the shapes of all these Tensors
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为啥这个文档里都是“:code:x”这样的写法,其他文档都是“ x ”的写法?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

两种语法,网页展示的结果应该是一样的。



This OP stacks all the inputs :code:`x` along axis.
This OP stacks all the input tensors :code:`x` along :code:`axis` dimemsion.
All tensors should to be of the same shape.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dtype是否要求相同?代码里有相关检查和处理吗?

Copy link
Contributor Author

@zhiqiu zhiqiu Aug 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

要求相同的dtype,c++代码中会做check和报错。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InvalidArgumentError: The DataType of stack Op's duplicable Variable X must be consistent. The current variable type is (double), but the previous variable type is (float). at (/paddle/paddle/fluid/framework/operator.cc:1298)

@@ -243,65 +248,39 @@ def stack(x, axis=0, out=None, name=None):
[5.0, 6.0] ] ]

Args:
x (Variable|list(Variable)): Input :code:`x` can be a single Tensor, a :code:`list` of Tensors.
x (Tensor|list(Tensor)): Input :code:`x` can be a single Tensor, a :code:`list` of Tensors.
If :code:`x` is a :code:`list`, the shapes of all these Tensors
must be the same. Supposing input is N dims
Tensors :math:`[d_0, d_1, ..., d_{n-1}]`, the output is N+1 dims
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没有文档预览图,看起来太费劲了

@@ -243,65 +248,39 @@ def stack(x, axis=0, out=None, name=None):
[5.0, 6.0] ] ]

Args:
x (Variable|list(Variable)): Input :code:`x` can be a single Tensor, a :code:`list` of Tensors.
x (Tensor|list(Tensor)): Input :code:`x` can be a single Tensor, a :code:`list` of Tensors.
If :code:`x` is a :code:`list`, the shapes of all these Tensors
must be the same. Supposing input is N dims
Tensors :math:`[d_0, d_1, ..., d_{n-1}]`, the output is N+1 dims
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

语法有问题

If :code:`x` is a :code:`list`, the shapes of all these Tensors
must be the same. Supposing input is N dims
Tensors :math:`[d_0, d_1, ..., d_{n-1}]`, the output is N+1 dims
Tensor :math:`[d_0, d_1, d_{axis-1}, len(x), d_{axis}, ..., d_{n-1}]`.
Support data types: float32, float64, int32, int64.
axis (int, optional): The axis along which all inputs are stacked. ``axis`` range is :math:`[-(R+1), R+1)`.
R is the first tensor of inputs. If ``axis`` < 0, :math:`axis=axis+rank(x[0])+1`.
R is the first tensor of inputs. If ``axis`` < 0, :math:`axis = axis+ndim(x[0])+1`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

R的定义没有说清楚

Copy link
Contributor Author

@zhiqiu zhiqiu Aug 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改, R is the number of dimensions of the first input tensor :code:x[0].

# result shape: [3, 1, 2]
# result value: [[[1.0, 2.0]],
# [[3.0, 4.0]],
# [[5.0, 6.0]]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

缺少axis为负数时的例子,并应该详细说明负数情况下是如何起作用的

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

case 2中axis是负数。

# [[3.0, 4.0]],
# [[5.0, 6.0]]]
"""
return layers.stack(x, axis, name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

报错信息怎么处理的?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

paddle.stack复用了layer.stack的报错信息

@zhiqiu
Copy link
Contributor Author

zhiqiu commented Aug 5, 2020

image

lanxianghit
lanxianghit previously approved these changes Aug 6, 2020
Copy link
Contributor

@lanxianghit lanxianghit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

paddle.enable_imperative()
x1 = fluid.dygraph.to_variable(data1)
x2 = fluid.dygraph.to_variable(data2)
x3 = fluid.dygraph.to_variable(data3)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use paddle.imperative.to_variable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, thanks

@zhiqiu zhiqiu changed the title refine stack refine paddle.stack Aug 6, 2020
Copy link
Contributor

@jzhang533 jzhang533 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@zhiqiu zhiqiu merged commit 6e7f0bb into PaddlePaddle:develop Aug 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants