You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An officially supported task in the examples folder
My own task or dataset (give details below)
Reproduction
importpeftimporttorchfrompathlibimportPathfromtransformersimportAutoModelForCausalLM, AutoTokenizerfrompeftimportLoraConfig, TaskTypefromtempfileimportTemporaryDirectorydefget_adapter_state_dict(model, adapter_name):
adapter_state_dict=model.state_dict()
adapter_weights= {key: valueforkey, valueinadapter_state_dict.items() ifadapter_nameinkey}
returnadapter_weightsdeftest_adapter_name():
MODEL_ID="openai-community/gpt2"ADAPTER_NAME="lora"# Load the base modelbase_model=AutoModelForCausalLM.from_pretrained(MODEL_ID)
# Define LoraConfig without base_model_name_or_pathpeft_config=LoraConfig(
task_type=TaskType.CAUSAL_LM,
inference_mode=False,
r=8
)
# Get the PEFT model with the adapter namepeft_model=peft.get_peft_model(base_model, peft_config, adapter_name=ADAPTER_NAME)
# Saving and loading the modelwithTemporaryDirectory() astemp_dir:
temp_dir=Path(temp_dir)
adapter_weights=get_adapter_state_dict(peft_model, ADAPTER_NAME)
peft_model.save_pretrained(temp_dir)
loaded_peft_model=peft.PeftModel.from_pretrained(model=base_model,
model_id=temp_dir/ADAPTER_NAME,
adapter_name=ADAPTER_NAME)
loaded_adapter_weights=get_adapter_state_dict(loaded_peft_model, ADAPTER_NAME)
# Assertion fails due to adapter weights been newly intializedforkeyinadapter_weights:
asserttorch.isclose(adapter_weights[key], loaded_adapter_weights[key]).all()
Expected behavior
A clear error or warning message indicating that the adapter_name and tuner_prefix should not be the same.
The text was updated successfully, but these errors were encountered:
This is kind of a stupid edge case, but not unthinkable to happen (e.g. to me). I suggest to raise when both adapter name and tuner prefix are the same when loading the peft model in the first place.
System Info
Who can help?
@BenjaminBossan
@stevhliu
Information
Tasks
examples
folderReproduction
Expected behavior
A clear error or warning message indicating that the adapter_name and tuner_prefix should not be the same.
The text was updated successfully, but these errors were encountered: