Correct way to save/load adapters and checkpoints in PEFT
Hi,It is not clear to me what is the correct way to save/load a PEFT checkpoint, as well as the final fine-tuned model. There have been reports oftrainer.resume_from_checkpointnot working as expected[1][2][3], each of which have very few replies, or do not seem to have any sort of consensus. Proposed solutions range fromtrainer.save_model, totrainer.save_statetoresume_from_checkpoint=Truetomodel.save_pretrained(PEFT docs)to even a very complicated procedure of merging and saving the model[4].It is very confusing trying to figure out the correct solution between these, especially ifresume_from_checkpointcan be buggy. Loading/saving models should really not be this confusing, so can we resolve once and for all what is the officially recommended (+tested) way of saving/loading adapters, as well as individual checkpoints during training? Can we update the HF docs accordingly, and simplify this process?@sgugger
2024-03-22T05:46:46Z
Hi@remorax98unfortunately sylvian is no longer a part of(just wanted to clarify this since there are lots of people who kept tagging him)also for loading your PEFT model for continuous training there is a very easy parameter around this it’s calledis_trainablewhich should allow you to load your PEFT model in a trainable state, then you can continue your training easily.how to usefor my repo innot-lain/Gemma-2b-Peft-finetuningall i have to do is# most of this code is from the button at the top right corner on 🤗
from peft import PeftModel, PeftConfig
from transformers import AutoModelForCausalLM

config = PeftConfig.from_pretrained("not-lain/Gemma-2b-Peft-finetuning")
model = AutoModelForCausalLM.from_pretrained("google/gemma-2b")
model = PeftModel.from_pretrained(model, 
"not-lain/Gemma-2b-Peft-finetuning",
 is_trainable=True # 👈 here
)
# check if it's working
model.print_trainable_parameters()
# >>> trainable params: 9,805,824 || all params: 2,515,978,240 || trainable%: 0.3897420034920493heart react this comment if this solved the problem for you
2024-03-22T09:51:52Z
Hi@not-lainthanks for letting me know about Sylvain! Sorry, my bad.Regarding this parameter, this is good to know and quite useful for me. But it does not answer my specific question - I am more concerned with the proper way for saving adapters and checkpoints in HF, and the lack of clarity in documentation regarding the same.Thanks anyway!
2024-03-22T17:34:54Z
don’t mention it@remorax98.I also made this notebook for you explaining all steps from the initial training then recalling the model and continue training, it took me a lot of time to get it done, but hope this helps you out.colab.research.google.comGoogle Colaboratoryif this notebook helped you clarify how to use PEFT, please consider marking this conversation as solvedregards,hafedh hichri
2024-04-18T16:07:29Z
Guys can you help with  proper examples of storing it to the file system instead of pushing to service? I triedtrainer.model.save_pretrained("shake_adapter")and thenshmodel = PeftModel.from_pretrained(
    base_model,
    "shake_adapter",
    is_trainable=True
)but it does not update my base model at all
2024-04-21T03:14:39Z
@adiudiunthe way PEFT works is it uses adapters to train the modelthe image below explains how you can visualize lora.I think what you’re looking for is thesave_embedding_layers, could you try setting it manually toTrue?huggingface.coModelsWe’re on a journey to advance and democratize artificial intelligence through open source and open science.
2024-05-16T18:43:23Z
@adiudiun, I had the same problem. The correct way is to first load thebase_modelusingAutoModel.from_pretrained(). Then, load the adapter config usingPeftConfig.from_pretrained('saved_dire'). Finally, load thepeft_modelas follows:Load the entire model with adapterspeft_model = PeftModel.from_pretrained(base_model, saved_dire)Load adapter1 and adapter2peft_model.load_adapter(saved_dire + ‘/adapter1’, adapter_name=‘adapter1’)peft_model.load_adapter(saved_dire + ‘/adapter2’, adapter_name=‘adapter2’)Here is the screenshot of that part:image1252×647 33.3 KBAlso, here is the link to the turtorial,https://github.com/akashghimireOfficial/HuggingFace_101/blob/master/Turtorial/12_more_about__get_peft_model.ipynb
2024-07-07T16:35:45Z
Hi, for what you have defined config when you don’t use it?
2024-08-15T15:33:06Z
Thank you for your effort. It is working now.