Skip to content

Different behavior of torch.round() on CPU and GPU #16498

@fadisaady

Description

@fadisaady

🐛 Bug

torch.round() seems to be rounding differently for CPU and GPU tensors.
On CPU tensors it rounds half-to-even and on GPU it rounds away-from-zero as shown in the example below.

To Reproduce

CPU rounding:
>>> torch.Tensor([1.5, 2.5, 3.5, 4.5]).round()
tensor([2., 2., 4., 4.])

GPU rounding:
>>> torch.Tensor([1.5, 2.5, 3.5, 4.5]).cuda().round()
tensor([2., 3., 4., 5.], device=‘cuda:0’)

Expected behavior

I expected the function to behave the same on CPU/GPU, either returning [2., 2., 4., 4.] or [2., 3., 4., 5.] on both commands.
It could also be nice to have a way to control the rounding method in future releases, but that's a different issue.

Environment

  • PyTorch Version (e.g., 1.0): 1.0
  • OS (e.g., Linux): Linux
  • How you installed PyTorch (conda, pip, source): pip
  • Build command you used (if compiling from source):
  • Python version: 3.5.2
  • CUDA/cuDNN version: 9
  • GPU models and configuration: GeForce GTX 1060
  • Any other relevant information:

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions