Paddle (NotFound) Operator elementwise_div does not have kernel for data_type[bool]

cpjpxq1n  于 2023-02-04  发布在  其他
关注(0)|答案(2)|浏览(249)

To Reproduce

import torch

y1 = torch.Tensor([1, 2, 3, -1])
y2 = torch.Tensor([2, 1, 2, 3])
print((y1> 0) / y2)

Result: tensor([0.5000, 1.0000, 0.5000, 0.0000])

import paddle
import numpy as np
y1 = paddle.to_tensor(np.array([1, 2, 3, -1]))
y2 = paddle.to_tensor(np.array([2, 1, 2, 3]))
print((y1 > 0) / y2)

Error: (NotFound) Operator elementwise_div does not have kernel for data_type[bool]:data_layout[ANY_LAYOUT]:place[CPUPlace]:library_type[PLAIN].
[Hint: Expected kernel_iter != kernels.end(), but received kernel_iter == kernels.end().] (at /paddle/paddle/fluid/imperative/prepared_operator.cc:159)
[operator < elementwise_div > error]

希望能适应Bool型 Div的计算
Describe the feature and the current behavior/state.
Any Other info.

mf98qq94

mf98qq941#

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

w46czmvw

w46czmvw2#

这里elementwise_div在2.0之后的版本中为paddle.divide算子。逐元素相除如果使用bool型会导致除零错误。我理解这里错误的发生是因为paddlepaddle和pytorch的用法存在差异。您可以参考这里的办法解决问题:
https://github.com/PaddlePaddle/X2Paddle/blob/develop/docs/pytorch_project_convertor/API_docs/ops/torch.div.md
https://github.com/PaddlePaddle/X2Paddle/blob/develop/docs/pytorch_project_convertor/API_docs/ops/torch.divide.md

相关问题