Repository navigation
Warn when the adapter-name filter removes colliding tensors during save - #3591
Closed
Sravanjangam wants to merge 2 commits into
Closed
Sravanjangam wants to merge 2 commits into
Sravanjangam wants to merge 2 commits into
Conversation
The negative filter in get_peft_model_state_dict matches by plain string containment, so an adapter whose NAME equals a module path segment of the saved adapter's tensors (e.g. an adapter called 'mlp' while a submodule is named 'mlp') silently removed those tensors from the checkpoint — up to and including writing a completely empty adapter_model.safetensors with no warning at all. Detect this collision before filtering and emit a RuntimeWarning naming the affected tensors, so silent truncation becomes visible. A structural (positional) filter is the cleaner long-term fix and is proposed in the issue; this makes the failure mode observable without changing behavior. Fixes huggingface#3584
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.
The negative filter in
get_peft_model_state_dictmatches by plain string containment, so an adapter whose name equals a module path segment of the saved adapter's tensors (e.g. an adapter calledmlpwhile a submodule is literally namedmlp) silently removed those tensors from the checkpoint — up to writing a completely emptyadapter_model.safetensorswith no warning at all.Fixes #3584
Details
This PR takes the incremental option discussed in the issue: detect the collision before filtering and emit a
RuntimeWarningnaming the affected tensors, converting silent truncation into a visible failure without changing save behavior. A structural (positional) filter remains the cleaner long-term fix and could follow separately if maintainers want it.Tests
TestAdapterNameCollisionWarningintests/test_initialization.py: both partial-loss and empty-checkpoint collisions now warn (no warning before, warning after); normal multi-adapter saves stay warning-free.Test environment: Python 3.12, torch 2.13.0+cpu, transformers 5.15.1, peft @ 5d602fd, ruff 0.16.4 (check + format clean).