Repository navigation
prepare: publish a validated split without replacing existing shards - #708
Conversation
There was a problem hiding this comment.
Verdict: CLEAN: The changed writer preserves existing shards and validates the full split before publication.
Non-blocking
⚠ Cover publication order: crates/model-hf/src/bin/prepare.rs:475. The assertions observe the output before publication and after completion. Replacing paths.iter().rev() at line 258 with paths.iter() leaves them green, while readers can see the first shard before its siblings. Extend this test with a deterministic observation that the first shard is published last.
⚠ Explain the debuggability layer: crates/model-hf/src/bin/prepare.rs:261. The PR supplies the shared fix and regression tests, but does not explain its debugging route. Document how the existing path-qualified publication and cleanup errors diagnose failures, or identify the existing probe that does so.
Checked
Duplicates: 7 new functions checked; no reusable duplicate found. Dryer reported 0 pairs.
Complexity: crapper flagged new write_split at 28. Its stages are staging/validation, publication/rollback, and cleanup; no existing decision tree gained branches.
Silent failure: 5 sites followed: conversion iterator errors, metadata errors, rollback, temporary-directory cleanup, and unlock. Failures reach the caller and exit status 1.
Tests, mutation by inspection: returning success for an existing output (243 → 414) and omitting rollback tracking (262 → 539) fail assertions. Bypassing busy rejection (224 → 422) and publishing forwards (258 → 459) survive.
Gates: no pins, bands, thresholds, or existing tests changed.
Escape catalog: C1–C4 do not match.
Adversarial checks: overlapping writers, a late publication conflict, and a pre-existing dangling symlink are blocked by locking, atomic no-replace rename, and symlink metadata checks.
Hot path: none; this is checkpoint conversion.
Notes
Tests were not rerun during this static review. The PR reports eight passing host tests and one ignored test.
🔨 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. |
prepare가 분할 파일을 만들다 실패하거나 두 번 동시에 돌아도 기존 결과를 망가뜨리지 않도록, 완성하고 검증한 뒤에만 공개하게 고칩니다.
Part of #565. Tracked in #699.
What and why
preparewrites a converted checkpoint as a split of GGUF shards, and two things could go wrong with it:prepareruns on the same output prefix shared one temporary.partname per shard. A run could report success and the split on disk could still change afterwards, because the other run was writing the same file.Both come from #540, which added the shard writer. The split is now written by one private function,
write_split. It takes an OS lock on a<prefix>.prepare.lockfile, which stays beside the output, writes every shard into a private temporary directory, checks the whole split with the reader the server uses (gguf::Split::openandmodel::arch::spec), and only then moves the shards into place with the existingrename_noreplace. The last shards go first and the first shard, which readers open, goes last. On an error it removes only its own temporary directory and the shards it already published.An output shard that already exists, whether a file, a directory or a dangling symlink, is now an error instead of being overwritten. A split cannot be swapped in one step, so keeping the old result and asking for a new prefix is the safe choice. This changes behavior for anyone who reran
prepareover the same prefix, and the module documentation says so. Tensor conversion, GGUF layout and output names are unchanged. There is no new public item, option or dependency, and no GPU path is touched. The change does not add fsync or crash durability.Release notes: Fixed:
prepareno longer overwrites existing shards, and a failed or concurrent run no longer leaves a mixed split.Code shape
write_splitis the one owner of writing, validating and publishing a split. It reusesWriter,gguf::Split,model::arch::specandmodel::fileio::rename_noreplace..partnaming are removed.cargo fmtandcargo clippyare clean on what I touched; the lint count did not go up.rustfmtran clean on the pinned nightly;cargo clippyhas not run on this head.Duplication found or removed (
path:line): none.split_dirincrates/model-hf/src/bin/prepare.rs:373is not shared withcrates/model-hf/src/lib.rs:16, because that library's test support iscfg(test)andpub(crate), so the separately compiledpreparebinary cannot reach it.What I ran
The tests ran on a Linux machine with
RUSTFLAGS='-C target-cpu=native'andCARGO_BUILD_JOBS=4. The change is in one host-side file and no CUDA path is involved, so no GPU gates ran.cargo test -p bloomery-model-hf --bin prepare split_ -- --nocaptureexits 101 withtest result: FAILED. 0 passed; 2 failed; 0 ignored; 0 measured; 5 filtered out; finished in 0.00s. Both new tests fail on an assertion, not at compile time.split_failure_preserves_existing_shardsshows the first existing shard's bytes changed after a later shard failed.split_concurrent_writers_cannot_change_a_successful_outputshows a successful writer's output changed afterwards.cargo test -p bloomery-model-hf --bin prepare -- --nocaptureexits 0 withtest result: ok. 8 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in 1.18s. Four of the eight are new regression tests. They cover shard counts of 1, 2 and 4 against the bytes an independentWriterproduces, the first shard absent until the whole split validates, and cleanup that touches only the run's own files after a write, validation or publish failure.git diff upstream/main...HEAD --checkexits 0.Not run:
cargo clippy, the contribution checks and the GPU gates.Reproduction
To see the failure first, run the first command with
crates/model-hf/src/bin/prepare.rsrestored to its upstream version and only the test module and its fixtures kept.What I ran into
This does not block the PR. The F32 scale packing in
preparestill builds a temporaryVecper tensor. I did not measure it and left it alone.AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.