#!/usr/bin/env python3 """Offline reader guard for the Original's `--dump-logits PATH` file. Layout: int32 n_vocab, int32 n_rows, then n_rows x n_vocab float32 (little endian). Builds before upstream `504579da` wrote that header when the file was OPENED, so on a native pack (which never reaches the per-token dump site) the file held a header that promised rows and no row at all, and the count in it was one too high even where rows were written (n_prompt + max_new, not n_prompt - 1 + max_new). A reader that trusts the header reports "0 differing positions" for such a file. This reader trusts the SIZE: python3 logits_dump_check.py FILE [--vocab 248320] [--rows N] exit 0 and print the row count, or exit 1 and say why python3 logits_dump_check.py --selftest Never part of serving; no model needed. """ import os import struct import sys import tempfile def check(path, vocab=None, rows=None): """Return (n_vocab, rows_by_size). Raise ValueError when the file is not a consistent dump.""" size = os.path.getsize(path) if size < 8: raise ValueError(f"{path}: {size} bytes, shorter than the 8-byte header") with open(path, "rb") as f: n_vocab, n_rows = struct.unpack("