-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow saving, loading and pushing adapter compositions together (#771)
Closes #441; closes #747. This PR introduces a set of new methods for saving, loading and pushing entire adapter compositions with one command: - `save_adapter_setup()` - `load_adapter_setup()` - `push_adapter_setup_to_hub()` They require two main params: - `adapter_setup`: the adapter composition to be saved. Identical to what can be specified for `active_adapters` - `head_setup`: for models with heads, the head setup to save along with the adapters. Identical to what can be specified for `active_head` Docs [here](https://github.com/adapter-hub/adapters/blob/04e69957a2bfc8093e2593186f7ebb2e71f88ec9/docs/loading.md#saving-and-loading-adapter-compositions) ### Example ```python model = AutoAdapterModel.from_pretrained("roberta-base") # create a complex setup model.add_adapter("a", config=SeqBnConfig()) model.add_adapter("b", config=SeqBnConfig()) model.add_adapter("c", config=SeqBnConfig()) model.add_adapter_fusion(["a", "b"]) model.add_classification_head("head_a") model.add_classification_head("head_b") adapter_setup = Stack(Fuse("a", "b"), "c") head_setup = BatchSplit("head_a", "head_b", batch_sizes=[1, 1]) model.set_active_adapters(adapter_setup) model.active_head = head_setup # save model.save_adapter_setup("checkpoint", adapter_setup, head_setup=head_setup) # push model.push_adapter_setup_to_hub("calpt/random_adapter_setup_test", adapter_setup, head_setup=head_setup) # re-load # model2 = AutoAdapterModel.from_pretrained("roberta-base") # model2.load_adapter_setup("checkpoint", set_active=True) ``` --------- Co-authored-by: Timo Imhof <[email protected]>
- Loading branch information
Showing
9 changed files
with
497 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.