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

[zero-dim] hack 1-D tensor to Scalar #53552

Merged
merged 1 commit into from
May 8, 2023

Conversation

zoooo0820
Copy link
Contributor

@zoooo0820 zoooo0820 commented May 6, 2023

PR types

Others

PR changes

APIs

Description

Pcard-66985

This is a following of #53358 . For 1-D index Tensor, this PR hack it to a Scalar, not Vector. This may cause difference of results.

>>> a = paddle.randn((2,3,4))
>>> index_0d = paddle.to_tensor(1)
>>> a[index_0d].shape
[3, 4]

>>> index_1d = paddle.to_tensor([1])

# with FLAGS_set_to_1d=True (Default)
>>> a[index_1d].shape    # In this case, is same as 0-d Tensor
/usr/local/lib/python3.8/dist-packages/paddle/fluid/variable_index.py:291: UserWarning: 1-D Tensor will be treat as advanced indexing in future version. Currently, 1-D Tensor means a scalar, not vector, and please modify it to 0-D Tensor.If advanced indexing is needed, please use `export FLAGS_set_to_1d=False` to set the flag.
  warnings.warn(
[3, 4]

# with FLAGS_set_to_1d=False
>>> a[index_1d].shape   # In this case, is different with 0-d Tensor.
[1, 3, 4]

@paddle-bot
Copy link

paddle-bot bot commented May 6, 2023

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

Copy link
Contributor

@zhwesky2010 zhwesky2010 left a comment

Choose a reason for hiding this comment

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

后续可以和numpy一起移除warning,目前累计一共3个地方的trick和warning了

@zhwesky2010 zhwesky2010 merged commit 186f5e0 into PaddlePaddle:develop May 8, 2023
@zoooo0820 zoooo0820 deleted the fix_hack_getitem branch May 8, 2023 06:58
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.

2 participants