Pull requests / #2288
#2288 tools: validate GGUF headers and tensor extents
open · @KeyanHu-git · 0 commentaires · Sur GitHub
Setup & installAMD / HIPNVIDIA / CUDAModels & quantsWindows
Description
## Title tools: validate GGUF headers and tensor extents Issue: Refs #1919, limited to the malformed-header and tensor-size validation items. ## Summary Malformed GGUF headers can raise `KeyError` or `OverflowError` outside setup's error handling. Separately, completeness checks treat an unknown tensor size as zero, so a file can be accepted without establishing that its tensor payload is present. This change validates header reads and computes the largest required end across all known tensors. Unsupported tensor geometry produces an explicit “cannot verify” result and advice to retain the file. ## What changed - **Header parsing:** bound file-controlled lengths and counts before reading or looping. Report truncated headers, unknown metadata types, nested arrays and invalid alignment as `ValueError` with the file name. Track the byte position internally instead of calling `tell()` for each small read. - **Tensor extents:** centralize completeness checks in `GGUFFile.data_end()`. Inspect every known tensor, including low-offset tensors that extend past later tensors or EOF, and reject invalid element counts for known block types. - **Supported sizes:** add I8/I16/I32/I64 and TQ1_0/TQ2_0 geometry. The ternary sizes follow the bundled ggml block definitions. - **Unsupported sizes:** distinguish unknown or unimplemented repacked formats from malformed input. `whole_shard()` returns false; `check_shards()` explains that verification is unavailable without advising deletion or creating a completion mark. - **Regression tests:** add `tools/test_gguf_reader_malformed.py` for malformed headers, tensor extents, supported integer/ternary payloads, unknown formats and alignment. ## Extra Notes ### Validation Windows 11, Python 3.12.0, NumPy 2.4.2; base: `a0116b2`. | Check | Unmodified upstream | With this patch | | --- | --- | --- | | Unknown metadata type | `KeyError` | `ValueError` naming the file | | Oversized string-length field | `OverflowError` | `ValueError` naming the file | | Unknown tensor-size probe | Accepted as whole | Reported as unverifiable | | Full setup suite | 474 tests; one existing SYCL failure | 474 tests; the same failure | The GGUF, shard and ModelScope suites pass **39 tests**, including 17 new test methods with type/alignment subcases. ```bash python -m unittest tools.test_gguf_reader_malformed tools.test_shards tools.test_setup_modelscope python -m unittest discover -s tools -p 'test_setup_*.py' ``` The unchanged full-suite failure is `test_setup_sycl.ToSycl.test_xe_ranks_the_experts_with_the_sycl_profile_and_i915_keeps_the_shipped_one`. Read-only checks of the installed model files also matched their actual sizes: | File | Calculated extent and actual size | | --- | ---: | | IQ1_M shard 1 | 29,608,446,496 bytes | | IQ1_M shard 2 | 28,800,138,432 bytes | | MTP GGUF | 889,017,216 bytes | These checks read the headers and file attributes, not tensor payloads; the model files were unchanged. ### Compatibility and related work #92 intentionally counted unknown tensor geometry as zero to avoid rejecting complete files. This PR changes that policy: known formats remain checkable, while unknown formats require a compatible reader before setup can confirm completeness. The file is retained, and the message distinguishes an unsupported format from corruption. Other items in #1919 remain outside this PR. #1405 also changes the setup validation callers; integration may require a rebase if it lands first.
Sur le site
Liens install, modèles, releases.