[go: nahoru, domu]

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

Better warning message or error when target module names are not available #40

Closed
sayakpaul opened this issue Jan 26, 2023 · 7 comments · Fixed by #51
Closed

Better warning message or error when target module names are not available #40

sayakpaul opened this issue Jan 26, 2023 · 7 comments · Fixed by #51

Comments

@sayakpaul
Copy link
Member
sayakpaul commented Jan 26, 2023

If we do:

from peft import LoraConfig, LoraModel
from transformers import AutoModelForImageClassification


model_checkpoint = "google/vit-base-patch32-224-in21k"
label2id = {"dog": 0, "cat": 1, "mouse": 2}
id2label = {v: k for k, v in label2id.items()}
model = AutoModelForImageClassification.from_pretrained(
    model_checkpoint, 
    label2id=label2id,
    id2label=id2label,
    ignore_mismatched_sizes = True, 
)

config = LoraConfig(
    r=16,
    lora_alpha=16,
    target_modules=["q_proj", "v_proj"],
    lora_dropout=0.0,
    bias="none",
)
model = LoraModel(config, model)

This wouldn't have any effect and will lead to errors during training because the target_modules were incorrectly named inside LoraConfig. When this case arises, it would help to throw a warning message so that the users can look into the issue with more information.

@pacman100
Copy link
Contributor
pacman100 commented Feb 2, 2023

Above PR should resolve this issue by raise error. For the example you specified in the issue description, following is the error message that will be raised

ValueError: Target modules ['q_proj', 'v_proj'] not found in the base model. Please check the target modules and 
try again.

@nameless0704
Copy link

Above PR should resolve this issue by raise error. For the example you specified in the issue description, following is the error message that will be raised

ValueError: Target modules ['q_proj', 'v_proj'] not found in the base model. Please check the target modules and 
try again.

I know maybe it's a different question but how do I solve this if I get this error? How to know what target module name I need?

@satani99
Copy link

hi @nameless0704, did you get any solution for the error?
My error was solved by changing target module to ["query_key_value"] but I don't know how to find for different models?

@pacman100
Copy link
Contributor

Hello, for models that aren't in the https://github.com/huggingface/peft/blob/main/src/peft/utils/other.py#L202, you need to look into the modeling_*.py file in transformers https://github.com/huggingface/transformers/tree/main/src/transformers/models

@panpan0000
Copy link

for example, you can vim to view your model layout file like pytorch_model.bin.index.json
you can see something like
model.layers.3.self_attn.q_proj.weight

or
transformer.encoder.layers.5.self_attention.query_key_value.weight

@karnikkanojia
Copy link

Can you help me understand what parameter will it be in this model, I can see there is nothing like q_proj like in the original phi model. The repo id is following: TheBloke/phi-2-GPTQ/modeling_phi.py

@BenjaminBossan
Copy link
Member

Can you help me understand what parameter will it be in this model, I can see there is nothing like q_proj like in the original phi model. The repo id is following: TheBloke/phi-2-GPTQ/modeling_phi.py

We have documented how to apply adapters to models that are not pre-configured here. Moreover, you can pass config = LoraConfig(..., target_modules="all-linear") to apply LoRA to all linear layers, which often works well.

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 a pull request may close this issue.

7 participants