Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix loading pretrained config #1041

Closed
wants to merge 1 commit into from

Conversation

pacman100
Copy link
Contributor

What does this PR do?

  1. fix loading pretrained config

@pacman100 pacman100 marked this pull request as ready for review October 20, 2023 19:57
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 catching this bug. I wonder if another solution would not be better: Instead of calling __post_init__ twice (once implicitly via the constructor, once explicitly), can we update the class_kwargs using the loaded_attributes before calling config = config_cls(**class_kwargs) and have the same effect?

BenjaminBossan added a commit to BenjaminBossan/peft that referenced this pull request Oct 23, 2023
Fixes huggingface#1045, supersedes huggingface#1041

Description

When loading a config from a file, we currently set the loaded
attributes on the config directly. However, this sidesteps the
__post_init__ call, which is required to convert the target_modules to a
set. This PR fixes this by avoiding to set attributes on the config
class directly, instead of going through __init__.

Other changes

While working on this, I did a slight refactor of the config tests.

1. All config classes are included now (some where missing before).
2. Use parameterized instead of looping through the classes.
3. Added a unit test for the aforementioned bug.

Notes

This fix is based on my comment here:

huggingface#1041 (review)

Normally, I'd just wait for Sourab to reply, but since he's off for a
few days, I created a separate PR.

Another way we could achieve this is to override __setattr__ on the
config class which explicitly converts target_modules to a set. This
would cover the case where a user does something like:

config = ...
config.target_modules = ["a", "b", "c"]

Then we don't need to rely on __post_init__. However, I would propose to
save the heavy guns for when absolutely necessary.
BenjaminBossan added a commit that referenced this pull request Oct 24, 2023
Fixes #1045, supersedes #1041

Description

When loading a config from a file, we currently set the loaded
attributes on the config directly. However, this sidesteps the
__post_init__ call, which is required to convert the target_modules to a
set. This PR fixes this by avoiding to set attributes on the config
class directly, instead of going through __init__.

Other changes

While working on this, I did a slight refactor of the config tests.

1. All config classes are included now (some where missing before).
2. Use parameterized instead of looping through the classes.
3. Added a unit test for the aforementioned bug.
@BenjaminBossan
Copy link
Member

@pacman100 This PR should be superseded by the change here:

https://github.com/huggingface/peft/pull/1046/files#diff-1e21bda41a67fe0b0b49bd3fa855bd34439c19c8510a0430b601e04a1c479a55

I'll leave this PR open for now in case you want to double-check.

@pacman100 pacman100 closed this Oct 26, 2023
@pacman100 pacman100 deleted the smangrul/fix-add-weighted-adapters branch November 8, 2023 05:29
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.

2 participants