这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@pzdkn
Copy link
Contributor

@pzdkn pzdkn commented Dec 3, 2024

This pull request addresses an issue where adapter weights are incorrectly initialized when the adapter_name conflicts with the tuner_prefix during model loading. Specifically, it introduces a warning message to notify users when this conflict occurs, as this could lead to confusion or unintentional weight reinitialization.

Changes:

  • Added a warning message when adapter_name matches the tuner_prefix, indicating a potential issue with missing adapter keys during model loading.
  • The warning clarifies that this conflict is likely caused by the adapter_name being contained in the tuner_prefix, helping users identify and resolve the issue more easily.

Impact:

  • Improves user experience by providing clearer feedback when model loading doesn't match expectations, preventing silent failures and making debugging easier.

Copy link
Member

@BenjaminBossan BenjaminBossan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR. It is certainly not a bad idea to warn users if they come across this issue. I'd go even further and also add a warning when users first create a model with an overlapping adapter name. For that, we'd have to adjust:

Would you be interested in working on those too? If not, I can later tackle this in a separate PR.

Regardless of that question, it would also be great to add a unit test for the warning (i.e. that there is no warning on the happy path but a warning when an overlapping name is chosen). Here is an example of a test that could be used as a starting point.

@pzdkn
Copy link
Contributor Author

pzdkn commented Dec 4, 2024

Yes I'd happy to take that!

@pzdkn pzdkn force-pushed the fix-adapter-name-naming-conflict branch from 30082ca to c9846c1 Compare December 4, 2024 14:02
@pzdkn
Copy link
Contributor Author

pzdkn commented Dec 4, 2024

Thanks for the guidance @BenjaminBossan ! I have added the warnings to both creation paths and the loading path plus an unit test.

@pzdkn pzdkn requested a review from BenjaminBossan December 4, 2024 14:18
Copy link
Member

@BenjaminBossan BenjaminBossan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for adding the other warnings and for providing the unit tests. In general, this all looks very good. I just have a small request, which is to break the one long test into multiple smaller tests. This improves readability and makes the tests useful (right now, if one assert fails, the checks further below are not executed).

One way is just to split this function into multiple smaller function. This results in a bit of code duplication but that's okay. Another suggestion is to create a class for all these tests. Inside the class, you can have define a pytest fixture for the duplicate code (like the model and config, check this test as an example). I'll leave this decision up to you. LMK if you have any questions.

@pzdkn pzdkn force-pushed the fix-adapter-name-naming-conflict branch from c9846c1 to 91c9cf2 Compare December 6, 2024 12:30
@pzdkn
Copy link
Contributor Author

pzdkn commented Dec 6, 2024

Hi thanks for the tips @BenjaminBossan ! Hope this does the job now 😄

@pzdkn pzdkn requested a review from BenjaminBossan December 6, 2024 12:35
@BenjaminBossan
Copy link
Member

@pzdkn Thanks for refactoring the test, it is now well structured. Could you please run make style to make the linter happy?

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

…eft_model, add_adapter, and from_pretrained

- Warn when adapter_name contains the tuner_prefix, which can cause weight reinitialization during model loading.

- Create TestNamingConflictWarning test class
@pzdkn pzdkn force-pushed the fix-adapter-name-naming-conflict branch from 91c9cf2 to ca95bd5 Compare December 10, 2024 13:47
@pzdkn
Copy link
Contributor Author

pzdkn commented Dec 10, 2024

Done 👍 Happy for another round of review @BenjaminBossan

Copy link
Member

@BenjaminBossan BenjaminBossan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the warnings for this edge case in naming, and for adding the nice unit tests. The PR LGTM.

Please ignore the failing CI, they're unrelated to the PR. We currently have trouble with the CI runners.

@BenjaminBossan BenjaminBossan merged commit 5cdade9 into huggingface:main Dec 11, 2024
10 of 14 checks passed
@pzdkn pzdkn deleted the fix-adapter-name-naming-conflict branch December 12, 2024 20:13
Guy-Bilitski pushed a commit to Guy-Bilitski/peft that referenced this pull request May 13, 2025
Warn when adapter_name contains the tuner_prefix, which can cause
weight reinitialization during model loading.
BenjaminBossan added a commit to BenjaminBossan/peft that referenced this pull request Sep 18, 2025
- The warning message was missing spaces between sentences.
- Added ' around strings for clarity
- For one warning, which extended another warning, put it at the start
  instead of the end, because the other warning can be quite long,
  leading to users missing the addition

For more context on this warning, see huggingface#2254
BenjaminBossan added a commit that referenced this pull request Sep 25, 2025
- The warning message was missing spaces between sentences.
- Added ' around strings for clarity
- For one warning, which extended another warning, put it at the start
  instead of the end, because the other warning can be quite long,
  leading to users missing the addition

For more context on this warning, see #2254
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.

3 participants