MCPcopy Index your code
hub / github.com/tinygrad/tinygrad / test_bf16_disk_write_read

Method test_bf16_disk_write_read

test/unit/test_disk_tensor.py:383–394  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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"))

Callers

nothing calls this directly

Calls 10

toMethod · 0.95
TensorClass · 0.90
realizeMethod · 0.80
tmpMethod · 0.80
readMethod · 0.45
writeMethod · 0.45
emptyMethod · 0.45
castMethod · 0.45
tolistMethod · 0.45
numpyMethod · 0.45

Tested by

no test coverage detected