Repository navigation
hf: serialize cached fetches and resolve checkpoint shards from the index - #985
Conversation
There was a problem hiding this comment.
Verdict: CLEAN: No blocking defect found in the changed cache locking or checkpoint resolution paths.
Checked
Duplicates: 18 new functions checked; no duplicate owner found. Dryer reported zero pairs; the changed gpu-gates code was checked manually.
Complexity: resolve_drafts 20→25 adds manifest orchestration; fetch_to 28→32 adds publication guards; verified_entries 13→16 adds disappearing-file guards. Manifest selection and locking remain shared decisions.
Silent failure: Six cache absence/error sites followed. Unverified files remain unavailable, malformed manifests return named errors, and missing required shards prevent resolution.
Tests (static mutation inspection): In crates/hf/src/fetch.rs:436, dropping locks at 436/897/961 fails download-count or wait assertions; dropping the suffix check at 1034 or read-only fallback at 1061 fails refusal or cached-read assertions. Reversing publication at 525/526 or replacing atomic marker publication at 1024 with an in-place write fails file-presence or inode assertions.
Tests (continued): In crates/hf/src/lib.rs:482, dropping required-shard checks, selecting unused shards at 485, or dropping Jinja selection at 463 fails manifest assertions. Removing parsing/path guards at crates/safetensors/src/lib.rs:479 fails invalid-map assertions. Bypassing the cached manifest at crates/hf/src/catalog.rs:635 fails byte estimates. Flattening paths or bypassing validation at crates/model-hf/src/remote.rs:514 fails folder-open or path-error assertions. Changed fixtures retain selection and checkpoint-support assertions.
Gates: No threshold, tolerance, lint level or test was removed or relaxed.
Performance: Load-time fetching and planning only; no decode, prefill or kernel path changed.
Escape catalog: No C1–C4 pattern matched.
Notes
Tests were inspected, not executed. The body supplies host fetch tests and a load-free plan run, but no just gate-* card run with output.
Card check: needs-gpu. This pull request changes crates/gpu-gates/src/model_file/fetch.rs, crates/gpu-gates/src/model_file/pick.rs and carries no gate run on a card (CONTRIBUTING's evidence list); a maintainer adds gpu-verified after one.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
Filed outside this PR: #986
|
The review is done and the contribution check passed, so I'm merging this. |
HF 캐시의 동시 fetch를 직렬화하고, checkpoint shard를 index의
weight_map에서 찾도록 고쳤습니다.What and why
Two processes fetching the same file could resume from the same partial download. Fetch, pre-hash and offline marker reads now take one per-destination cross-process lock, held from the state check through verify and publish, so a second caller finds the finished file. A cache destination named
*.lockis refused before any sidecar or parent folder is created, so a payload can never replace a lock file.A checkpoint's required shards were not read from its index, so shards in subfolders (for example
tensors/model-00001-of-00021.safetensors) were missed and offline resolve could fail on them. The shard list now comes from the validated, non-emptyweight_map, deduplicated. Resolve refuses, naming the path, a shard missing from the listing, or in offline mode missing its body or verified marker. A malformed index, a non-string shard value or an unsafe relative path is refused at the same boundary. Existing directory symlinks still resolve.The model picker's download estimate and header read use the same shard list once the index is cached, so unused shards in the listing no longer count as downloads or send a cached checkpoint back to ranged header reads. Without a cached index the estimate stays the upper bound over every listed shard. The header copy of a checkpoint keeps each shard's subfolder. The top-level
.jsonand.jinjarule has one owner, used by both the candidate list and the manifest.Release notes: Fixed: concurrent downloads of the same Hugging Face file no longer collide, and checkpoints whose shards live in subfolders resolve from the cache.
Code shape
crates/hf/src/fetch.rsandcrates/hf/src/lib.rs, which every caller already goes through.Folder::weight_mapincrates/safetensors/src/lib.rsis the one parser of the index, shared byFolder::openand resolve. The existingcache_path,exact,digestand marker publishing helpers are reused.crates/gpu-gates/src/model_file/fetch.rsnow writes a validweight_mapindex instead of arbitrary bytes.cargo fmtandcargo clippyare clean on what I touched; the lint count did not go up.Duplication found or removed (
path:line): the two copies of the top-level config rule incrates/hf/src/lib.rs(checkpoint_filesandcheckpoint_manifest) are now onecheckpoint_config.What I ran
Tests of the cached-index, config and lock changes, on commit
02666d84b79fcce20f756afebdd55dac5e327fcc(base90c9f3055b75b99c6e5972e2297b16c922562500), on an Apple silicon Mac:Output of each test with its fix taken out follows. First, with the cached-index branch of
row_filesreplaced by the candidate list:Next, with the
.lockcheck disabled:Last, with the
.jinjarule dropped from the shared config check:Earlier tests of the fetch lock and the shard list, on commit
5609a89b339b99f744a4bdcc69e69893684d8278(basec7b6420554d8c903a583824e147099c6f715e5a9), on a DGX Spark (NVIDIA GB10, driver 595.84):CARGO_BUILD_JOBS=4 cargo test -p bloomery-hf --lib fetch::tests -- --test-threads=4 bash tools/gate.sh -p bloomery-gpu-gates --features hf --lib -- model_file::fetch::tests --nocapture --test-threads=1The new tests there are
concurrent_fetches_share_one_download(two processes overlap on one destination; one download, matching digest and marker) andcheckpoint_manifest_requires_its_shards_online_and_offline(subfolder shards selected, unneeded shards skipped, missing body, marker or listing refused).Real binary on a DGX Spark, commit
dcd4cb72bd2316d556e11c800d639ea6b7cced2c(basefe680eed0feb81b8924bacdcac825096a77a3210), resolving the already cachednvidia/Qwen3.8-Flash-Next-FP4-Localcheckpoint offline, with no downloads. The cache holds the 30 files the index lists, 21 of them shards undertensors/. Card line fromnvidia-smi --query-gpu=name,driver_version,memory.total --format=csv,noheader:NVIDIA GB10, 595.84, [N/A]. The release build usedcargo oxide build --arch sm_121a -- --release -p bloomery-gpu-gates --features glm5next,clef,mimo2,solar2,minimaxm3,flint,gemma-embedding2,hf,checkpoint --bin bloomery-serve, then:The
--planrun loads no tensors and starts no server.AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.