Repository navigation
Conversation
Qubitium
force-pushed
the
upstream/08-safetensors-reference-offload-20261108
branch
from
November 8, 2026 07:57
38b8240 to
ea590da
Compare
Qubitium
reviewed
Nov 8, 2026
Qubitium
left a comment
Collaborator
There was a problem hiding this comment.
Review: layer 8/36 — authenticated safetensors reference offload
Rebased onto the layer-7 branch (9d20a5f3). One conflict in utils/model.py: this layer moves _atomic_shard_file next to the writer, which collided with the layer-6 permission fix at its old location. Resolved by keeping the fixed body at the new location. Diff vs the predecessor is only this layer's three files. Pushed as ea590da0.
Verified
tests/test_offload_files.py -k "streaming_state_dict or safetensors_reference"→ 9 passed (7 original + 2 added)ruff checkclean- Manual probes for float8 round-trip and restore behavior
Fixed
- Duplicated dtype table omitted float8 — the new
_SAFETENSORS_DTYPEcopied a subset of_DTYPE_SAFE_MAP(the exact drift the float8 gotcha comment inutils/model.pywarns about), so any float8 tensor made reference offload fail with "metadata differs". It now resolves spellings through_torch_dtype_to_safetensors(local import;model.pyimports this module lazily).float8_e4m3fnround-trips byte-exactly; added coverage. - Silent non-persistent buffer loss —
module.to_empty(recurse=True)replaces all parameters and buffers, butstate_dict()and the published index only record persistent ones. Reproduced: apersistent=Falsebuffer becomes meta and is unrecoverable. The helper now fails closed before touching the module; added coverage. - Windows portability —
os.fchmodis Unix-only andos.O_DIRECTORYmay not exist. Guarded (hasattr/os.name == "posix", matchinglooper/checkpoint_store.py). - Restore behavior documented — no Accelerate hooks are attached, so
undo_offload_to_diskleaves the module on meta (verified). Added a docstring note that this path is export-only viaget_state_dict_for_save.
Notes (not blockers)
include_prefixesusesstr.startswith, so a prefixmodel.layers.1also matchesmodel.layers.10.... There are no callers yet; nail down boundary semantics (name == p or name.startswith(p + ".")) before the first caller lands.- The slow branch (
format="safetensors"withoutdata_offsets) does not verifysha256; the new index writer always sets offsets, so only externally produced indexes are affected. - Source symlinks are rejected (
os.path.islink). HF cache snapshots are symlinks, so callers must pass the resolved blob path (or the helper couldrealpath). - Index temp file is
f"{index_path}.{os.getpid()}.tmp"opened with"x"; a stale file from a recycled PID would fail.tempfile.mkstempwould be more robust. - No
parent_module_lockaround the offload; concurrent offloads of the same module can race. to_emptybreaks tied-weight identity; export still writes both names, which HF tolerates.- Computing
sha256from the in-memory tensors validates content against the module, not against the source file; a source/module mismatch is caught at write time by_copy_file_stream(fail-closed), not here.
The design is sound: geometry is validated against the exact header, ranges must be contiguous to EOF, and the digest is verified while streaming so a changed source fails closed.
Qubitium
marked this pull request as ready for review
November 8, 2026 08:10
Qubitium
force-pushed
the
upstream/08-safetensors-reference-offload-20261108
branch
from
November 8, 2026 08:16
ea590da to
b49520f
Compare
… buffers - Derive safetensors spellings from utils/model.py's _DTYPE_SAFE_MAP instead of a local table that omitted float8; float8 reference offload now round-trips. - Reject modules with non-persistent buffers: to_empty(recurse=True) would replace them with meta while state_dict()/index cannot record them, silently losing data. Fail before touching the module. - Guard os.fchmod and directory fsync for non-POSIX hosts. - Document that reference offload installs no Accelerate hooks, so undo_offload_to_disk cannot restore it.
Qubitium
force-pushed
the
upstream/08-safetensors-reference-offload-20261108
branch
from
November 8, 2026 08:20
b49520f to
64ddd1a
Compare
This was referenced Nov 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add explicit reference offload for an existing safetensors artifact, validate the tensor set, dtypes, shapes and contiguous ranges, and publish an Accelerate-compatible index while moving module leaves to meta. Bind payload digests and verify them during streaming export. Support exact-name/prefix filtering before state collection. The source remains caller-owned and must stay available; this is opt-in. Test that changed source payloads fail closed.
Stack
Layer 8/36 of a dependency-ordered fork extraction. Depends on #3585. Review only this layer.
GitHub requires this cross-fork PR to target upstream
main, so its Files changed tab includes earlier stack layers. After the predecessor lands, rebase this branch and retarget the next layer; do not merge later layers out of order. No predecessor is merged automatically.Tests
69 passed, 1 CUDA skip. Used Python 3.12, Torch 2.14.1, Transformers 5.19.0. No model quantization, GPU work, downloads, or heavyweight model validation. Unit fixtures are small and CPU execution is constrained to one math thread.
Review and remaining validation
This layer and its dependency diff were reviewed for scope, existing extension points, and compatibility with the resolved fork snapshot. New focused regression coverage is included. Kept as a draft for maintainer review; hardware paths and end-to-end model behavior have not been revalidated in this session. No speed claim. Original integration/history is preserved in tpurtell#3.