| 27 | # ── Helpers ──────────────────────────────────────────────────────────────── |
| 28 | |
| 29 | def save_tensor(path, t): |
| 30 | t = t.detach().cpu().float().contiguous() |
| 31 | os.makedirs(os.path.dirname(path) or ".", exist_ok=True) |
| 32 | with open(path + ".bin", "wb") as f: |
| 33 | f.write(t.numpy().tobytes()) |
| 34 | with open(path + ".shape", "w") as f: |
| 35 | f.write(",".join(str(d) for d in t.shape)) |
| 36 | print(f" saved {path} shape={list(t.shape)} " |
| 37 | f"min={t.min().item():.6f} max={t.max().item():.6f} mean={t.mean().item():.6f}") |
| 38 | |
| 39 | |
| 40 | # ── Inlined from vitdet.py ───────────────────────────────────────────────── |