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

(this issue is just for my personal self-learning ) not flexible enough: paddle.scatter() #43260

Closed
OccupyMars2025 opened this issue Jun 6, 2022 · 4 comments
Labels
PFCC Paddle Framework Contributor Club,https://github.com/PaddlePaddle/community/tree/master/pfcc status/close 已关闭 type/docs 文档问题

Comments

@OccupyMars2025
Copy link
Contributor

OccupyMars2025 commented Jun 6, 2022

问题描述 Please describe your issue

"torch code, can be replaced with torch.nn.functional.one_hot"
def one_hot_torch(x, num_classes, on_value=1., off_value=0., device='cuda'):
x = x.long().view(-1, 1)
return torch.full((x.size()[0], num_classes), off_value, device=device).scatter_(1, x, on_value)

“paddle version”
def one_hot(x, num_classes, on_value=1., off_value=0., device='cuda'):
x = x.astype("int64").reshape([-1])
out = paddle.nn.functional.one_hot(x, num_classes=num_classes)
out = paddle.where(out > 0.5, on_value, off_value)
out = paddle.to_tensor(out, place=paddle.CUDAPlace(0) if paddle.is_compiled_with_cuda() else paddle.CPUPlace())
return out

TODO: When I study the above code, I find out that compared to torch.scatter(), paddle.scatter() is not flexible enough. The key problems are how to "index" and how to handle the case when there are repeated numbers in "index" especially in GPU mode ( simultaneous running threads that work on the same element in a tensor may have conflicts ???)

The following two PRs may have the same problems:
paddle.index_add
paddle.index_fill

@paddle-bot-old
Copy link

paddle-bot-old bot commented Jun 6, 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!

@OccupyMars2025 OccupyMars2025 changed the title imcomplete feature: paddle.scatter() not flexible enough: paddle.scatter() Jun 6, 2022
@SunNy820828449
Copy link
Contributor

Thanks for your issue. We will feedback this issue to our developer.

@paddle-bot-old paddle-bot-old bot added type/docs 文档问题 and removed type/others 其他问题 labels Jun 8, 2022
@Ligoml
Copy link
Contributor

Ligoml commented Jun 10, 2022

In fact, paddle.put_along_axis and torch.scatter are corresponding, we suggest you try paddle.put_along_axis to solve this issue. We will add clarification later in the documentation.

@OccupyMars2025
Copy link
Contributor Author

Thank you for your answer.

@OccupyMars2025 OccupyMars2025 changed the title not flexible enough: paddle.scatter() (this issue is just for my personal self-learning ) not flexible enough: paddle.scatter() Jun 20, 2022
@paddle-bot-old paddle-bot-old bot added status/close 已关闭 and removed status/new-issue 新建 labels Jun 25, 2022
@luotao1 luotao1 added the PFCC Paddle Framework Contributor Club,https://github.com/PaddlePaddle/community/tree/master/pfcc label Aug 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PFCC Paddle Framework Contributor Club,https://github.com/PaddlePaddle/community/tree/master/pfcc status/close 已关闭 type/docs 文档问题
Projects
None yet
Development

No branches or pull requests

4 participants