[Mlir-commits] [mlir] [MLIR][test] Check for ml_dtypes before running tests (PR #123061)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Wed Jan 15 06:16:52 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Konrad Kleine (kwk)

<details>
<summary>Changes</summary>

We noticed that `mlir/python/requirements.txt` lists `ml_dtypes` as a requirement but when looking at the code in `mlir/python`, the only `import` is guarded:

```python
try:
    import ml_dtypes
except ModuleNotFoundError:
    # The third-party ml_dtypes provides some optional low precision data-types for NumPy.
    ml_dtypes = None
```

This makes `ml_dtypes` an optional dependency.

Some python tests however partially depend on `ml_dtypes` and should not run if that module is unavailable. That is what this change does.

This is a replacement for #<!-- -->123051 which was excluding tests too broadly.

---
Full diff: https://github.com/llvm/llvm-project/pull/123061.diff


1 Files Affected:

- (modified) mlir/test/python/execution_engine.py (+10-3) 


``````````diff
diff --git a/mlir/test/python/execution_engine.py b/mlir/test/python/execution_engine.py
index 0d12c35d96bee7..9bfec3e7d0c538 100644
--- a/mlir/test/python/execution_engine.py
+++ b/mlir/test/python/execution_engine.py
@@ -5,7 +5,12 @@
 from mlir.passmanager import *
 from mlir.execution_engine import *
 from mlir.runtime import *
-from ml_dtypes import bfloat16, float8_e5m2
+try:
+    from ml_dtypes import bfloat16, float8_e5m2
+    HAS_ML_DTYPES=True
+except ModuleNotFoundError:
+    HAS_ML_DTYPES=False
+
 
 MLIR_RUNNER_UTILS = os.getenv(
     "MLIR_RUNNER_UTILS", "../../../../lib/libmlir_runner_utils.so"
@@ -564,7 +569,8 @@ def testBF16Memref():
         log(npout)
 
 
-run(testBF16Memref)
+if HAS_ML_DTYPES:
+    run(testBF16Memref)
 
 
 # Test f8E5M2 memrefs
@@ -603,7 +609,8 @@ def testF8E5M2Memref():
         log(npout)
 
 
-run(testF8E5M2Memref)
+if HAS_ML_DTYPES:
+    run(testF8E5M2Memref)
 
 
 #  Test addition of two 2d_memref

``````````

</details>


https://github.com/llvm/llvm-project/pull/123061


More information about the Mlir-commits mailing list