Repository navigation
hf: extract the mapped safetensors reader from hub code - #575
Conversation
There was a problem hiding this comment.
Verdict: MUST_FIX: the newly public float converter silently accepts truncated tensor bytes.
Must fix
1. Validate Raw before converting its bytes (kind A)
crates/safetensors/src/lib.rs:315 exposes f32_values to callers that can construct Raw directly through its public fields at line 140. Passing Raw { dtype: Dtype::F32, shape: &[1], bytes: &[0, 0, 0] } to f32_values bypasses file validation and returns Ok([]): .as_chunks::<4>().0 drops the partial value. BF16 and F16 do the same with an odd byte count. This violates the no-silent-failure contract.
Validate this boundary before callers depend on successful conversion of malformed tensors.
Insert this guard before Ok(match raw.dtype {:
let expected = raw.shape.iter().try_fold(raw.dtype.size(), |bytes, &dim| {
bytes.checked_mul(dim)
});
if expected != Some(raw.bytes.len()) {
return Err(bad(format!(
"{name}: shape {:?} does not match {} {} bytes",
raw.shape,
raw.bytes.len(),
raw.dtype.name()
)));
}Add a direct Raw regression asserting Error::Format for the example above and partial BF16/F16 values. Removing the guard must make that assertion fail.
Non-blocking
⚠ CUDA move proof is missing: crates/gpu-gates/Cargo.toml:23 changes the reader dependency of CUDA-linked consumers. The PR explicitly omits their CUDA builds and move proof. Attach cargo oxide feature-build results, identical ptx-scan tables or canon-check output, and the affected DSpark/Clef/GLM gate results to close that validation gap.
Checked
Duplicates: 1 newly public function checked; the existing converter is reused and the old reader module is removed. Dryer reported 0 pairs.
Complexity: crapper reports Folder::open at 17; its body moved unchanged, with no added branches.
Silent failure: 5 sites followed; 2 .ok() chains reach named format errors, while 3 conversion arms discard partial values as described in item 1.
Tests: static mutation review shows restoring decision's HF edge or dropping its reader edge makes the new key assertions fail. Existing reader tests miss malformed direct Raw inputs.
Gates: reader assertions moved unchanged; unsafe budgets transferred with dated PINs; no tolerance relaxed.
Escape catalog: no C1–C4 pattern matched the added code.
Notes
Validation was static; no Rust tests or CUDA builds ran during validation.
Card check: needs-gpu. This pull request changes crates/gpu-gates/Cargo.toml, crates/gpu-gates/src/bin/gate_clef_serve.rs, crates/gpu-gates/src/bin/shared/dspark_hf.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)
29a0dab to
f964af2
Compare
|
Addressed the mandatory Raw boundary request from #575 (review) in
Fresh results: reader debug/release 12/12 each; HF 78/78; decision + reader 69/69; model-hf 21/21; warnings-denied clippy for all four host packages, comments, unsafe ratchet and full HIP lab locked/offline metadata passed. Existing extraction matrix and limits remain in the updated PR body. The requested CUDA feature-shape/PTX/canon/real-gate move proof remains unverified here: cargo oxide is absent and this machine has no NVIDIA seat. No CUDA pass or waiver is claimed. Ready for re-review of the mandatory fix; CUDA evidence still needs the equipped lane. |
There was a problem hiding this comment.
Since the last review:
- Raw conversion validation: fixed at crates/safetensors/src/lib.rs:316, with a direct regression test.
- CUDA move proof: still open at crates/gpu-gates/Cargo.toml:23.
Verdict: CLEAN: the new guard closes the malformed-span failure; no must-fix finding remains.
Non-blocking
⚠ CUDA move proof remains missing: crates/gpu-gates/Cargo.toml:23 changes the reader dependency of CUDA-linked consumers. Attach the affected cargo oxide feature-build results, identical ptx-scan tables or canon-check output, and DSpark/Clef/GLM gate results. The PR explicitly reports these checks as unavailable.
Checked
Duplicates: 1 new test checked; it covers direct Raw validation, which existing file-parser tests cannot exercise. Dryer reported 0 pairs. No new duplicate owner requires extraction.
Complexity: crapper flags Folder::open at 17; it is unchanged in this interdiff. f32_values adds one validation branch.
Silent failure: 3 float conversion arms followed; malformed spans and overflow return Error::Format before chunking can discard bytes.
Tests: static mutation review of production line 320 shows that dropping or reversing the guard fails the assertion at line 606. Scalar and empty assertions protect valid boundary inputs.
Gates: no pin, tolerance, test case or lint level was relaxed in the new commit.
Escape catalog: no C1–C4 pattern matched the new commit.
Notes
Reviewed the added interdiff commit; the extraction patch is unchanged. Validation was static; no Rust tests or CUDA builds ran during this review.
Card check: needs-gpu. This pull request changes crates/gpu-gates/Cargo.toml, crates/gpu-gates/src/bin/gate_clef_serve.rs, crates/gpu-gates/src/bin/shared/dspark_hf.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)
f964af2 to
acb939a
Compare
There was a problem hiding this comment.
Since the last review:
- Raw conversion validation: fixed at crates/safetensors/src/lib.rs:320; the guard and regression remain intact.
- CUDA move proof: still open at crates/gpu-gates/Cargo.toml:23.
Verdict: CLEAN: the import resolutions preserve the reader and tensor-parallel contracts; no new defect was found.
Non-blocking
⚠ CUDA move proof remains missing: crates/gpu-gates/Cargo.toml:23. Attach affected cargo oxide feature-build results, identical ptx-scan tables or canon-check output, and the owning DSpark/Clef/GLM gate results. This verifies the device-linked consumers after the dependency move. The PR reports these checks as unavailable.
Checked
Duplicates: 0 new definitions in the interdiff; dryer reported 0 pairs. The changed imports use the existing reader owner.
Complexity: crapper flags Folder::open at 17; its body is unchanged since the previous review. The interdiff adds no branches.
Silent failure: 0 new sites. The existing Raw guard rejects malformed spans and overflow before conversion.
Tests: the FP8 oracle body and assertions match the base after removing the reader import. Static mutation check: dropping the f32_values guard at line 320 fails the malformed-span assertion at line 606.
Gates: no pins, thresholds or test cases changed in the interdiff.
Escape catalog: no C1–C4 pattern matched.
Notes
Reviewed the changed interdiff hunks; the remaining extraction and validation patches are unchanged. Static comparisons confirmed that GLM's tp_tensors and read_tp match the base, and both consumers directly depend on the reader. No Rust tests, CUDA builds or runtime gates ran during this review.
Card check: needs-gpu. This pull request changes crates/gpu-gates/Cargo.toml, crates/gpu-gates/src/bin/gate_clef_serve.rs, crates/gpu-gates/src/bin/shared/dspark_hf.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)
|
@Burntgogi Thanks for the contribution. The review is done, so I'm merging this. |
What
Closes #528. Extract the existing mapped reader into
bloomery-safetensors(libsafetensors) and migrate all consumers in HF, decision, model-hf and gpu-gates. No HF re-export or compatibility reader remains.f32_valuesnow checks the complete shape-by-dtype byte count, including overflow, before converting directly constructedRawspans. The existingf32_valuesbecomes public for HF ModelOpt rather than adding a second conversion or shape allocation.safetensorsfeature. It depends on the reader, not HF.hfandclef, not generic GPU features.gate-safetensorsrecipe and update path/class mappings and existing docs.Exercised verification
Review fix
f964af2was rebased onto main4014464. Freshly rerun: reader debug/release, HF, decision with safetensors, model-hf, warnings-denied clippy, comments and unsafe ratchet. The other entries below retain the earlier extraction evidence.The new direct-Raw regression failed before the guard and passes afterward: partial F32/BF16/F16 values, too-short/too-long spans and overflow are Format errors; scalar and zero-element spans remain valid. A separate temporary external consumer exercised the public API and observed the three named partial-value refusals plus valid scalar/empty conversion; it was removed.
Linux x86_64, i5-12600K, pinned nightly-2026-08-28,
RUSTFLAGS=-C target-cpu=native, isolated target/tmp/bloomery-issue528-target.tools/gate.shwith--locked. Ignored real-file/oracle gates are not counted as passes.why: HF is absent from both decision gate keys; the reader is present in the Clef gate key.recipes.py check: 147 gate rows held to derivation;gate_class.py check: 0 findings;orphan-tests: 3236 tests each owned by a gate/lab recipe.contrib-check --tier t0 --only '^check-unsafe$'passed, total1/red0. No ratchet was relaxed.cargo metadata --locked --offline --format-version 1passed (without--no-deps). This verifies dependency/lock resolution, not HIP execution.Explicit limits
No full T0/CI success, Mac runtime, real-model decision CLI, CUDA build, PTX/canon or GPU runtime gate is claimed. Local
cargo oxide --versionfailed because the command is not installed; device-linked crates were not built with plain cargo. Feature metadata checked the GPU-gates dependency off by default and on under hf/clef; that is not GPU typecheck or runtime evidence.Please run the affected CUDA feature shapes/move proof and owning DSpark/Clef serving/GLM checkpoint gates where their toolchain/assets are available. Local pre-review was unavailable because
claudeis not installed. GitHub CI/review are separate.Written with AI assistance.