| 43 | |
| 44 | |
| 45 | def test_save_load_float8(dtype): |
| 46 | if "float8" in dtype or "bfloat16" in dtype: |
| 47 | ml_dtypes = pytest.importorskip("ml_dtypes") |
| 48 | np_dtype = np.dtype(getattr(ml_dtypes, dtype)) |
| 49 | else: |
| 50 | np_dtype = np.dtype(dtype) |
| 51 | |
| 52 | arr = np.arange(16, dtype=np_dtype) |
| 53 | |
| 54 | with tempfile.TemporaryDirectory(prefix="tvm_") as temp_dir: |
| 55 | tvmjs.dump_tensor_cache({"arr": arr}, temp_dir) |
| 56 | cache, _ = tvmjs.load_tensor_cache(temp_dir, tvm.cpu()) |
| 57 | |
| 58 | after_roundtrip = cache["arr"].numpy() |
| 59 | |
| 60 | np.testing.assert_array_equal(arr, after_roundtrip) |
| 61 | |
| 62 | |
| 63 | if __name__ == "__main__": |