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

[AdaLora] Fix adalora inference issue #745

Merged
merged 1 commit into from
Jul 26, 2023

Conversation

younesbelkada
Copy link
Contributor

Fixes #571

As stated by @BenjaminBossan the regularization term is only computed in training mode, i.e. when outputs.loss is different than None

Can confirm this snippet that is not working on main

import torch
from peft import AdaLoraConfig, get_peft_model, AutoPeftModelForCausalLM
from transformers import AutoModelForCausalLM 

model_id = "facebook/opt-350m"
peft_config = AdaLoraConfig(
    task_type="CAUSAL_LM"
)

model = AutoModelForCausalLM.from_pretrained(model_id)
dummy_input = torch.LongTensor([[1, 2, 3, 4, 5]])

model = get_peft_model(model, peft_config)
model.save_pretrained("test-adalora")

model = AutoPeftModelForCausalLM.from_pretrained("test-adalora")
_ = model(dummy_input)

Now works

Also fixes an issue when creating an adalora model with dropout == 0.

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Jul 24, 2023

The documentation is not available anymore as the PR was closed or merged.

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.

LGTM, thanks!

The trainable_adapter_name parameter is also used in this method:

def update_and_allocate(self, global_step):

But it probably makes no sense to call it in inference mode, so I guess we can leave it as is.

@younesbelkada younesbelkada merged commit 8541b60 into huggingface:main Jul 26, 2023
@younesbelkada younesbelkada deleted the fix-adalora-inference branch July 26, 2023 12: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.

maybe one inference error about AdaLoraModel
3 participants