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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide half-away-from-zero rounding mode on Tensor::round #54201

Open
josevalim opened this issue Mar 17, 2021 · 1 comment
Open

Provide half-away-from-zero rounding mode on Tensor::round #54201

josevalim opened this issue Mar 17, 2021 · 1 comment
Labels
enhancement Not as big of a feature, but technically not a bug. Should be easy to fix function request A request for a new function or the addition of new arguments/modes to an existing function. module: cpp Related to C++ API triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@josevalim
Copy link

josevalim commented Mar 17, 2021

馃殌 Feature

Currently Tensor::round rounds half-to-nearest-even, however, some platforms and tools round half-away-from-zero by default. One of such examples is XLA, which uses half-away-from-zero by default (and half-to-nearest-even is emulated in libraries like JAX).

Operations like Tensor::div already support rounding_mode as an option, so hopefully a similar option - but with different values - can be added to round.

Motivation

I am writing bindings for both PyTorch and XLA for the Elixir programming language and one of the discrepancies we found were the rounding operations. Both XLA and Elixir rounds half-away-from-zero, which is inconsistent to PyTorch default behaviour (which actually aligns with Python 3).

Pitch

The current behaviour rounds both -0.5 and 0.5 to 0. A new rounding option should round them to -1.0 and 1.0 respectively.

Thank you!

cc @yf225 @glaringlee

@jeffreyksmithjr
Copy link
Contributor

jeffreyksmithjr commented Mar 17, 2021

Seems like something possibly small enough to be an enhancement, but I'm not the person to say definitively. Added a label to indicate that this is a request specifically to expose this in libtorch, although obviously it would be beneficial to have consistency across the Python and C++ frontends. Just clarifying that @josevalim 's need is in calling into the C++ API.

@agolynski agolynski added enhancement Not as big of a feature, but technically not a bug. Should be easy to fix function request A request for a new function or the addition of new arguments/modes to an existing function. triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module labels Mar 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Not as big of a feature, but technically not a bug. Should be easy to fix function request A request for a new function or the addition of new arguments/modes to an existing function. module: cpp Related to C++ API triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

No branches or pull requests

3 participants