Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow saving, loading and pushing adapter compositions together #771

Merged
merged 5 commits into from
Jan 8, 2025

Conversation

calpt
Copy link
Member

@calpt calpt commented Dec 27, 2024

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

Example

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)

@calpt calpt changed the title Add saving, loading and pushing adapter compositions together Allow saving, loading and pushing adapter compositions together Dec 27, 2024
@calpt calpt marked this pull request as ready for review December 28, 2024 13:29
Copy link
Contributor

@TimoImhof TimoImhof left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@TimoImhof TimoImhof merged commit 9edc20d into adapter-hub:main Jan 8, 2025
4 checks passed
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.

Push Fusion weights to adapters hub
2 participants