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

长度为 1 的 Tensor 无法用 bool 取值 #36940

Closed
yt605155624 opened this issue Nov 2, 2021 · 4 comments
Closed

长度为 1 的 Tensor 无法用 bool 取值 #36940

yt605155624 opened this issue Nov 2, 2021 · 4 comments
Assignees

Comments

@yt605155624
Copy link
Contributor

>>> import paddle
>>> y = paddle.to_tensor([1,2])
>>> temp = paddle.to_tensor([True,False])
>>> y[temp]
Tensor(shape=[1], dtype=int64, place=CUDAPlace(0), stop_gradient=True,
       [1])
>>> y = paddle.to_tensor([1])
>>> temp = paddle.to_tensor([True])
>>> y[temp]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/yuantian01/yt_py37/lib/python3.7/site-packages/paddle/fluid/dygraph/varbase_patch_methods.py", line 594, in __getitem__
    return _getitem_impl_(self, item)
  File "/home/yuantian01/yt_py37/lib/python3.7/site-packages/paddle/fluid/variable_index.py", line 463, in _getitem_impl_
    attrs=attrs)
  File "/home/yuantian01/yt_py37/lib/python3.7/site-packages/paddle/fluid/framework.py", line 3249, in append_op
    kwargs.get("stop_gradient", False))
  File "/home/yuantian01/yt_py37/lib/python3.7/site-packages/paddle/fluid/dygraph/tracer.py", line 45, in trace_op
    not stop_gradient)
ValueError: (InvalidArgument) The dtype of Tensor in list must be int32 or int64, but received: 0 (at /paddle/paddle/fluid/operators/utils.h:85)
  [operator < slice > error]
@paddle-bot-old
Copy link

paddle-bot-old bot commented Nov 2, 2021

您好,我们已经收到了您的问题,会安排技术人员尽快解答您的问题,请耐心等待。请您再次检查是否提供了清晰的问题描述、复现代码、环境&版本、报错信息等。同时,您也可以通过查看官网API文档常见问题历史IssueAI社区来寻求解答。祝您生活愉快~

Hi! We've received your issue and please be patient to get responded. We will arrange technicians to answer your questions as soon as possible. Please make sure that you have posted enough message to demo your request. You may also check out the APIFAQGithub Issue and AI community to get the answer.Have a nice day!

@FeixLiu
Copy link
Contributor

FeixLiu commented Nov 2, 2021

对于temp的shape为[1]的时候,框架认为该variable是int/scalar,走了与shape不为1时不同的代码逻辑。是否会更新该逻辑使之支持您列出的问题,我们内部会安排评估,未来有计划尽快回复。

@CuberrChen
Copy link

@FeixLiu
请问这个问题有没有暂时的解决办法?我也遇到了相同的问题

@FeixLiu
Copy link
Contributor

FeixLiu commented Feb 17, 2022

感谢您的反馈~这里的问题我们在最新的develop代码分支里已经支持#37761 预计在后续的正式版本中发布。
如果赶时间的话可以直接拉取最新的develop分支代码编译进行使用,编译流程可以参考这里https://www.paddlepaddle.org.cn/documentation/docs/zh/install/compile/linux-compile.html

@FeixLiu FeixLiu closed this as completed Feb 17, 2022
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

No branches or pull requests

3 participants