Skip to content

Conversation

@alvanli
Copy link
Contributor

@alvanli alvanli commented Mar 8, 2023

I don't usually directly push the model to hub and I had some trouble with saving the model locally when I relied on the trainer checkpoints in the sample notebook.

Added a callback to save adapter to checkpoints, using the code from here: #96

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@alvanli alvanli force-pushed the alvanli/add-local-saving-whisper-largev2 branch from c5619ba to 5e788b3 Compare March 8, 2023 15:08
Copy link
Contributor

@pacman100 pacman100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alvanli, Thanks a lot for adding this! 🤗

@pacman100 pacman100 merged commit c119993 into huggingface:main Mar 8, 2023
@jordancole21
Copy link

Hey! just implemented this in my flan t5 code! What code would I use to load the model in from the saved checkpoint?

@alvanli
Copy link
Contributor Author

alvanli commented Mar 8, 2023

for Whisper, it was something like this

from peft import PeftModel, PeftConfig
from transformers import WhisperForConditionalGeneration, Seq2SeqTrainer

peft_model_id = "./<output_dir>/checkpoint-12000"
peft_config = PeftConfig.from_pretrained(peft_model_id)
model = WhisperForConditionalGeneration.from_pretrained(
    peft_config.base_model_name_or_path, load_in_8bit=True, device_map="auto"
)
model = PeftModel.from_pretrained(model, peft_model_id)

@jordancole21
Copy link

from peft import PeftModel, PeftConfig
from transformers import WhisperForConditionalGeneration, Seq2SeqTrainer

peft_model_id = "./<output_dir>/checkpoint-12000"
peft_config = PeftConfig.from_pretrained(peft_model_id)
model = WhisperForConditionalGeneration.from_pretrained(
peft_config.base_model_name_or_path, load_in_8bit=True, device_map="auto"
)
model = PeftModel.from_pretrained(model, peft_model_id)

Thank you! That worked perfectly!

Guy-Bilitski pushed a commit to Guy-Bilitski/peft that referenced this pull request May 13, 2025
…ing-whisper-largev2

Add local saving for whisper largev2 example notebook
cyyever pushed a commit to cyyever/peft that referenced this pull request Sep 4, 2025
* adds a hacky peft example

* fixes bug due to missing "prepare_model_for_training"

* Formatting

* adds peft to requirements

* Update trl/trainer/ppo_trainer.py

Co-authored-by: Younes Belkada <49240599+younesbelkada@users.noreply.github.com>

* gpt neo runs

* changes requested on the PR

* style

* updates to prepare_model_for_int8_training PEFT PR huggingface#105

* updates to prepare_model_for_int8_training PEFT PR huggingface#105

* adds missing 8-bit attribute to modeling base

* adds lr to example script

* adds missing train to trainer

* disables caching temporarily while I debug something

* debugging issues with unstable training

* Fix peft + int8 (huggingface#170)

* add fix

* another fix

* Auto stash before merge of "peft-example" and "origin/peft-example"

* adds peft model types to modeling base

* reduces memory usage using adapters and no ref model.

* adds support for EleutherAI/gpt-neox-20b

* example for peft finetune of cm model

* removes hacky research code

* fixing the rebase and some typos

* style

* style2

* adds gradient checkpointing to base model

* cleans up comments

* moves config and other pretrained_model properties to __init__

* make style

* added tests

* change dependency

* Update .github/workflows/tests.yml

* fix test

* fix style and failing tests

* make quality

* revert change

* rm unneeded change

* revert changes

* rm changes

* rm changes

* rm uneeded change

* Update trl/models/modeling_base.py

* revert uneeded changes

* make style

* adapt suggestions

* fix tests

* attempt to fix

* fix

* fix

* add no peft test

* revert

* remove unneded check

* more tests

* fix logic

* add `save_pretrained` support

* fix quality

* clean up

* clean up

* stronger test

* refactor comments

* make style

* attempt to add non-peft tests

* remove test runner

* format

* fix test

* move `train` on top

* fix peft import

* make quality

* fixes typo

* adds peft example to docs

---------

Co-authored-by: Younes Belkada <49240599+younesbelkada@users.noreply.github.com>
Co-authored-by: younesbelakda <younesbelkada@gmail.com>
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.

3 participants