-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
save and load base model with revision #1658
save and load base model with revision #1658
Conversation
changed name of parameter from "revision" to "base_model_revision" for clarity
Thanks a lot for this PR.
We don't really have a single place where we test this functionality, I think it's fine to add the tests to the
I added a model here: >>> model = AutoModelForCausalLM.from_pretrained("peft-internal-testing/tiny-random-BertModel").eval()
>>> model(torch.arange(10).reshape(-1, 1)).logits.sum()
tensor(27.5802, grad_fn=<SumBackward0>)
>>> model_rev = AutoModelForCausalLM.from_pretrained("peft-internal-testing/tiny-random-BertModel", revision="v2.0.0").eval()
model_rev(torch.arange(10).reshape(-1, 1)).logits.sum()
tensor(-166.8932, grad_fn=<SumBackward0>) |
to maintain backwards compatibility with already-uploaded models
@mnoukhov Let me know when the PR is ready for review. |
I ended up changing I can change it back and add a little code to account for having Otherwise ready for review @BenjaminBossan |
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. |
There was a problem hiding this 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. I agree that keeping revision
at this point makes more sense for backwards compatibility.
I think we have to work a bit on the test, please check out my comment there.
I changed the tests but more importantly, realized there is a big problem. For some reason, I assumed that
but This feature / fix therefore requires either
I think the second makes more sense, but that means this is blocked until this is added to transformers. What do you think we should do? |
I don't think that the latter would make sense. The revision is not really a model config, the same config will typically apply to all revisions. So that only really leaves the first option. |
tests for revision now working
Added the One small thing I've noticed is that the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making the adjustments, the PR is almost good to go. I only have a few small comments left, please take a look.
One small thing I've noticed is that the peft_config passed to get_peft_model is modified in place and then set in the config so maybe we should be doing copy.copy for the config in get_peft_model to avoid issues like using the config twice and overwriting the revision the second time?
Yes, good point, this is not super clean. Maybe this could be addressed in a separate PR if you're interested.
@@ -101,7 +102,7 @@ def from_pretrained( | |||
"Cannot infer the auto class from the config, please make sure that you are loading the correct model for your task type." | |||
) | |||
|
|||
base_model = target_class.from_pretrained(base_model_path, **kwargs) | |||
base_model = target_class.from_pretrained(base_model_path, revision=base_model_revision, **kwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a small concern here, in PEFT configs, the revision
parameter defaults to None
but in transformers, it defaults to main
:
Honestly, the from_pretrained
method is a bit inscrutable to me, so I don't know if this can cause any issues (or might in the future). WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point. It shouldn't affect anything but I'll change all revision defaults from None
to "main"
for consistency
remove revision from kwargs and set it correctly for each .from_pretrained call
In doing the last changes, I discovered there was a problem if both the base model and the peft model have a revision. In that case, call would lead to an error in I fixed it, but in order to have a test for this, I would probably need a LoRA model on the hub with a revision different to that of its base model. An example would be an adapter with a |
Thanks for discovering and fixing that issue. I created a LoRA adapter with and without revision: model = AutoModelForCausalLM.from_pretrained("hf-internal-testing/tiny-random-BertModel").eval()
# without revision
model = PeftModel.from_pretrained(model, "peft-internal-testing/tiny-random-BertModel-lora")
# with revision
model = PeftModel.from_pretrained(model, "peft-internal-testing/tiny-random-BertModel-lora", revision="v1.2.3") I don't think we have any way of loading a PEFT model with revision directly using Regarding what I said earlier:
I'm doubting now if the proposed change is better. It is still true, but so far, all adapters have |
I've added the test with differing peft and base model revisions. The one caveat is that the peft config you've uploaded has a
The only issue I can forsee is if the default branch name changes in the future i.e. github changing from On a more conceptual basis, I think I prefer |
I agree with your assessment. In the end, I think I'd also prefer |
Default reverted to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all the changes and your patience, this now looks good to be merged.
I'll wait with the merge for after the next PEFT release (likely very soon), just to be 100% sure, since these types of changes always have a small chance to miss some edge case.
@mnoukhov PEFT release is out, merging this now. Again, thanks for the PR. |
addresses #1567
changed name of parameter from
revision
tobase_model_revision
for claritycan add unit tests if someone gives pointers to similar ones to extend
may need to add a model to
hf-internal-testing
with a base model with revision for these unit tests