Repository navigation
fix: bound offload source-reference RSS and stop cached kernel-validation failures pinning models (#4463, #4465) - #4496
Merged
Conversation
…heck (#4463) `_module_source_reference_index` proved each base-module tensor equal to the source checkpoint by loading it with `safe_open().get_tensor()` and comparing with `torch.equal`. That is a full owned copy plus the mapped file pages, so the check added ~2x the embedding size to the quantize peak RSS (+1004 MiB in the Llama-3.2-1B base-module offload call). `_source_payload_sha256_if_equal` now streams the payload range through one reusable 16 MiB `readinto` buffer, compares it with a uint8 view of the live tensor, and hashes the compared bytes for the index `sha256`. The reference offload and its disk saving are unchanged. Llama-3.2-1B GPTQ quantize peak RSS 3954 -> 3327 MiB, Qwen2.5-0.5B 3098 -> 2842 MiB; offload temp disk unchanged; checkpoints byte-identical. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… loading model (#4465) `cached_validate_once` lru-cached the exception `validate_once` returned; `with_traceback(None)` cleared only its own traceback, so the chained `__cause__` frames (and through `f_back` the loader frames holding the model) lived for the whole process, and a caller that raised the cached object re-attached a traceback to it. GGUF had a second root: the llama-cpp import failure was kept as an exception in a module global. - Cache `(ok, type, message)` via `_cache_validation_status` and rebuild a fresh exception per caller with `new_validation_error` (moved from utils/importer.py, which now imports it). - gguf_cpp keeps the llama-cpp import and ggml-cuda load failures as text and reports them inline in the raised message. GGUF Qwen2.5-0.5B load without llama-cpp-python: 471.2 MiB still allocated after `del` -> 0.0 MiB. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Qubitium
deleted the
fix/offload-ref-rss-and-validate-cache-4463-4465
branch
November 16, 2026 19:39
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.
Fixes #4465
Addresses #4463 item 1 (base-module offload source-reference RSS). Item 2 was fixed in #4492; item 3 is handled separately.
#4463 item 1: the base-module reference check no longer copies the tensor
_module_source_reference_indexproved each base-module tensor equal to the source checkpoint withsafe_open().get_tensor()+torch.equal. That is a full owned copy plus the mapped file pages._source_payload_sha256_if_equalstreams the payload's byte range through one 16 MiBreadintobuffer. It compares each chunk with a uint8 view of the live tensor and hashes the compared bytes for the indexsha256.Saved checkpoints are byte-identical.
#4465: cached validation failures hold text, not exceptions
cached_validate_oncecached the exception object. Its__cause__traceback, and throughf_backthe loader frames that hold the model, stayed alive for the life of the process. A laterraise errattached a new traceback to the cached object._cache_validation_statusnow caches(ok, type, message).new_validation_error, shared withvalidate_quant_linear, builds a fresh exception for each caller.gguf_cppkept the llama-cpp import failure as an exception in a module global, which pinned the same frames. It now keeps that failure, and the ggml-cuda load failure, as text quoted in the raised message.__cause__; only the message text is kept.del; it now leaves 0.0 MiB.flowchart TD A["make_quant / validate_quant_linear"] --> B["BaseQuantLinear.validate"] B --> C["cached_validate_once (_cache_validation_status)"] C --> D{"status cached?"} D -- no --> E["cls.validate_once()"] E -- ok --> G["cache (True, None, None)"] E -- "exception" --> H["cache (False, type, str) - exception dropped"] D -- yes --> I["new_validation_error -> fresh exception"] G --> I H --> I classDef failure fill:#ffe8e8,stroke:#b30000,color:#111; class H failure;Before/after details with file:line evidence are in
docs/safetensors-reference-offload.mdanddocs/kernel-validation-and-cache-lifecycle.md.Tests
tests/test_offload_reference_rss_4463.py:VmHWM) bound for a 128 MiB tensor: main adds 84–95 MiB, this PR about 2 MiB.tests/test_cached_validate_once_lifetime_4465.py: a weakref'd model must be collectable after a chained failure, after raising the returned error, and after a GGUF probe withoutllama_cpp.ruffis clean.🤖 Generated with Claude Code