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

Conversation

@yaswanth19
Copy link
Contributor

@yaswanth19 yaswanth19 commented Sep 21, 2024

Refer #1932 for more context.

The main logic is we would have a specific prefix of adapter related keys and if such prefix is present in any of the missing keys then raise a warning else the adapter is loaded succesfully.

@yaswanth19
Copy link
Contributor Author

Hi @BenjaminBossan

I think this logic should cover most of the cases. I haven't added prompt learning techniques here as they don't have a concrete prefix. Please let me know if I am missing any edge cases.

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 this PR. I made a few suggestion, please check.

On top of those, I would also like to see a test being added. LMK if you feel up to that task and if you need support with it.

@yaswanth19
Copy link
Contributor Author

Yes @BenjaminBossan, Let me know which test cases should be handled. I will add those.

@yaswanth19 yaswanth19 closed this Sep 23, 2024
@yaswanth19 yaswanth19 reopened this Sep 23, 2024
@BenjaminBossan
Copy link
Member

Let me know which test cases should be handled. I will add those.

I checked our existing tests and I think it would actually be fine if we extend one of our existing tests and check that the missing_keys are empty. Take a look at this one:

def _test_load_multiple_adapters(self, model_id, config_cls, config_kwargs):
# just ensure that this works and raises no error
model = self.transformers_class.from_pretrained(model_id)
config = config_cls(
base_model_name_or_path=model_id,
**config_kwargs,
)
model = get_peft_model(model, config)
with tempfile.TemporaryDirectory() as tmp_dirname:
model.save_pretrained(tmp_dirname)
del model
model = self.transformers_class.from_pretrained(model_id).to(self.torch_device)
model = PeftModel.from_pretrained(model, tmp_dirname, torch_device=self.torch_device)
model.load_adapter(tmp_dirname, adapter_name="other")
model.load_adapter(tmp_dirname, adapter_name="yet-another")

There we're just loading two adapters and do no further checks (the test is just that there is no error). We could assign the load_result and assert that there are no missing keys for both of them. WDYT?

Apart from that, I just noticed that after your last pushes, when I go to https://github.com/huggingface/peft/pull/2084/files, for some reason I see 27 changed files (even though it only says 1 file on this page). Not sure what's going on. Maybe it's a GitHub bug, but it makes it super hard to review the PR. I would suggest to wait a day and see if it goes away by itself. If not, maybe you need to rebase on the latest main or if that doesn't help, create a fresh PR. Again, let's wait a day and only try those options if there is still the same error then.

@BenjaminBossan
Copy link
Member

Hmm, I still see 27 changed files :-/ Could you please try re-basing? Otherwise, we may need a new PR with just the relevant changes.

@yaswanth19
Copy link
Contributor Author

Rebased the branch correctly and added test cases. Please review the PR.

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 the updates. The rebase appears to have fixed the issue with the GH diff, nice. I have a suggestion to simplify the code a bit. Moreover, could you please run make style on the PR?

@yaswanth19
Copy link
Contributor Author

Done with changes.

@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.

@BenjaminBossan
Copy link
Member

As you can see, the CI is failing and the reason is that the test does not pass when checking VB-LoRA. The reason for that is that the vector bank in VB-LoRA is shared among all layers, so there isn't an individual one for each layer. I don't think there is an easy way to account for that in the code changes you made. My suggestion is therefore to simply skip the test for VB-LoRA, adding a comment explaining why. Could you please adjust the test accordingly?

To check locally that the error is fixed, just run pytest tests/ -k test_load_multiple_adapters -v.

@yaswanth19
Copy link
Contributor Author

Done, Skipping the VBLORA test case and added appropriate comment.

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.

Great, thanks for this PR, this should hopefully reduce confusion about missing keys in the future. Nice work.

@BenjaminBossan BenjaminBossan merged commit ccc3501 into huggingface:main Sep 25, 2024
@yaswanth19
Copy link
Contributor Author

yaswanth19 commented Sep 25, 2024

Yup Thanks @BenjaminBossan for guiding me, and I would be happy to help with any other issues or feature requests 🤗

@BenjaminBossan
Copy link
Member

Sounds good, thanks! You can watch the PEFT issues for potential contributions, especially when there is the contributions-welcome tag.

BenjaminBossan added a commit to BenjaminBossan/peft that referenced this pull request Sep 30, 2024
After merging huggingface#2084, we now clean up the missing_keys when loading a
PEFT adapter to remove all but the relevant keys (the fact that base
model keys are missing is expected when loading a PEFT adapter).

Since the presence of missing_keys now really means that something might
have gone wrong during loading, we can now warn the user if they call
PeftModel.from_pretrained.

Note that load_adapter still does not warn, as here we return the
load_result and users can already check, but for from_pretrained, they
don't have that possibility.
BenjaminBossan added a commit that referenced this pull request Oct 2, 2024
After merging #2084, we now clean up the missing_keys when loading a
PEFT adapter to remove all but the relevant keys (the fact that base
model keys are missing is expected when loading a PEFT adapter).

Since the presence of missing_keys now really means that something might
have gone wrong during loading, we can now warn the user if they call
PeftModel.from_pretrained.

Note that load_adapter still does not warn, as here we return the
load_result and users can already check, but for from_pretrained, they
don't have that possibility.
BenjaminBossan added a commit to BenjaminBossan/peft that referenced this pull request Oct 22, 2024
After merging huggingface#2084, we now clean up the missing_keys when loading a
PEFT adapter to remove all but the relevant keys (the fact that base
model keys are missing is expected when loading a PEFT adapter).

Since the presence of missing_keys now really means that something might
have gone wrong during loading, we can now warn the user if they call
PeftModel.from_pretrained.

Note that load_adapter still does not warn, as here we return the
load_result and users can already check, but for from_pretrained, they
don't have that possibility.
Guy-Bilitski pushed a commit to Guy-Bilitski/peft that referenced this pull request May 13, 2025
…ace#2084)

When loading a PEFT adapter, a lot of missing keys are reported, because the
base model weights are not loaded. However, this is totally fine. Therefore,
those missing keys can be safely ignored.

When using from_pretrrained, the missing keys won't be returned to the user,
thus there is no room for confusion. But when using load_adapter, the missing
keys (and unexpected keys) are returned and can cause confusion. With this PR,
the missing keys are filtered to remove keys that are unrelated to the adapter.

A small gap is VB-LoRA which reports missing keys because the vector bank
parameters are actually only loaded once and then shared.
Guy-Bilitski pushed a commit to Guy-Bilitski/peft that referenced this pull request May 13, 2025
After merging huggingface#2084, we now clean up the missing_keys when loading a
PEFT adapter to remove all but the relevant keys (the fact that base
model keys are missing is expected when loading a PEFT adapter).

Since the presence of missing_keys now really means that something might
have gone wrong during loading, we can now warn the user if they call
PeftModel.from_pretrained.

Note that load_adapter still does not warn, as here we return the
load_result and users can already check, but for from_pretrained, they
don't have that possibility.
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