#10692·oneflow

CPU greater and greater_equal incorrectly return True for comparisons involving NaN

Author: ALinrunrunCreated Aug 6, 2026Updated Aug 6, 2026
Labelsbugcommunity

Summary

On CPU, oneflow.gt / oneflow.greater and oneflow.ge / oneflow.greater_equal incorrectly return True for ordered comparisons involving NaN.

According to IEEE 754, every ordered comparison involving NaN must be False. For example:

  • 1.0 > NaNFalse
  • NaN > 2.0False
  • NaN >= NaNFalse

However, OneFlow's CPU kernels return True for these comparisons:

oneflow CPU gt(x, y) = [1, 1, 1, 0]
oneflow CPU ge(x, y) = [1, 1, 1, 1]

The expected results are:

gt(x, y) = [0, 0, 0, 0]
ge(x, y) = [0, 0, 0, 1]

NumPy, PyTorch, and OneFlow's CUDA kernels return the expected results. Other OneFlow comparison operators such as lt, le, eq, and ne also handle NaN correctly.

This causes CPU/GPU behavioral divergence and can silently produce incorrect masks in code that uses > or >= for thresholding, filtering, gating, or similar operations.

Code to reproduce bug

python
#!/usr/bin/env python3

import os

os.environ["CUDA_VISIBLE_DEVICES"] = "-1"

import oneflow as flow


nan = float("nan")

x = flow.tensor([1.0, nan, nan, 5.0])
y = flow.tensor([nan, 2.0, nan, 5.0])

gt = flow.gt(x, y).numpy().astype(int).tolist()
ge = flow.ge(x, y).numpy().astype(int).tolist()

expected_gt = [0, 0, 0, 0]
expected_ge = [0, 0, 0, 1]

print(f"oneflow CPU gt(x, y)={gt}  (IEEE-correct {expected_gt})")
print(f"oneflow CPU ge(x, y)={ge}  (IEEE-correct {expected_ge})")

assert gt == expected_gt
assert ge == expected_ge

Run with:

bash
python oneflow-001.py

Actual output:

W cuda_device_descriptor_class.cpp:48] no CUDA-capable device is detected
oneflow CPU gt(x, y)=[1, 1, 1, 0]  (IEEE-correct [0, 0, 0, 0])
oneflow CPU ge(x, y)=[1, 1, 1, 1]  (IEEE-correct [0, 0, 0, 1])
Traceback (most recent call last):
  File "oneflow-001.py", line 26, in <module>
    assert gt == expected_gt
AssertionError

Expected output:

oneflow CPU gt(x, y)=[0, 0, 0, 0]  (IEEE-correct [0, 0, 0, 0])
oneflow CPU ge(x, y)=[0, 0, 0, 1]  (IEEE-correct [0, 0, 0, 1])

System Information

  • What is your OneFlow installation (pip, source, dockerhub): pip
  • OS: Linux
  • OneFlow version (run python3 -m oneflow --doctor):
version: 0.9.0
git_commit: 381b12c
cmake_build_type: Release
rdma: True
mlir: True
  • Python version: Python 3.10
  • CUDA driver version: No CUDA-capable device detected
  • GPU models: None used; the issue reproduces on CPU
  • Other info: The reproducer forces the CPU path with CUDA_VISIBLE_DEVICES=-1.