| 381 | |
| 382 | @unittest.skipIf(OSX or Device.DEFAULT == "CL", "new LLVM has an issue on OSX, DEV=CL gives the wrong output") |
| 383 | def test_bf16_disk_write_read(self): |
| 384 | t = Tensor([10000, -1, -1000, -10000, 20], dtype=dtypes.float32) |
| 385 | t.to(f"disk:{self.tmp('dt_bf16_disk_write_read_f32')}").realize() |
| 386 | |
| 387 | # hack to "cast" f32 -> bf16 |
| 388 | with open(self.tmp('dt_bf16_disk_write_read_f32'), "rb") as f: dat = f.read() |
| 389 | adat = b''.join([dat[i+2:i+4] for i in range(0, len(dat), 4)]) |
| 390 | with open(self.tmp('dt_bf16_disk_write_read_bf16'), "wb") as f: f.write(adat) |
| 391 | |
| 392 | t = Tensor.empty(5, dtype=dtypes.bfloat16, device=f"disk:{self.tmp('dt_bf16_disk_write_read_bf16')}") |
| 393 | ct = t.to(Device.DEFAULT).cast(dtypes.float) |
| 394 | assert ct.numpy().tolist() == [9984., -1, -1000, -9984, 20] |
| 395 | |
| 396 | def test_copy_from_disk(self): |
| 397 | fn = pathlib.Path(self.tmp("dt_copy_from_disk")) |