Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

[BUGFIX] Fix floor divide #21096

Merged
merged 4 commits into from
Jul 18, 2022
Merged

Conversation

Kacper-Pietkun
Copy link
Contributor

Description

Incorrect rounding of a number.

import numpy as onp
import mxnet as mx


onp_d1 = onp.array([0.941], dtype=onp.float16)
onp_d2 = onp.array([0.1569], dtype=onp.float16)
mx_d1 = mx.numpy.array(onp_d1, dtype=onp.float16)
mx_d2 = mx.numpy.array(onp_d2, dtype=onp.float16)

# 0.941 / 0.1569 = 5.997450605481198
onp_out = onp.floor_divide(onp_d1, onp_d2)  # onp_out = [5.] <= GOOD
mx_out = mx.np.floor_divide(mx_d1, mx_d2)  # mx_out = [6.] <= WRONG

Cause

Incorrect rounding was caused by unnecessary implicit conversion from float to float16 after division but before rounding (5.99745 was saved as 6 during conversion from float to float16, because of lack of precision).

Solution

From now, before doing calculations float16 arguments are explicitly casted to float and they are converted back to float16 only after division and rounding has been made.

Checklist

Essentials

  • PR's title starts with a category (e.g. [BUGFIX], [MODEL], [TUTORIAL], [FEATURE], [DOC], etc)
  • Changes are complete (i.e. I finished coding on this PR)
  • All changes have test coverage

@mxnet-bot
Copy link

Hey @Kacper-Pietkun , Thanks for submitting the PR
All tests are already queued to run once. If tests fail, you can trigger one or more tests again with the following commands:

  • To trigger all jobs: @mxnet-bot run ci [all]
  • To trigger specific jobs: @mxnet-bot run ci [job1, job2]

CI supported jobs: [windows-gpu, website, miscellaneous, centos-gpu, sanity, clang, windows-cpu, edge, unix-cpu, unix-gpu, centos-cpu]


Note:
Only following 3 categories can trigger CI :PR Author, MXNet Committer, Jenkins Admin.
All CI tests must pass before the PR can be merged.

@mseth10 mseth10 added the pr-awaiting-testing PR is reviewed and waiting CI build and test label Jul 15, 2022
Copy link
Contributor

@agrabows agrabows left a comment

Choose a reason for hiding this comment

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

Please add yourself to contibutors.md file.

@mseth10 mseth10 added pr-work-in-progress PR is still work in progress and removed pr-awaiting-testing PR is reviewed and waiting CI build and test labels Jul 15, 2022
@Kacper-Pietkun
Copy link
Contributor Author

@mxnet-bot run ci [centos-cpu]

@mxnet-bot
Copy link

Undefined action detected.
Permissible actions are : run ci [all], run ci [job1, job2]
Example : @mxnet-bot run ci [all]
Example : @mxnet-bot run ci [centos-cpu, clang]

@agrabows
Copy link
Contributor

@mxnet-bot run ci [centos-cpu]

@mxnet-bot
Copy link

Unauthorized access detected.
Only following 3 categories can trigger CI :
PR Author, MXNet Committer, Jenkins Admin.

@Kacper-Pietkun
Copy link
Contributor Author

@mxnet-bot run ci [centos-cpu]

@mxnet-bot
Copy link

Jenkins CI successfully triggered : [centos-cpu]

@mseth10 mseth10 added pr-awaiting-testing PR is reviewed and waiting CI build and test pr-work-in-progress PR is still work in progress and removed pr-work-in-progress PR is still work in progress pr-awaiting-testing PR is reviewed and waiting CI build and test labels Jul 15, 2022
@Kacper-Pietkun
Copy link
Contributor Author

@mxnet-bot run ci [centos-gpu]

@mxnet-bot
Copy link

Jenkins CI successfully triggered : [centos-gpu]

@mseth10 mseth10 added pr-awaiting-testing PR is reviewed and waiting CI build and test pr-work-in-progress PR is still work in progress and removed pr-work-in-progress PR is still work in progress pr-awaiting-testing PR is reviewed and waiting CI build and test labels Jul 18, 2022
@Kacper-Pietkun
Copy link
Contributor Author

@mxnet-bot run ci [centos-gpu]

@mxnet-bot
Copy link

Jenkins CI successfully triggered : [centos-gpu]

@mseth10 mseth10 added pr-awaiting-testing PR is reviewed and waiting CI build and test pr-awaiting-review PR is waiting for code review and removed pr-work-in-progress PR is still work in progress pr-awaiting-testing PR is reviewed and waiting CI build and test labels Jul 18, 2022
@bgawrych bgawrych merged commit ef0415d into apache:master Jul 18, 2022
@Kacper-Pietkun Kacper-Pietkun deleted the bug_floor_divide branch July 19, 2022 08:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pr-awaiting-review PR is waiting for code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants