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

Support for Custom Adapters #2273

Closed
dgme-syz opened this issue Dec 11, 2024 · 4 comments
Closed

Support for Custom Adapters #2273

dgme-syz opened this issue Dec 11, 2024 · 4 comments

Comments

@dgme-syz
Copy link

Feature request

In simple terms, I would like support that allows users to customize their own adapter. I noticed that users only need to add a folder under this path src/peft/tuners and place some adapter-related files, usually config.py, layer.py, and model.py.

However, during implementation, I found that I also need to modify src/peft/utils/save_and_load.py/get_peft_model_state_dict to ensure that the custom adapter can be saved correctly. This is because the function is currently only adapted for existing adapters, so I have to modify the source code to ensure that the custom adapter can be used successfully.

PEFT is the most convenient and efficient fine-tuning library, and it would be even better if this feature were supported. Perhaps you’ve already implemented this functionality, but I haven’t found it yet. If so, please point it out. Thank you very much.

Motivation

I hope to use custom adapters to fine-tune large language models.

Your contribution

Currently, I have no clear ideas.

@BenjaminBossan
Copy link
Member

You are correct, when adding a new method, besides creating a new directory inside of src/peft/tuners, there is also the necessity to make a few adjustments to other PEFT files (usually very small adjustments, but it depends on the type of adapter).

Regarding the change in get_peft_model_state_dict, yes, we can refactor this to work out of the box without further changes for new adapters, I'll take a look. But note that by adding new code into src/peft/tuners, you're already making changes to the PEFT code base, so editing get_peft_model_state_dict is not really that different.

Perhaps you’ve already implemented this functionality

No, but as mentioned, I'll look into this, I had planned to facilitate this for a long time. The only thing we have right now is a way to add new custom LoRA layers, but not yet to add completely new adapter types.

Copy link

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

@BenjaminBossan
Copy link
Member

not stale, see #2282

@BenjaminBossan
Copy link
Member

@dgme-syz The PR is merged, adding a new PEFT method is now much simplified. To quote myself:

Ignoring tests, docs, and examples, we have the additions to src/peft/tuners/my_peft_method, but also need to:

  1. Add an entry to PEFT_TYPE_TO_CONFIG_MAPPING in mapping.py.
  2. Add an entry to PEFT_TYPE_TO_TUNER_MAPPING in mapping.py.
  3. Add an entry to PEFT_TYPE_TO_MODEL_MAPPING in peft_model.py
  4. Add an entry to PEFT_TYPE_TO_PREFIX_MAPPING in utils/constants.py
  5. Add some code to get_peft_model_state_dict in utils.save_and_load.py

With the changes in this PR, all these steps can be omitted.

On top of that, we also have the re-imports to peft/__init__.py and peft/tuners/__init__.py but those are still required (I'm hesitant to mess with the import system). Furthermore, it's still required to add an entry to PeftType in utils.peft_types.py. Since this is an enum, it can't be easily generated automatically. Therefore, adding a new PEFT method is still not 100% self-contained.

To register a new PEFT method, you should now add this to peft/tuners/my_peft_method/__init__.py:

from peft.utils import register_peft_method

register_peft_method(name="my_peft_method", config_cls=MyConfig, model_cls=MyModel)

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

No branches or pull requests

2 participants