jax-ml/ml_dtypes

Test failures on aarch64-darwin

Closed this issue · 3 comments

I'm observing the following failures in the test suite on aarch64-darwin.

============================= test session starts ==============================
platform darwin -- Python 3.10.12, pytest-7.4.0, pluggy-1.2.0
rootdir: /private/tmp/nix-build-python3.10-ml-dtypes-0.3.1.drv-0/source
configfile: pytest.ini
collected 475 items                                                            

tests/custom_float_test.py ..............................F.............. [  9%]
...F.................................................................... [ 24%]
........................................................................ [ 39%]
.........F.............................................................. [ 54%]
........................................................................ [ 70%]
.........                                                                [ 72%]
tests/finfo_test.py ......                                               [ 73%]
tests/iinfo_test.py ....                                                 [ 74%]
tests/int4_test.py ..................................................... [ 85%]
.....................................................................    [ 99%]
tests/metadata_test.py .                                                 [100%]

=================================== FAILURES ===================================
_____________________ CustomFloatTest.testArgmax_bfloat16 ______________________

self = <custom_float_test.CustomFloatTest testMethod=testArgmax_bfloat16>
float_type = <class 'ml_dtypes.bfloat16'>

    def testArgmax(self, float_type):
      values_to_sort = np.float32(
>         float_type(np.float32(FLOAT_VALUES[float_type]))
      )
E     RuntimeWarning: invalid value encountered in cast

tests/custom_float_test.py:452: RuntimeWarning
_____________________ CustomFloatTest.testArgmin_bfloat16 ______________________

self = <custom_float_test.CustomFloatTest testMethod=testArgmin_bfloat16>
float_type = <class 'ml_dtypes.bfloat16'>

    def testArgmin(self, float_type):
      values_to_sort = np.float32(
>         float_type(np.float32(FLOAT_VALUES[float_type]))
      )
E     RuntimeWarning: invalid value encountered in cast

tests/custom_float_test.py:474: RuntimeWarning
________________ CustomFloatTest.testRoundTripToNumpy_bfloat16 _________________

self = <custom_float_test.CustomFloatTest testMethod=testRoundTripToNumpy_bfloat16>
float_type = <class 'ml_dtypes.bfloat16'>

    @ignore_warning(category=RuntimeWarning, message="overflow encountered")
    def testRoundTripToNumpy(self, float_type):
      for dtype in [
          float_type,
          np.float16,
          np.float32,
          np.float64,
          np.longdouble,
      ]:
        with self.subTest(dtype.__name__):
          for v in FLOAT_VALUES[float_type]:
            np.testing.assert_equal(dtype(v), dtype(float_type(dtype(v))))
            np.testing.assert_equal(dtype(v), dtype(float_type(dtype(v))))
            np.testing.assert_equal(
                dtype(v), dtype(float_type(np.array(v, dtype)))
            )
          if dtype != float_type:
            np.testing.assert_equal(
                np.array(FLOAT_VALUES[float_type], dtype),
>               float_type(np.array(FLOAT_VALUES[float_type], dtype)).astype(
                    dtype
                ),
            )
E           RuntimeWarning: invalid value encountered in cast

tests/custom_float_test.py:238: RuntimeWarning
=========================== short test summary info ============================
FAILED tests/custom_float_test.py::CustomFloatTest::testArgmax_bfloat16 - RuntimeWarning: invalid value encountered in cast
FAILED tests/custom_float_test.py::CustomFloatTest::testArgmin_bfloat16 - RuntimeWarning: invalid value encountered in cast
FAILED tests/custom_float_test.py::CustomFloatTest::testRoundTripToNumpy_bfloat16 - RuntimeWarning: invalid value encountered in cast
======================== 3 failed, 472 passed in 1.00s =========================

I'm on ml-dtypes 0.3.1, and building from source.

Thanks for the report – these look like expected warnings that we need to add to our ignore list (FLOAT_TYPES deliberately includes invalid values like nan). We have an ignore_warning context manager that we already employ frequently in the test suite, and it looks like we'll have to add it to the problematic tests – would you be willing to put together a PR?

Unfortunately I don't have bandwidth to put together a PR atm, but I'd be happy to test one out if one comes online.

Sure, no problem. #107 should fix the issue for you.