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

The need for zero-dimensional tensors. #42757

Closed
AndPuQing opened this issue May 13, 2022 · 6 comments
Closed

The need for zero-dimensional tensors. #42757

AndPuQing opened this issue May 13, 2022 · 6 comments
Assignees
Labels

Comments

@AndPuQing
Copy link
Contributor

需求描述 Feature Description

I am now trying add Paddle in deepxde(https://github.com/lululxvi/deepxde) as backend. For some reason, we need to distinguish between zero-dimensional tensors and 1D tensors, as follows:

import torch

a = torch.tensor(3)
print(a.ndim) # 0
b = torch.tensor([3])
print(b.ndim) # 1

import paddle
a=paddle.to_tensor([3])
print(a.ndim) # 1
b=paddle.to_tensor(3)
print(b.ndim) # 1

替代实现 Alternatives

No response

@paddle-bot-old
Copy link

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

@jzhang533
Copy link
Contributor

@iclementine is investigating on this.

@iclementine
Copy link

iclementine commented May 13, 2022

Currently, paddle has limited and inconsistent support for zero-dimensional tensors due to a previous design to fake a zero-dimensional tensor with a 1d tensor with shape [1]. After that, a lot of APIs has been hacked to deal with zero-dimensional tensors, which is incorrect mathematically.

For example, indexing an 1d tensor with an integer returns a 1d tensor with shape [1] instead of a 0d tensor. Reduction on a tensor at all dimensions returns a 1d tensor with shape [1] instead of a 0d tensor.

It's a known issue and we are planning on fixing it. But fixing this requires a throughout scanning of all APIs, which might requires some time.

@AndPuQing
Copy link
Contributor Author

Right now I'm using a 1D tensor to simulate a zero-dimensional tensor which is indeed problematic, so expect the problem to be solved. Thank you for your reply

@zhwesky2010
Copy link
Contributor

zhwesky2010 commented Sep 5, 2022

@AndPuQing Hello, is there other API except to_tensor? We are considering supporting 0D, but Many APIs need to be modified. If you encounter any problem with the API of 0D, you can report this API to us, and we will support it firstly.

@zhwesky2010
Copy link
Contributor

@AndPuQing 你好,飞桨将于2.5版本全面支持0维Tensor,上述反馈的0D问题也将同时解决。

欢迎试用并安装develop 版本的paddle whl包,将体验最新的0维特性:https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/develop/install/pip/linux-pip.html
安装命令:
pip install paddlepaddle-gpu==0.0.0.post112 -f https://www.paddlepaddle.org.cn/whl/linux/gpu/develop.html


Hello, Paddle will fully support the 0-dimensional Tensor in version 2.5, and the 0D issue will also be resolved at the same time.
Welcome to try and install the develop version of the paddle whl package, and you will experience the latest 0-dimensional features: https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/develop/install/pip/linux -pip.html
Install Command:
pip install paddlepaddle-gpu==0.0.0.post112 -f https://www.paddlepaddle.org.cn/whl/linux/gpu/develop.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants