Repository navigation
fix(nf12): refresh cached exponent when loader replaces buffer - #3629
Merged
Merged
Conversation
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.
Problem
NF12ADLinear._exp_base()cached the exponent from its placeholder buffer. Accelerate'sset_module_tensor_to_devicereplaces that buffer directly during checkpoint loading, without calling_load_from_state_dict. Inspecting the module before load (for example,repr(module)) pinned exponent 0 even after the checkpoint installed exponent 54. A non-escaped BF16 weight of-0.000244140625then decoded as about-7.52e-37.Fix
Track the exponent buffer by identity, and its PyTorch version when available. A replacement or versioned in-place update refreshes the cached scalar.
clear_weight_cache()also joins the base module's state-dict/device-move invalidation hooks and handles explicit updates to inference tensors, which have no version counter. The packed representation and inference weight lifetime are unchanged.Correct the vendored NF12 README's public format spelling from
nf12_adtonf12, matching #3627 and the saved config.This is a localized cache-invalidation bug fix; the loading and dispatch flow is unchanged.
Validation
python -m pytest tests/test_nf12_ad_codec.py -q -o log_cli=false --disable-warnings --tb=short: 13 passed, 1 skipped (HIP kernel unavailable here).uvx ruff check gptqmodel/nn_modules/qlinear/nf12_ad.py tests/test_nf12_ad_codec.py: passed.git diff --check: passed.For the 16x64 fixture, persistent NF12 tensors are 1,537 bytes (1,536 packed + one exponent byte; zero escapes), and the decoded BF16 matrix is 2,048 bytes of temporary CPU scratch per forward. This test does not measure throughput; native NF12 acceleration is unavailable in this environment.