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

[Fix] Fix paddle.floor_divide AssertionError when using CUDA 11.2 #45051

Merged
merged 1 commit into from
Sep 26, 2022

Conversation

Bobholamovic
Copy link
Member

@Bobholamovic Bobholamovic commented Aug 10, 2022

PR types

Bug fixes

PR changes

OPs

Describe

How to reproduce

In an environment with CUDA 11.2, the bug can be reproduced by executing the following code:

import paddle

import numpy as np

x = np.array([2, 3, 4])

y = np.array([1, 5, 2])

xp, yp = paddle.to_tensor(x), paddle.to_tensor(y)

rp = paddle.floor_divide(xp, yp)

print(rp)

The running result contains assertion errors even if b is a non-zero number:

07ba07639d544078fefe555c1804e80d

Causes

This bug is caused by the calls tostd::trunc(), as the functor gives expected results when these calls are removed.

How I fixed it

My solution is to remove the calls to std::trunc(), since they are NOT necessary here. The reason is two-fold:

  1. Currently, paddle.floor_divide() supports only int32 and int64 data, and rounding-to-zero is the defined behavior of integer division in C++.
  2. According to link, calling std::trunc() can result in an extra type coercions when input arguments are of integral types, which brings overheads.

It is noteworthy that the floor_divide implementation for integral types in PyTorch is also dependent on C++ integer division, and no std::trunc() is used.

Also note that the name paddle.floor_divide is not so accurate. For divisions involving a negative number and a positive number, the result is rounded to zero instead of performing actual floor division. This PR does not change this behavior.

@paddle-bot
Copy link

paddle-bot bot commented Aug 10, 2022

你的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.

@paddle-bot-old paddle-bot-old bot added contributor External developers and removed contributor External developers labels Sep 13, 2022
@Bobholamovic Bobholamovic requested review from chenwhql and removed request for AshburnLee September 26, 2022 03:48
Copy link
Contributor

@chenwhql chenwhql left a comment

Choose a reason for hiding this comment

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

LGTM

@xiegegege xiegegege merged commit 091ae70 into PaddlePaddle:develop Sep 26, 2022
@paddle-bot
Copy link

paddle-bot bot commented Sep 26, 2022

你的PR已合入Paddle库,请关注后续测试结果。
Your PR has been merged into the repository. An official integration test will be conducted later. Stay tuned.

Bobholamovic added a commit to Bobholamovic/Paddle that referenced this pull request Sep 26, 2022
phlrain pushed a commit that referenced this pull request Sep 29, 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

Successfully merging this pull request may close these issues.

3 participants