Repository navigation
readers: refuse duplicate checkpoint keys and overlapping GGUF tensor ranges - #977
Conversation
There was a problem hiding this comment.
Verdict: MUST_FIX: The shared Python GGUF reader accepts duplicate tensor names, making the type check depend on declaration order.
Must fix
1. Refuse duplicate tensor names in the shared Python reader (kind A)
tools/ref/gguf-ranges.py:174 reads repeated names without rejecting them. A clef header declaring token_embd.weight as F32 and then Q8_0 passes through read_header to tools/hf-arch-check.py:625, where Q8_0 overwrites F32 and check_row reports types=ok. Reversing the declarations causes refusal. This is a proven sibling of the duplicate-name defect this PR fixes in Rust.
Fixing the shared parser now avoids separate fixes in its callers. Replace its tensor-info loop with:
tensors = []
names = set()
for _ in range(n_tensors):
name = string().decode("utf-8", "replace")
if name in names:
raise Refusal(65, f"{path}: duplicate tensor name {name!r}")
names.add(name)
nd = u32()
dims = [u64() for _ in range(nd)]
tensors.append((name, u32(), dims, u64()))Extend the existing reader self-test with both declaration orders and a unique-name case. Removing this guard must make the duplicate assertions fail.
Checked
- Diagnostics report 0 dryer pairs and
parse_headercomplexity 22 → 24. - In-memory probes through
check_rowreproduced the declaration-order failure. The proposed guard refused both orders and accepted a unique Q8_0 embedding. - Gates: no pins relaxed; the PR supplies FAIL-first output.
- Escape catalog: no C1–C4 matches.
Notes
Rust tests were not executed during validation.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
6f3a4a8 to
ce59d3b
Compare
There was a problem hiding this comment.
Since the last review: the duplicate tensor-name finding is fixed at tools/ref/gguf-ranges.py:176. Both declaration orders are refused.
Verdict: CLEAN: The earlier failure is closed, and no must-fix defect remains in the reviewed interdiff.
Checked
- Duplicates: 0 new functions, types or constants in the interdiff; dryer reports 0 candidate pairs. The shared header parser remains the owner for its callers.
- Complexity: crapper reports
parse_headerat 22 → 24 from two duplicate checks. This function is unchanged in the interdiff. - Silent failure: 3 duplicate-refusal paths followed to consumers. Same-file names, split-set names and the architecture type check return named refusals.
- Tests: 6 new assertions pass in memory. Deleting the header guard above fails 2 assertions. Deleting tools/ref/gguf-ranges.py:234 fails the split assertion. Deleting tools/hf-arch-check.py:626 fails both type-check assertions. Unique names across shards load; equal-type duplicates are refused.
- Gates: no pins relaxed. The dropped fixture-test commit's changes are retained in the added commit.
- Escape catalog: no C1–C4 matches in the revised hunks.
- Performance: the revised code runs in tools and header loading; no inference hot path changes.
Notes
Rust tests and complete tool self-tests were not run. Validation used isolated in-memory probes. GPU evidence is incomplete: the PR lacks the required nvidia-smi line, tested commit hashes and just gate-* output.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
|
The review is done and the contribution check passed, so I'm merging this. |
중복된 체크포인트 키와 서로 겹치는 GGUF tensor 범위를 로드 시점에 오류로 거부하도록 고쳤습니다.
What and why
The safetensors header and index readers let a repeated JSON key overwrite the earlier one, and the GGUF reader accepted a repeated metadata key, a repeated tensor name, or two tensors whose data ranges overlap. A file with such an ambiguity loaded with whichever entry came last, so the loaded weights depended on declaration order.
The safetensors header and
model.safetensors.index.jsonobjects are now read with a duplicate-key check shared by both entry points. The GGUF header parser refuses repeated metadata keys and tensor names, and the strict reader refuses overlapping tensor ranges. Each error names the key or the two tensors involved. Adjacent and separated ranges, and tensor order, load as before. No compute path changes.Release notes: Fixed: duplicate keys in safetensors headers and indexes, and duplicate keys or overlapping tensor ranges in GGUF files, are refused at load instead of resolving by declaration order.
Code shape
copying it (
AGENTS.md"Common code first",docs/rust-quality.mdR14). Where I found an existing copy, Inamed it below.
(tensor shapes, the attention kind, the quant). A common owner gained no per-model branch, flag or trait method.
tools/check-comments.sh).PIN(YYYY-MM-DD):and its reason.
cargo fmtandcargo clippyare clean on what I touched; the lint count did not go up.Duplication found or removed (
path:line), or "none": none.What I ran
Before the fix, on a build with the new tests and the old readers (RTX 5090 machine, CPU run):
After the fix:
The new tests cover duplicates in both declaration orders, nested JSON keys, index entries and overlapping ranges, and check that adjacent and separated GGUF ranges still load.
Real files on the RTX 5090 machine, with the release
bloomery-serve-qwen38andpreparebuilt from the tested tree. The GGUF isQwen3.8-Flash-Next-UD-Q4_K_XLand the checkpoint folder isQwen3.8-Flash-Next-NVFP4.Hardware (if the change is for a machine)
AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.