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

Strided_slice 的异常行为 #43375

Closed
Kevin-XiongC opened this issue Jun 9, 2022 · 4 comments
Closed

Strided_slice 的异常行为 #43375

Kevin-XiongC opened this issue Jun 9, 2022 · 4 comments
Assignees
Labels
status/developed 开发完成 type/bug-fixed bug已修复

Comments

@Kevin-XiongC
Copy link

Kevin-XiongC commented Jun 9, 2022

bug描述 Describe the Bug

image

上图结果由以下script得到,其中出现了OoTA值0,而且对于shape为(2,)的tensor可以传入大于2的start end,请问各个参数的合理范围是多少?或者是在三者有-1时,Strided_slice行为是怎样?

print(paddle.strided_slice(paddle.to_tensor([28,29]),axes=[0],starts=[-1],ends=[9],strides=[1]))
print(paddle.strided_slice(paddle.to_tensor([28,29]),axes=[0],starts=[-1],ends=[-9],strides=[-1]))
print(paddle.strided_slice(paddle.to_tensor([28,29]),axes=[0],starts=[321312],ends=[-1],strides=[-1]))

其他补充信息 Additional Supplementary Information

paddle 2.2 or 2.3
mac x86
python3.7

@paddle-bot-old
Copy link

paddle-bot-old bot commented Jun 9, 2022

您好,我们已经收到了您的问题,会安排技术人员尽快解答您的问题,请耐心等待。请您再次检查是否提供了清晰的问题描述、复现代码、环境&版本、报错信息等。同时,您也可以通过查看官网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!

@zyfncg
Copy link
Contributor

zyfncg commented Jun 10, 2022

你好,感谢反馈!经过排查stride_slice的参数为负数时确实存在一些问题。starts和ends参数的合理范围应该在[-shape_size, shape_size],在这个范围内设置参数值应该是没有问题的,这也是我们推荐的用法。但为了写起来更简单stride_slice也允许输入的参数超过这个范围:如果start和end的值大于对应维度的size,在处理时会将其设置为维度的size值;如果start和end的值小于0,会先加上shape_size,如果加完之后仍小于0则按0处理(stride小于0并且end为-1时除外,此时由于要从后往前选择到第0个元素,所以end需要为-1)。
所以脚本中的第一和第三个示例等价于:

print(paddle.strided_slice(paddle.to_tensor([28,29]),axes=[0],starts=[1],ends=[2],strides=[1]))
print(paddle.strided_slice(paddle.to_tensor([28,29]),axes=[0],starts=[1],ends=[-1],strides=[-1]))

第二个示例由于end值-9+2=-7仍小于0,所以需要按0处理,因此正确的结果应该是等价于:

print(paddle.strided_slice(paddle.to_tensor([28,29]),axes=[0],starts=[1],ends=[0],strides=[-1]))
#Tensor(shape=[1], dtype=int64, place=Place(gpu:0), stop_gradient=True,
#            [29])

@Kevin-XiongC
Copy link
Author

Kevin-XiongC commented Jun 17, 2022

strided_slice和set_value 这两个我理解索引逻辑应该一样的op,貌似实际处理时也不一样?如下图所示,同一个slice参数,strided_slice读了三个entry,但是set_value改写了四个entry,按照『如果start和end的值小于0,会先加上shape_size』这个逻辑ends+4会变成0,因为是左闭右开区间[3,0),所以被修改的应该只有3,2,1三个索引?

看起来set_value的逻辑像是在stride小于0时和end<0时,就是取到0的闭区间?
image

@paddle-bot-old
Copy link

Since you haven't replied for more than a year, we have closed this issue/pr.
If the problem is not solved or there is a follow-up one, please reopen it at any time and we will continue to follow up.
由于您超过一年未回复,我们将关闭这个issue/pr。
若问题未解决或有后续问题,请随时重新打开,我们会继续跟进。

@Ligoml Ligoml added the status/developed 开发完成 label Jun 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/developed 开发完成 type/bug-fixed bug已修复
Projects
None yet
Development

No branches or pull requests

4 participants