[fix] Fix model loading inconsistency after Peft training by using PeftModel #2980
+64
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves: #2465, #2979
Pull Request Overview
To load models trained with Peft, I tried two implementations as follows: one where the base model path is provided to model_name_or_path in AutoConfig, and another using PeftModel.
I personally recommend the case of using PeftModel because I want accurate inference results to be displayed.
What do you all think?
Case of providing the base model path to model_name_or_path in AutoConfig:
70ba486
Case of using PeftModel:
https:/UKPLab/sentence-transformers/pull/2980/files
Details
About the Case of Providing the Base Model Path to model_name_or_path in AutoConfig
Pros
No need to increase Peft dependency in the SentenceTransformers package.
Cons
The inference results of the loaded model do not match the inference results and evaluation results from the model before saving, making this approach less favorable. (See the "Evaluation Results of Experiment (1)" below.)
About the Case of Using PeftModel
Pros
The inference results of the loaded model match the inference results and evaluation results from the model before saving, making it a correct implementation.
Cons
It increases the Peft dependency in the SentenceTransformers package.
Experiment
Evaluation Results of Experiment (1): Case of Providing the Base Model Path to model_name_or_path in AutoConfig
I saved a checkpoint from a model trained using Peft with the following script, and output the evaluation results with that model.
The following evaluation results were output from the model before saving:
The following evaluation results were output when the model was loaded using the following code. All the evaluation results differ from the previous ones.
Evaluation Results of Experiment (2): Case of Using PeftModel
The evaluation results were calculated with the same script as in Experiment (1). In this case, using PeftModel, all values matched.