Skip to content

hf: refuse unsupported checkpoint sources before fetching files - #738

Merged
juliankang4 merged 2 commits into
midagedev:mainfrom
juliankang4:fix-checkpoint-fetch-admission
Oct 23, 2026
Merged

juliankang4 merged 2 commits into
midagedev:mainfrom
juliankang4:fix-checkpoint-fetch-admission

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

--hf로 safetensors checkpoint만 있는 저장소를 지정하면, 이를 열 수 없는 호출자도 shard를 전부 내려받은 뒤에야 거부하던 문제를 고칩니다.

Part of #565. Tracked in #699.

What and why

A --hf repository that holds a safetensors checkpoint and no GGUF set resolves to the checkpoint's folder. Only a caller that can open a checkpoint folder can use that result. Client::resolve, Client::resolve_drafts and model_file::resolve did not know which caller they served. A build without the checkpoint feature, and callers that only read GGUF files (the embedding side seat and sentence_prompts), therefore downloaded and verified every shard first and refused afterwards. The user waited for the whole checkpoint and then got an error.

The checkpoint fallback and its fetch loop came in with 2a22225053118b7dd0c90d4e310db6f9a334f215, merged in #635.

The resolvers now take a Sources value (Gguf or GgufOrCheckpoint) that names what the caller can open. The existing checkpoint helper checks it right after it sees the repo has no GGUF set, before any file event or fetch, and returns a new HfError::CheckpointUnsupported that names the repo. The offline cache path goes through the same helper, so a cached checkpoint folder is refused the same way. model_file::name hands over GgufOrCheckpoint only when the checkpoint feature is on. The embedding side seat hands over Gguf, because Split::open is its only consumer. The existing refusal of :<quant> on a checkpoint repo, the GGUF-first choice and the per-draft lookup behave as before.

The regression test lives in model_file::fetch's test module. The existing gate-gpu-gates-lib recipe already runs it with the hf feature. gate-ds41-bind gains one step that runs it with deepseek41,checkpoint, which also reaches the real side seat caller.

Release notes: Fixed: --hf refuses a safetensors-only repository before downloading any shard when the running binary or the calling seat cannot open a checkpoint.

Code shape

  • No second copy. The existing checkpoint helper stays the one place that decides. Online resolve, offline fallback and both public resolvers hand the same value to it.
  • Model code holds only architecture facts. No model code changes.
  • Dead code is gone. Nothing made unused.
  • No silent failure. An unsupported checkpoint is a named error that carries the repo.
  • Comments state what is true now.
  • No relaxed gate. No band, tolerance or lint moved.
  • cargo fmt and cargo clippy are clean on what I touched; the lint count did not go up. The format check is part of just contrib-check --tier t0 below; I did not run cargo clippy separately.

Duplication found or removed (path:line): none.

What I ran

The test checkpoint_support_is_checked_before_download serves a checkpoint-only repo with two shards from a file:// hub, reaches it through a stub curl that logs each hub path it is asked for, and counts the requests each caller makes. It covers model_file::name, model_file::resolve with Gguf, a :Q4_K_M quant, a caller that supports checkpoints, and, with the deepseek41 feature, the real side seat. Each case runs in a child process because model_file::name sets process-wide state.

Against the code before the fix, the first form of this test (a separate integration test with a loopback hub) showed the defect. The two unsupported callers fetched four shards in total:

listing GETs: 2, shard GETs: 4
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.64s

On the final test, a mutant that moves the checkpoint file fetch ahead of the admission check in resolve_drafts fails the name case in the hf build. A mutant that makes side_seat::Flags::read accept checkpoints fails the side case in the deepseek41,checkpoint build. Both runs exit with rc 101, and the tree was restored afterwards:

assertion `left == right` failed: name: ["/api/models/fixture/checkpoint/tree/main?recursive=true", ...
  left: 2
 right: 0
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 140 filtered out; finished in 0.31s

With the fix, on the PR head, on a Linux x86-64 host:

just gate-gpu-gates-lib
test model_file::fetch::tests::checkpoint_support_is_checked_before_download ... ok
test result: ok. 138 passed; 0 failed; 3 ignored; 0 measured; 0 filtered out; finished in 0.35s

just contrib-check --tier t0
DONE tier=t0 total=38 red=0 wall=437s

On an RTX 5090 machine the test ran in the hf build and with deepseek41,checkpoint, just gate-ds41-bind, which now includes the deepseek41,checkpoint step that reaches the real side seat. The run exited with rc 0:

NVIDIA GeForce RTX 5090, 595.99.02
| NVIDIA-SMI 595.99.02              Driver Version: 595.99.02      CUDA Version: 13.2     |
bash tools/gate.sh --release -p bloomery-gpu-gates --features hf --lib -- "$T" --nocapture
name: listing requests: 1, shard requests: 0
resolve: listing requests: 1, shard requests: 0
quant: listing requests: 1, shard requests: 0
supported: listing requests: 1, shard requests: 2
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 140 filtered out; finished in 0.32s
BLOOMERY_BOX_LOCAL=1 just gate-ds41-bind
test result: ok. 29 passed; 0 failed; 0 ignored; 0 measured; 193 filtered out; finished in 0.02s
test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 220 filtered out; finished in 0.00s
name: listing requests: 1, shard requests: 2
resolve: listing requests: 1, shard requests: 0
quant: listing requests: 1, shard requests: 0
supported: listing requests: 1, shard requests: 2
side: listing requests: 1, shard requests: 0
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 221 filtered out; finished in 0.62s
test result: ok. 34 passed; 0 failed; 0 ignored; 0 measured; 188 filtered out; finished in 0.03s

Those runs load no model and run no GPU computation. They build the device-linked crate and run the side seat's own resolver call. The RTX 5090 runs were on a head whose only difference from the PR head is the order of clauses inside the gate-ds41-bind line; the test and production code are unchanged.

Not run here: cargo check --workspace --all-targets across feature combinations (the public signatures of resolve, resolve_drafts and model_file::resolve change), cargo clippy on its own, and the other just gate-* recipes. No kernel, copy, launch or inference output changes, so no PTX comparison or timing run applies.

Reproduction

just gate-gpu-gates-lib
just gate-ds41-bind

What I ran into

This does not block this PR. qwen38_folder still refuses a checkpoint folder given directly with -m when the feature is off; that is a separate entry point and stays as it was.

Hardware

The Linux host runs used:

host: Linux 7.0.0-38-generic x86_64, AMD Ryzen 5 PRO 6650H with Radeon Graphics

The side seat runs used an RTX 5090 machine, as shown above.

AI help

AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.

@github-actions github-actions Bot added gpu The card engine: crates/gpu*, crates/app model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja needs-gpu Changes code a card must check, and carries no gate run on a card tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo labels Oct 23, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: CLEAN: Unsupported checkpoint sources are rejected at the shared owner before shard fetching, and no must-fix defect was found.

Checked

Duplicates: 3 new definitions and the error variant checked; no duplicated owner found. Dryer reported 0 pairs; gpu-gates was searched manually. The two new tests cover library admission and caller capability selection.

Complexity: crapper flagged no functions. Production growth passes the capability to the existing checkpoint helper and adds one rejection branch.

Silent failure: 2 admission-error paths followed. Online returns CheckpointUnsupported; cached resolution wraps it in Offline. Neither returns a model path or sets the process model.

Tests: mutation analysis of checkpoint's capability comparison makes the new hf test fail its error assertion; moving the fetch loop before admission makes the caller test fail its request-count assertion. Changing the side seat to accept checkpoints fails its child assertion. Taking checkpoint fallback despite an available GGUF set fails the changed draft-selection test. Signature-only test edits retain their assertions. These are static checks, not reviewer-executed mutations.

Gates: no pins, tolerances, assertions or cases removed or relaxed. The body supplies FAIL-first and caller-test mutant output.

Adversarial checks: offline admission, quant rejection, feature-off selection, and mixed GGUF/checkpoint listings are guarded. This is load-time code; no per-token work changes.

Escape catalog: no C1–C4 pattern matched. The curl stub preserves the real command's exit status with exec.

Notes

Tests were not executed during this static review. The card-run evidence omits the tested base/head hashes; gpu.json therefore records incomplete evidence.
The reported contrib-check --tier t0 run includes the bloomery-hf tests, including the new online/cache test.

Card check: needs-gpu. This pull request changes crates/gpu-gates/src/model_file.rs, crates/gpu-gates/src/model_file/fetch.rs, crates/gpu-gates/src/side_seat/flags.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)

@juliankang4

Copy link
Copy Markdown
Collaborator Author

The review is done and the contribution check passed, so I'm merging this.

@juliankang4
juliankang4 merged commit 8249381 into midagedev:main Oct 23, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gpu The card engine: crates/gpu*, crates/app model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja needs-gpu Changes code a card must check, and carries no gate run on a card tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant