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

Add support for AdapterPlus #746

Merged
merged 35 commits into from
Nov 25, 2024
Merged

Add support for AdapterPlus #746

merged 35 commits into from
Nov 25, 2024

Conversation

julian-fong
Copy link
Contributor

@julian-fong julian-fong commented Oct 19, 2024

This PR aims to add support for AdapterPlus

Github: https://github.com/visinf/adapter_plus
Paper: https://arxiv.org/pdf/2406.06820

Integration of AdapterPlus into the adapters library will involve adding new parameters/options to the BnConfig

Checklist of things that are added/to be added

  1. New type of scaling called channel, in which we add learnable parameters for the channel/input_size dimension
  2. New type of init_weights called houlsby, where the projection matrices $W_{down}$ and $W_{up}$ will be initialized with zero-centered Gaussian with a standard deviation of $10^{-2}$ truncated at 2 standard deviations, and zeros for bias
  3. Support for drop_path, also known as stochastic depth ONLY applicable for vision based tasks using residual networks - located under a new file called /methods/vision.py

Copy link
Member

@calpt calpt left a comment

Choose a reason for hiding this comment

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

Did a first review pass, looks pretty solid overall! thanks for working on this!

Could you additionally add the new config to relevant locations in the docs. e.g. methods.md and classes/adapter_config?

@@ -40,6 +40,7 @@
"DEFAULT_ADAPTER_CONFIG",
"DEFAULT_ADAPTERFUSION_CONFIG",
"AdapterConfig",
"AdapterPlusConfig",
Copy link
Member

Choose a reason for hiding this comment

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

imports are added twice in this file, once here and once in the type checking block below

src/adapters/configuration/adapter_config.py Outdated Show resolved Hide resolved
src/adapters/methods/vision.py Outdated Show resolved Hide resolved
@julian-fong
Copy link
Contributor Author

@calpt It looks like there is a missing torchvision import error happening in the CI. Is the CI configured to install the package? I don't see it inside as a core dependency in setup.py but not exactly sure if that is the correct place to look.

@calpt
Copy link
Member

calpt commented Oct 30, 2024

@calpt It looks like there is a missing torchvision import error happening in the CI. Is the CI configured to install the package? I don't see it inside as a core dependency in setup.py but not exactly sure if that is the correct place to look.

you're right, it's not currently installed in CI. we could add it as optional dependency in setup.py, similar to what HF does here: https://github.com/huggingface/transformers/blob/405b56269812056d9593869e22b7b264d806cb1e/setup.py#L312 and then install that additional dep package here

pip install .[sklearn,testing,sentencepiece]

@julian-fong
Copy link
Contributor Author

julian-fong commented Oct 31, 2024

@calpt It looks like there is a missing torchvision import error happening in the CI. Is the CI configured to install the package? I don't see it inside as a core dependency in setup.py but not exactly sure if that is the correct place to look.

you're right, it's not currently installed in CI. we could add it as optional dependency in setup.py, similar to what HF does here: https://github.com/huggingface/transformers/blob/405b56269812056d9593869e22b7b264d806cb1e/setup.py#L312 and then install that additional dep package here

pip install .[sklearn,testing,sentencepiece]

Would you like that in a separate pr? I know other open-source libraries prefer another pr to differentiate scopes of pull requests, so just wondering what your preference is

@julian-fong
Copy link
Contributor Author

julian-fong commented Nov 1, 2024

@calpt It looks like there is a missing torchvision import error happening in the CI. Is the CI configured to install the package? I don't see it inside as a core dependency in setup.py but not exactly sure if that is the correct place to look.

you're right, it's not currently installed in CI. we could add it as optional dependency in setup.py, similar to what HF does here: https://github.com/huggingface/transformers/blob/405b56269812056d9593869e22b7b264d806cb1e/setup.py#L312 and then install that additional dep package here

pip install .[sklearn,testing,sentencepiece]

Please correct me if I'm wrong, but wouldn't torchvision need to be included as a core dependency since (and maybe there is an alternative that avoids this) we're importing the torchvision stochactic_depth function in methods/modeling.py? Users will be missing the library for that import whenever the file is being used if they install adapters straight up.

Thats sort of why I originally wrote the native implementation in the library so that we don't need to include any new core dependencies for timm or torchvision.

@calpt
Copy link
Member

calpt commented Nov 2, 2024

@calpt It looks like there is a missing torchvision import error happening in the CI. Is the CI configured to install the package? I don't see it inside as a core dependency in setup.py but not exactly sure if that is the correct place to look.

you're right, it's not currently installed in CI. we could add it as optional dependency in setup.py, similar to what HF does here: https://github.com/huggingface/transformers/blob/405b56269812056d9593869e22b7b264d806cb1e/setup.py#L312 and then install that additional dep package here

pip install .[sklearn,testing,sentencepiece]

Would you like that in a separate pr? I know other open-source libraries prefer another pr to differentiate scopes of pull requests, so just wondering what your preference is

fine to include here since this is directly related to the new functionality implemented in this pr

@calpt
Copy link
Member

calpt commented Nov 2, 2024

@calpt It looks like there is a missing torchvision import error happening in the CI. Is the CI configured to install the package? I don't see it inside as a core dependency in setup.py but not exactly sure if that is the correct place to look.

you're right, it's not currently installed in CI. we could add it as optional dependency in setup.py, similar to what HF does here: https://github.com/huggingface/transformers/blob/405b56269812056d9593869e22b7b264d806cb1e/setup.py#L312 and then install that additional dep package here

pip install .[sklearn,testing,sentencepiece]

Please correct me if I'm wrong, but wouldn't torchvision need to be included as a core dependency since (and maybe there is an alternative that avoids this) we're importing the torchvision stochactic_depth function in methods/modeling.py? Users will be missing the library for that import whenever the file is being used if they install adapters straight up.

Thats sort of why I originally wrote the native implementation in the library so that we don't need to include any new core dependencies for timm or torchvision.

that's a good point. I think what we can do is to make the import of torchvision conditional on the package being available. this is pretty standard practice across Transformers and they have helper methods for checking all sorts of packages, including torchvision: https://github.com/huggingface/transformers/blob/33868a057c02f0368ba63bd1edb746be38fe3d90/src/transformers/utils/import_utils.py#L361

If torchvision is not installed & stochastic_depth is used, we should thrown an exception, otherwise we don't care whether it's installed. This keeps it optional for all non-vision use cases.

Copy link
Member

@calpt calpt 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 overall, thanks a lot for working on this!
can be merged from my side once all checks are passing

@julian-fong
Copy link
Contributor Author

looks good to me overall, thanks a lot for working on this! can be merged from my side once all checks are passing

I have fixed the code quality issues - thanks!

@calpt calpt merged commit ec4a59e into adapter-hub:main Nov 25, 2024
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.

2 participants