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

Migrate to peft from opendelta for parameter efficient tuning methods #434

Open
jon-tow opened this issue Apr 13, 2023 · 6 comments
Open
Labels
feature request New feature or request

Comments

@jon-tow
Copy link
Collaborator

jon-tow commented Apr 13, 2023

🚀 The feature, motivation, and pitch

Let's migrate to peft.

Tasks

Doing so will require the following updates:

  1. Replace the opendelta setup in the AccelerateBaseTrainer with a peft backed setup:

    if self.config.model.delta_kwargs is not None:
    delta_type, delta_kwargs = parse_delta_kwargs(
    model.base_model.config,
    self.config.model.delta_kwargs,
    self.config.model.num_layers_unfrozen,
    )
    delta_model_class = get_delta_model_class(delta_type)
    delta_model = delta_model_class(model.base_model, **delta_kwargs)
    delta_model.freeze_module(exclude=["deltas"], set_state_dict=True)
    if self.accelerator.is_main_process:
    delta_model.log()

  2. Handle fine-grained layer capturing to only modify the upper trunk layers of hydra architectures as handled below:

    trlx/trlx/utils/modeling.py

    Lines 414 to 428 in 92b68e4

    def get_delta_modified_modules(
    config: transformers.PretrainedConfig,
    modified_modules: List[str],
    num_layers_unfrozen: int = -1,
    ) -> List[str]:
    """Returns a list of module names to be modified for a given delta method with
    the specified number of learnable layers."""
    unfrozen_layers_pattern = generate_layer_regex(config, num_layers_unfrozen)
    # [r] for regex as per https://github.com/thunlp/OpenDelta/blob/main/opendelta/utils/name_based_addressing.py#L20
    regex_prefix = "[r]"
    # TODO (jon-tow): `decoder.block.` is hardcoded to support T5 layer naming.
    decoder_prefix = "decoder.block." if config.is_encoder_decoder else ""
    module_list = [regex_prefix + decoder_prefix + unfrozen_layers_pattern + module for module in modified_modules]
    return module_list

Motivation

Citing @ethankim00's concerns with opendelta:

  • opendelta import fails due to an unnecessary turtle package import. Even if pip installed, users may be required to have sudo privileges to install the corresponding base graphics package ModuleNotFoundError caused by turtle package thunlp/OpenDelta#47
  • Doesn’t seem to work with DeepSpeed ZeRO 3
  • Additional inference overhead from not merging in the LoRA adapters layers
  • Incompatibility with int8 training
  • Less actively maintained than the peft library, which has been growing rapidly
  • Sharing adapter weights on the HuggingFace Hub is less convenient with opendelta

Alternatives

No response

Additional context

No response

@jon-tow jon-tow added the feature request New feature or request label Apr 13, 2023
@jon-tow
Copy link
Collaborator Author

jon-tow commented Apr 14, 2023

Assignee: @glerzing will be taking a go at this :)

@loganlebanoff
Copy link

I'm curious as to the status of this issue/PR

@glerzing
Copy link
Contributor

I'm developing automated tests for it, there should be a PR soon.

@akk-123
Copy link

akk-123 commented May 12, 2023

@glerzing look forward it

glerzing added a commit to glerzing/trlx that referenced this issue May 13, 2023
glerzing added a commit to glerzing/trlx that referenced this issue May 13, 2023
@akk-123
Copy link

akk-123 commented May 22, 2023

@glerzing when will have a pr?

@glerzing
Copy link
Contributor

It should be ready for PR tomorrow, sorry for the wait.

glerzing added a commit to glerzing/trlx that referenced this issue May 23, 2023
glerzing added a commit to glerzing/trlx that referenced this issue May 23, 2023
glerzing added a commit to glerzing/trlx that referenced this issue May 24, 2023
glerzing added a commit to glerzing/trlx that referenced this issue May 24, 2023
glerzing added a commit to glerzing/trlx that referenced this issue May 24, 2023
glerzing added a commit to glerzing/trlx that referenced this issue May 24, 2023
jon-tow added a commit that referenced this issue Jun 23, 2023
* Migrate to peft from opendelta  for parameter efficient tuning methods (#434) +  Collapse reference+learner hydra heads when using LoRa (#320)

* fix from_config

* Review corrections

* ILQL generate when temperature is 0.

* revert: guard against experimental 8-bit loading support

* format: run `black`

---------

Co-authored-by: jon-tow <[email protected]>
Co-authored-by: maxreciprocate <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants