CARVIEW |
Navigation Menu
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
修复atleast函数中,”输入为tensor的list,输出不是tensor的list“的bug #73102
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
Conversation
modified: python/paddle/tensor/manipulation.py modified: test/legacy_test/test_atleast_xd.py
你的PR提交成功,感谢你对开源项目的贡献! |
Codecov ReportAttention: Patch coverage is
❌ Your patch status has failed because the patch coverage (0.00%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## develop #73102 +/- ##
==========================================
Coverage ? 0.00%
==========================================
Files ? 1
Lines ? 9
Branches ? 0
==========================================
Hits ? 0
Misses ? 9
Partials ? 0 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
CI: https://xly.bce.baidu.com/paddlepaddle/paddle/newipipe/detail/12905852/job/29455975 if len(inputs) == 1 and isinstance(inputs[0], list):
if all(
isinstance(
item,
(
paddle.Tensor,
paddle.base.framework.Variable,
paddle.base.libpaddle.pir.Value,
),
)
for item in inputs[0]
):
inputs = inputs[0]
print("in atleast_1d inputs:", inputs) in atleast_1d inputs: [Tensor(shape=[], dtype=int32, place=Place(cpu), stop_gradient=True,
123), Tensor(shape=[3], dtype=float32, place=Place(cpu), stop_gradient=True,
[1., 2., 3.]), Tensor(shape=[2, 2], dtype=int64, place=Place(cpu), stop_gradient=True,
[[1, 2],
[3, 4]])]
in atleast_2d inputs: [Tensor(shape=[], dtype=int32, place=Place(cpu), stop_gradient=True,
123), Tensor(shape=[3], dtype=float32, place=Place(cpu), stop_gradient=True,
[1., 2., 3.]), Tensor(shape=[2, 2], dtype=int64, place=Place(cpu), stop_gradient=True,
[[1, 2],
[3, 4]])]
in atleast_3d inputs: [Tensor(shape=[], dtype=int32, place=Place(cpu), stop_gradient=True,
123), Tensor(shape=[3], dtype=float32, place=Place(cpu), stop_gradient=True,
[1., 2., 3.]), Tensor(shape=[2, 2], dtype=int64, place=Place(cpu), stop_gradient=True,
[[1, 2],
[3, 4]])] |
PR-CI-Coverage |
python/paddle/tensor/manipulation.py
Outdated
@@ -5277,6 +5277,20 @@ def atleast_1d(*inputs, name=None): | |||
[123]), Tensor(shape=[1, 1], dtype=float32, place=Place(cpu), stop_gradient=True, | |||
[[1.23000002]])] | |||
""" | |||
if len(inputs) == 1 and isinstance(inputs[0], list): |
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.
if len(inputs) == 1 and isinstance(inputs[0], (list, tuple)):
inputs = inputs[0]
不用判断list里是什么
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.
您好,请问是指不用判断list里面是不是paddle.tensor吗?因为好像原本的测试中有list包含list的情况,所以不判断的话测试无法通过。
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.
具体是哪个case呢?
list包含list情况按这么写,应该也没问题吧?
if len(inputs) == 1 and isinstance(inputs[0], (list, tuple)):
inputs = inputs[0]
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.
import numpy as np
import paddle
import torch
# inputs = ([[[137]]],)
inputs = [[[[137]]]]
print("Inputs:", inputs)
print("type Inputs:", type(inputs))
print("type Inputs[0]:", type(inputs[0]))
result = paddle.atleast_1d(*inputs)
print("Result:", type(result))
print("Result:", result)
# result_pt = torch.atleast_1d(*inputs)
# print("Result_pt:", type(result_pt))
# print("Result_pt:", result_pt)
Inputs: [[[[137]]]]
type Inputs: <class 'list'>
type Inputs[0]: <class 'list'>
len(out) == 1
Result: <class 'paddle.Tensor'>
Result: Tensor(shape=[1, 1, 1], dtype=int64, place=Place(gpu:0), stop_gradient=True,
[[[137]]])
对于上面这个例子,paddle会将[[[[137]]]]的list改为[[[137]]]的tensor。pytorch应该不支持这个输入。
如果按照下面的方式写的话,paddle会将[[[[137]]]]的list改为[[137]]的tensor。会比之前少一个维度。
if len(inputs) == 1 and isinstance(inputs[0], (list, tuple)):
inputs = inputs[0]
Inputs: [[[[137]]]]
type Inputs: <class 'list'>
type Inputs[0]: <class 'list'>
len(out) == 1
Result: <class 'paddle.Tensor'>
Result: Tensor(shape=[1, 1], dtype=int64, place=Place(gpu:0), stop_gradient=True,
[[137]])
python/paddle/tensor/manipulation.py
Outdated
@@ -5277,6 +5277,20 @@ def atleast_1d(*inputs, name=None): | |||
[123]), Tensor(shape=[1, 1], dtype=float32, place=Place(cpu), stop_gradient=True, | |||
[[1.23000002]])] | |||
""" | |||
if len(inputs) == 1 and isinstance(inputs[0], list): | |||
if all( |
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.
这里改成any,规则是:如果有任意一个Tensor,就可以按list来分解,如果全部为子list,就不用分解。
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.
嗯,收到,已修改
python/paddle/tensor/manipulation.py
Outdated
@@ -5277,6 +5277,20 @@ def atleast_1d(*inputs, name=None): | |||
[123]), Tensor(shape=[1, 1], dtype=float32, place=Place(cpu), stop_gradient=True, | |||
[[1.23000002]])] | |||
""" | |||
if len(inputs) == 1 and isinstance(inputs[0], list): |
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.
这里改成 isinstance(inputs[0], (list, tuple)):
覆盖 输入一个tuple(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.
嗯,收到,已修改
modified: python/paddle/tensor/manipulation.py
CI还是有同样的问题,测试的代码应该可以覆盖 |
class TestAtleastWithTensorList(unittest.TestCase): | ||
"""Test when input is a list of paddle tensors""" | ||
|
||
def test_tensor_list_input(self): |
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.
再加几个case,分别是 list包含list、Tensor list、tuple包含tuple、Tensor tuple,目前只有第二种Tensor list
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.
嗯,收到,已添加
modified: test/legacy_test/test_atleast_xd.py
modified: test/legacy_test/test_atleast_xd.py
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
@Qin-sx 看下这个CE-Framework为何失败,是否有不兼容问题 |
嗯,我重新执行通过了,应该是偶发的。我记得之前提交的版本应该都是通过的。 |
PR Category
User Experience
PR Types
Bug fixes
Description
当前问题
当输入为tensor的list时,输出为tensor
解决方案
当输入为tensor的list时,进行判断,现在输出也为tensor的list