-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
[Hackthon 4th No.7] add paddle.unflatten API #53055
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
你好 @zoooo0820,对于 RFC 中提到的 不过,相对于 |
@Ainavo 你好, |
你好@zoooo0820, |
收到 |
这里可以先暂时不加,如果要加的话还涉及到补单测等工作,工作重心可能偏离。数据类型支持后续由对应专项工作去补充。目前可以测试已经支持的数据类型。 |
好的 |
|
另外一个 pr 先将 shape 输入为 paddle.Tensor 的数据类型使用 |
@zoooo0820 你好,ci 已过,有时间可以 review 一下吗? |
https://aistudio.baidu.com/aistudio/competition/detail/776/0/introduction 请 cos43 review 下这个PR,同时关注下上述规则(by 2023年4月25日)。 |
可以请 @cos43 review 一下吗~ |
python/paddle/tensor/manipulation.py
Outdated
if axis < 0: | ||
axis = axis + length | ||
new_shape = ( | ||
tuple(x.shape[:axis]) + tuple(shape) + tuple(x.shape[axis + 1 :]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
支持shape
为Tensor,本质上不是单纯为了增加一个支持的数据类型,而是Tensor是一个未知的数据(例如shape
是需要由前面某个OP计算出来)。
在静态图下,在组网构图阶段,是不能利用Tensor内的实际数值的,所以对于静态图而言,new_shape
这样先转tuple再组合起来的方案是不适用的。这个地方,尽量保证new_shape
始终由tensor计算得到,并仍然作为一个tensor给到reshape
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
支持
shape
为Tensor,本质上不是单纯为了增加一个支持的数据类型,而是Tensor是一个未知的数据(例如shape
是需要由前面某个OP计算出来)。在静态图下,在组网构图阶段,是不能利用Tensor内的实际数值的,所以对于静态图而言,
new_shape
这样先转tuple再组合起来的方案是不适用的。这个地方,尽量保证new_shape
始终由tensor计算得到,并仍然作为一个tensor给到reshape
目前,先使用 paddle.shape
获取为 Tensor 数据的 shape
,然后通过 paddle.concat
进行张量连接,由于 paddle.shape
返回的数据类型是 int32
,因此在 shape
输入时,添加了 int32
的数据类型检查。同时 paddle.reshape
在文档中提到 shape
参数的类型为 int32
(不过 int64
也可以正常输入)。
@zoooo0820 已按照建议进行修改,其中 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Sorry to inform you that 7494a65's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unflatten也同步进行修改
Parameters: | ||
shape (list|tuple|Tensor): Unflatten :attr:`shape` on the specified :attr:`axis`. At most one dimension of the target :attr:`shape` can be -1. | ||
If the input :attr:`shape` does not contain -1 , the product should be equal to ``x.shape[axis]`` size. | ||
The data type is `int` . If :attr:`shape` is a list or tuple, the elements of it should be integers or Tensors with shape []. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zoooo0820 麻烦判断下Tensors with shape []
描述是否准确?感觉 形状为[]的tensor 很难界定
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zoooo0820 麻烦判断下
Tensors with shape []
描述是否准确?感觉 形状为[]的tensor 很难界定
补充:这里是参考了 paddle.reshape 的文档
Paddle/python/paddle/tensor/manipulation.py
Line 3526 in b6c0407
The data type is ``int32`` . If ``shape`` is a list or tuple, the elements of it should be integers or Tensors with shape []. |
感觉这里想表达的意思是 元素为 Tensor 的 list 或 tuple
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zoooo0820 麻烦判断下
Tensors with shape []
描述是否准确?感觉 形状为[]的tensor 很难界定补充:这里是参考了 paddle.reshape 的文档
Paddle/python/paddle/tensor/manipulation.py
Line 3526 in b6c0407
The data type is ``int32`` . If ``shape`` is a list or tuple, the elements of it should be integers or Tensors with shape [].
和内部研发同学问了下,形状为[]的tensor为意思是 0维tensor,应该符合描述
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zoooo0820 麻烦判断下
Tensors with shape []
描述是否准确?感觉 形状为[]的tensor 很难界定补充:这里是参考了 paddle.reshape 的文档
Paddle/python/paddle/tensor/manipulation.py
Line 3526 in b6c0407
The data type is ``int32`` . If ``shape`` is a list or tuple, the elements of it should be integers or Tensors with shape []. 和内部研发同学问了下,形状为[]的tensor为意思是 0维tensor,应该符合描述
好的,学到了~
python/paddle/tensor/manipulation.py
Outdated
@@ -4787,6 +4787,75 @@ def index_add_(x, index, axis, value, name=None): | |||
return _C_ops.index_add_(x, index, value, axis) | |||
|
|||
|
|||
def unflatten(x, shape, axis, name=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
对应竞品的API,从复现模型的易用角度出发,这里以及Unflatten类中的shape, axis的前后顺序可调整下,对应RFC也辛苦修改一下呢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
对应竞品的API,从复现模型的易用角度出发,这里以及Unflatten类中的shape, axis的前后顺序可调整下,对应RFC也辛苦修改一下呢
好的
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
对应竞品的API,从复现模型的易用角度出发,这里以及Unflatten类中的shape, axis的前后顺序可调整下,对应RFC也辛苦修改一下呢
修改后的 RFC 链接:
主要修改参数顺序及参数说明,另外删除一些单测中的错误检测
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
PR types
New features
PR changes
APIs
Description
add api for unflatten
中文文档链接:
修改后的 RFC 链接: