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

Pluggable Model Integration Interface #738

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

calpt
Copy link
Member

@calpt calpt commented Aug 25, 2024

This PR drafts a new model integration interface which makes it easier to support new and custom model architectures for selected adapter methods without full model implementation.

This is done with the new AdapterModelInterface class that translates from generic model access points to model-specific attribute names.

Example usage:

For Qwen model:

model_interface = AdapterModelInterface(
    adapter_types=["lora", "reft"],
    model_embeddings="embed_tokens",
    model_layers="layers",
    layer_self_attn="self_attn",
    layer_cross_attn=None,
    attn_k_proj="k_proj",
    attn_q_proj="q_proj",
    attn_v_proj="v_proj",
    layer_intermediate_proj="mlp.up_proj",
    layer_output_proj="mlp.down_proj",
)

model_name = "Qwen/Qwen2-0.5B"

model = AutoModelForCausalLM.from_pretrained(model_name)
adapters.init(model, interface=model_interface)

config = LoRAConfig()
# config = LoReftConfig()
model.add_adapter("my_adapter", config=config)

print(model.adapter_summary())

Overview

Supported adapter types:

  • LoRA
  • ReFT
  • Bottleneck/ Compacter
  • Prefix Tuning
  • Prompt Tuning

Supported features:

  • Embedding training
  • Parallel composition
  • Fusion composition

calpt and others added 6 commits August 25, 2024 01:04
iter_layers and iter_attentions shouldn't use `getattr` and `hasattr` but instead use `multigetattr` and `multihasattr`
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.

2 participants