Skip to content

Nan propagation of min/max function broken for POWER #57537

@Flamefire

Description

@Flamefire

🐛 Bug

Running the tests shows a failure with nan propagation for torch.max/torch.min introduced in 1.8.0 via #41541

Example:

FAIL: test_min_max_binary_op_nan_cpu_float32 (__main__.TestBinaryUfuncsCPU)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/easybuild-tmp/eb-TDt0D1/tmpeqDImk/lib/python3.8/site-packages/torch/testing/_internal/common_device_type.py", line 290, in instantiated_test
    result = test_fn(self, *args)
  File "test_binary_ufuncs.py", line 1306, in test_min_max_binary_op_nan
    self.assertTrue(torch.isnan(ma[i]), "max(a, b): {}, a: {}, b: {}".format(ma[i], a[i], b[i]))
AssertionError: tensor(False) is not true : max(a, b): 0.29149895906448364, a: nan, b: 0.29149895906448364

To Reproduce

Run tests on PPC

See e.g https://gist.github.com/Flamefire/3f11af7f908742908d0d035d3e430646

Expected behavior

Tests succeed

Environment

  • PyTorch Version (e.g., 1.0): 1.8.1
  • OS (e.g., Linux): Linux
  • How you installed PyTorch (conda, pip, source): source
  • Any other relevant information: ppc9le

Additional context

This failure was (knowingly) introduced by the mentioned PR.
Question now is: Is the behavior on NaNs defined by PyTorch? If so there is a bug which needs fixing. Otherwise the relevant tests should be removed or changed.

Also see e.g. https://eigen.tuxfamily.org/bz/show_bug.cgi?id=1494 / https://gitlab.com/libeigen/eigen/-/issues/1494

using the vec_max intrinsic which follows IEEE-754R and thus returns numeric for numeric vs NaN comparisons.

If the NaN-propagating behavior is wanted, I don't see any other approach but not using vec_min etc on VSX

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: NaNs and InfsProblems related to NaN and Inf handling in floating pointmodule: POWERIssues specific to the POWER/ppc architecturetriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions