Skip to content

Warn when the adapter-name filter removes colliding tensors during save - #3591

Closed
Sravanjangam wants to merge 2 commits into
huggingface:mainfrom
Sravanjangam:fix/adapter-name-collision-warning
Closed

Sravanjangam wants to merge 2 commits into
huggingface:mainfrom
Sravanjangam:fix/adapter-name-collision-warning

Conversation

@Sravanjangam

Copy link
Copy Markdown
Contributor

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 literally named mlp) silently removed those tensors from the checkpoint — up to writing a completely empty adapter_model.safetensors with 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 RuntimeWarning naming 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

  • New TestAdapterNameCollisionWarning in tests/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).

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
@Sravanjangam
Sravanjangam deleted the fix/adapter-name-collision-warning branch August 30, 2026 15:17
@Sravanjangam Sravanjangam reopened this Aug 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

save_pretrained writes an empty/truncated adapter checkpoint (silently) when another adapter name equals a base-model module path component

1 participant