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

关于0维Tensor的代码修改请求 #2

Open
zhwesky2010 opened this issue Nov 3, 2022 · 0 comments
Open

关于0维Tensor的代码修改请求 #2

zhwesky2010 opened this issue Nov 3, 2022 · 0 comments

Comments

@zhwesky2010
Copy link

zhwesky2010 commented Nov 3, 2022

Hi,开发者你好,由于飞桨API之前对0维Tensor的支持不完善,通过shape为[1]的1D Tensor来替代shape为[]的0D Tensor,因此在很多本应输出0维tensor的场景中,实际输出的是1维tensor(如:loss)。目前飞桨计划全面支持0维tensor,在大多数情况下不会有不兼容问题,但也发现少量情况可能会报错。

目前发现 会报错 的代码是:loss.numpy()[0] 。原因是此前loss为1D Tensor(错误的语义),运行loss.numpy()[0]可以将其转化为python float数据。在修改为0D Tensor(正确的语义)后,此操作会报错。需要将所有 loss.numpy()[0] 修改为 float(loss) ,以避免后续版本的代码错误。

因此请麻烦修改:

  • 对于shape为[1]的1维Tensor:Tensor.numpy()[0] 修改为 float(Tensor),对当前不会有影响,亦可适应未来变化。感谢贡献代码。

Hi, Developer, Due to the poor support for the 0D tensor in Paddle API. In many case, the output 1D tensor which shoulde be 0D Tensor (such as loss) are used by mistake. Paddle is plan to support 0D tensor fully, which will not cause incompatibility in most cases. However, it is also found that some code will report error.

This code is: loss.numpy()[0] 。 The reason is that the loss was 1D Tensor (wrong) before, it can be used as loss.numpy()[0]. After the loss is modified to 0D Tensor (correct), the operation will result in an error. Therefore, it is needed to modify loss.numpy()[0] to float(loss) , to avoid errors in future paddle version.

Therefore, please modify:

  • As for shape[1] Tensor: modify Tensor.numpy()[0] to float (Tensor) , It will not affect the current situation, but also adapt to future. Thank you for contributing code.
@zhwesky2010 zhwesky2010 changed the title 模型代码修改请求 关于0维Tensor的代码修改请求 Nov 3, 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

1 participant