fix(checkpoint): validate FTW v1 indexes eagerly - #459
Avicennasis wants to merge 1 commit into
Conversation
Malformed or truncated FTW indexes used to surface as mmap/O_DIRECT failures deep inside the load. Parse and check the index once at open (integer ranges, required fields, duplicate keys, entry names, shard coverage, shard size), raise FTWFormatError, and reject nothing the writer produces. Shards are stat'd through symlinks because Hugging Face hub snapshots are symlink farms.
faa90f6 to
56ed570
Compare
|
Rebased onto current #486's Re-ran on a CPU-only Ubuntu 24.04 x86_64 box (AMD Ryzen 7 5800X, 16 threads, 125 GiB, no GPU; Python 3.12, torch 2.11.0+cu130, transformers 5.17.0, pytest 9.1.1, run with
Nothing in the change touches a kernel or a model family; the validator runs once at |
Problem. A malformed or truncated FTW v1 index (missing field, wrong type, out-of-range offset, duplicate key, shard shorter than declared) surfaces late, as an mmap or O_DIRECT failure inside the load, with no indication of which index field was wrong.
Change. Parse and validate the index once at
FTWReaderopen: required fields, JSON integers within the signed 64-bit range, duplicate keys rejected, entry names checked, tensors and shards checked for coverage and overlap, each shard stat'd and size-checked. Errors raiseFTWFormatError(aValueError) naming the field. The writer validates its own metadata.Shard symlinks are followed — Hugging Face hub snapshots are symlink farms — and the regular-file and size checks apply to the link target. A shard name that is not a filesystem name (a JSON-escaped lone surrogate) is refused under the same error type rather than escaping as
UnicodeEncodeError.Nothing the writer produces is rejected; existing valid checkpoints load unchanged.
Not in this PR. Runtime integrity re-checks, admission, generations, and bank-schema validation are separate changes.
Tested. Ubuntu 24.04 x86_64, kernel 7.0.0, 16 cores / 125 GiB, no GPU — this is a pure-Python change and the added tests are CPU-only. Python 3.12, torch 2.11.0+cu130, transformers 5.17.0, pytest 9.1.1, safetensors 0.8.0. Run with
PYTHONPATH=python(an editable install needsCUDA_HOME); the C++ extension is not built in this environment, which accounts for one of the pre-existing failures below.Focused:
Also under
python -O(85 passed), since several of the checks would be lost if they were assertions.Full suite from the repo root, this branch:
and
mainat9535656in the same venv, same command:Identical failure sets —
tests/engine/test_cache_budget.py::test_adjust_config_defaults_moe_cache_auto_for_auto_resolved_offload_backend,tests/engine/test_cache_budget.py::test_adjust_config_resolves_num_tokens_generic,tests/moe/test_offload.py::test_adjust_config_converts_moe_cache_rate_to_cache_size, andtests/kernels/test_swiglu_clamp.py::test_cpu_extension_supports_swiglu_clamp(the CPU extension is not built here). The +85 is this PR's test file.No checkpoint was converted; the tests build their own FTW files with
FTWWriter.git diff --checkclean;compileallok; ruff 0.15.0 reports nothing on the four touched files (and nothing on theirmaincounterparts).Fixes #458.