Skip to content

Use defaultdict for _SET_ADAPTER_SCALE_FN_MAPPING#13320

Merged
sayakpaul merged 4 commits intohuggingface:mainfrom
Alexkkir:refactor/peft-defaultdict
Mar 24, 2026
Merged

Use defaultdict for _SET_ADAPTER_SCALE_FN_MAPPING#13320
sayakpaul merged 4 commits intohuggingface:mainfrom
Alexkkir:refactor/peft-defaultdict

Conversation

@Alexkkir
Copy link
Contributor

What does this PR do?

Currently everyone patches _SET_ADAPTER_SCALE_FN_MAPPING when training their models with peft
https://github.com/search?q=_SET_ADAPTER_SCALE_FN_MAPPING&type=code

Common patching practice looks like:

_SET_ADAPTER_SCALE_FN_MAPPING = {
    "MyModelName": lambda model_cls, weights: weights,
}

And as result every few months people modify file peft.py to add their own model:
image

The reason for this is lack of default behavior for _SET_ADAPTER_SCALE_FN_MAPPING.

This pr proposes to replace _SET_ADAPTER_SCALE_FN_MAPPING with defaultdict. It will simplify adding new models to diffusers as well as training and inference models with peft.

Before submitting

@sayakpaul, probably you can review this pr. Thanks!

Copy link
Member

@sayakpaul sayakpaul left a comment

Choose a reason for hiding this comment

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

Super cool! Thank you.

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@Alexkkir
Copy link
Contributor Author

Alexkkir commented Mar 24, 2026

@sayakpaul some tests crashed, is this ok? is this related to proposed change?

@sayakpaul
Copy link
Member

Those are unrelated. Will merge after another round of CI.

@sayakpaul
Copy link
Member

(Fixing the CUDA test failures in #13323)

@sayakpaul sayakpaul merged commit 832676d into huggingface:main Mar 24, 2026
29 of 32 checks passed
@sayakpaul
Copy link
Member

Failing tests are unrelated.

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.

3 participants