Save a tensor as raw float32 binary + shape file.
(path, t)
| 25 | |
| 26 | |
| 27 | def save_tensor(path, t): |
| 28 | """Save a tensor as raw float32 binary + shape file.""" |
| 29 | t = t.detach().cpu().float().contiguous() |
| 30 | with open(path + ".bin", "wb") as f: |
| 31 | f.write(t.numpy().tobytes()) |
| 32 | with open(path + ".shape", "w") as f: |
| 33 | f.write(",".join(str(d) for d in t.shape)) |
| 34 | print(f" saved {path} shape={list(t.shape)} bytes={t.numel()*4}") |
| 35 | |
| 36 | |
| 37 | def main(): |
no test coverage detected